Swap things around -- rename refactors, moving towards non-derpy design. Maybe.
This commit is contained in:
parent
ddedd077b6
commit
946d49675c
16
Group.cpp
16
Group.cpp
@ -17,20 +17,20 @@ Group::Group(const Group *other)
|
|||||||
|
|
||||||
void Group::update()
|
void Group::update()
|
||||||
{
|
{
|
||||||
firstRow = firstItem().row();
|
firstItemIndex = firstItem().row();
|
||||||
|
|
||||||
rowHeights = QVector<int>(numRows());
|
rowHeights = QVector<int>(numRows());
|
||||||
for (int i = 0; i < numRows(); ++i)
|
for (int i = 0; i < numRows(); ++i)
|
||||||
{
|
{
|
||||||
rowHeights[i] = view->categoryRowHeight(
|
rowHeights[i] = view->categoryRowHeight(
|
||||||
view->model()->index(i * view->itemsPerRow() + firstRow, 0));
|
view->model()->index(i * view->itemsPerRow() + firstItemIndex, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Group::HitResults Group::pointIntersect(const QPoint &pos) const
|
Group::HitResults Group::hitScan(const QPoint &pos) const
|
||||||
{
|
{
|
||||||
Group::HitResults results = Group::NoHit;
|
Group::HitResults results = Group::NoHit;
|
||||||
int y_start = top();
|
int y_start = verticalPosition();
|
||||||
int body_start = y_start + headerHeight();
|
int body_start = y_start + headerHeight();
|
||||||
int body_end = body_start + contentHeight() + 5; // FIXME: wtf is this 5?
|
int body_end = body_start + contentHeight() + 5; // FIXME: wtf is this 5?
|
||||||
int y = pos.y();
|
int y = pos.y();
|
||||||
@ -95,7 +95,7 @@ void Group::drawHeader(QPainter *painter, const int y)
|
|||||||
|
|
||||||
int Group::totalHeight() const
|
int Group::totalHeight() const
|
||||||
{
|
{
|
||||||
return headerHeight() + 5 + contentHeight();
|
return headerHeight() + 5 + contentHeight(); // FIXME: wtf is that '5'?
|
||||||
}
|
}
|
||||||
|
|
||||||
int Group::headerHeight() const
|
int Group::headerHeight() const
|
||||||
@ -122,10 +122,10 @@ int Group::numRows() const
|
|||||||
return qMax(1, qCeil((qreal)numItems() / (qreal)view->itemsPerRow()));
|
return qMax(1, qCeil((qreal)numItems() / (qreal)view->itemsPerRow()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Group::top() const
|
int Group::verticalPosition() const
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
const QList<Group *> cats = view->m_categories;
|
const QList<Group *> cats = view->m_groups;
|
||||||
for (int i = 0; i < cats.size(); ++i)
|
for (int i = 0; i < cats.size(); ++i)
|
||||||
{
|
{
|
||||||
if (cats.at(i) == this)
|
if (cats.at(i) == this)
|
||||||
@ -143,7 +143,7 @@ QList<QModelIndex> Group::items() const
|
|||||||
for (int i = 0; i < view->model()->rowCount(); ++i)
|
for (int i = 0; i < view->model()->rowCount(); ++i)
|
||||||
{
|
{
|
||||||
const QModelIndex index = view->model()->index(i, 0);
|
const QModelIndex index = view->model()->index(i, 0);
|
||||||
if (index.data(CategorizedViewRoles::CategoryRole).toString() == text)
|
if (index.data(GroupViewRoles::GroupRole).toString() == text)
|
||||||
{
|
{
|
||||||
indices.append(index);
|
indices.append(index);
|
||||||
}
|
}
|
||||||
|
25
Group.h
25
Group.h
@ -10,22 +10,38 @@ class QModelIndex;
|
|||||||
|
|
||||||
struct Group
|
struct Group
|
||||||
{
|
{
|
||||||
|
/* constructors */
|
||||||
Group(const QString &text, GroupView *view);
|
Group(const QString &text, GroupView *view);
|
||||||
Group(const Group *other);
|
Group(const Group *other);
|
||||||
|
|
||||||
|
/* data */
|
||||||
GroupView *view;
|
GroupView *view;
|
||||||
QString text;
|
QString text;
|
||||||
bool collapsed;
|
bool collapsed;
|
||||||
QVector<int> rowHeights;
|
QVector<int> rowHeights;
|
||||||
int firstRow;
|
int firstItemIndex;
|
||||||
|
|
||||||
|
/* logic */
|
||||||
|
/// do stuff. and things. TODO: redo.
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
/// draw the header at y-position.
|
||||||
void drawHeader(QPainter *painter, const int y);
|
void drawHeader(QPainter *painter, const int y);
|
||||||
|
|
||||||
|
/// height of the group, in total. includes a small bit of padding.
|
||||||
int totalHeight() const;
|
int totalHeight() const;
|
||||||
|
|
||||||
|
/// height of the group header, in pixels
|
||||||
int headerHeight() const;
|
int headerHeight() const;
|
||||||
|
|
||||||
|
/// height of the group content, in pixels
|
||||||
int contentHeight() const;
|
int contentHeight() const;
|
||||||
|
|
||||||
|
/// the number of visual rows this group has
|
||||||
int numRows() const;
|
int numRows() const;
|
||||||
int top() const;
|
|
||||||
|
/// the height at which this group starts, in pixels
|
||||||
|
int verticalPosition() const;
|
||||||
|
|
||||||
enum HitResult
|
enum HitResult
|
||||||
{
|
{
|
||||||
@ -37,9 +53,12 @@ struct Group
|
|||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(HitResults, HitResult)
|
Q_DECLARE_FLAGS(HitResults, HitResult)
|
||||||
|
|
||||||
HitResults pointIntersect (const QPoint &pos) const;
|
/// shoot! BANG! what did we hit?
|
||||||
|
HitResults hitScan (const QPoint &pos) const;
|
||||||
|
|
||||||
|
/// super derpy thing.
|
||||||
QList<QModelIndex> items() const;
|
QList<QModelIndex> items() const;
|
||||||
|
/// I don't even
|
||||||
int numItems() const;
|
int numItems() const;
|
||||||
QModelIndex firstItem() const;
|
QModelIndex firstItem() const;
|
||||||
QModelIndex lastItem() const;
|
QModelIndex lastItem() const;
|
||||||
|
@ -41,14 +41,14 @@ GroupView::GroupView(QWidget *parent)
|
|||||||
|
|
||||||
GroupView::~GroupView()
|
GroupView::~GroupView()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_categories);
|
qDeleteAll(m_groups);
|
||||||
m_categories.clear();
|
m_groups.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
void GroupView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
||||||
const QVector<int> &roles)
|
const QVector<int> &roles)
|
||||||
{
|
{
|
||||||
if (roles.contains(CategorizedViewRoles::CategoryRole) || roles.contains(Qt::DisplayRole))
|
if (roles.contains(GroupViewRoles::GroupRole) || roles.contains(Qt::DisplayRole))
|
||||||
{
|
{
|
||||||
updateGeometries();
|
updateGeometries();
|
||||||
}
|
}
|
||||||
@ -74,18 +74,18 @@ void GroupView::updateGeometries()
|
|||||||
|
|
||||||
for (int i = 0; i < model()->rowCount(); ++i)
|
for (int i = 0; i < model()->rowCount(); ++i)
|
||||||
{
|
{
|
||||||
const QString category =
|
const QString groupName =
|
||||||
model()->index(i, 0).data(CategorizedViewRoles::CategoryRole).toString();
|
model()->index(i, 0).data(GroupViewRoles::GroupRole).toString();
|
||||||
if (!cats.contains(category))
|
if (!cats.contains(groupName))
|
||||||
{
|
{
|
||||||
Group *old = this->category(category);
|
Group *old = this->category(groupName);
|
||||||
if (old)
|
if (old)
|
||||||
{
|
{
|
||||||
cats.insert(category, new Group(old));
|
cats.insert(groupName, new Group(old));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cats.insert(category, new Group(category, this));
|
cats.insert(groupName, new Group(groupName, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,22 +95,22 @@ void GroupView::updateGeometries()
|
|||||||
m_editedCategory = cats[m_editedCategory->text];
|
m_editedCategory = cats[m_editedCategory->text];
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
qDeleteAll(m_categories);
|
qDeleteAll(m_groups);
|
||||||
m_categories = cats.values();
|
m_groups = cats.values();
|
||||||
|
|
||||||
for (auto cat : m_categories)
|
for (auto cat : m_groups)
|
||||||
{
|
{
|
||||||
cat->update();
|
cat->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_categories.isEmpty())
|
if (m_groups.isEmpty())
|
||||||
{
|
{
|
||||||
verticalScrollBar()->setRange(0, 0);
|
verticalScrollBar()->setRange(0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int totalHeight = 0;
|
int totalHeight = 0;
|
||||||
for (auto category : m_categories)
|
for (auto category : m_groups)
|
||||||
{
|
{
|
||||||
totalHeight += category->totalHeight() + m_categoryMargin;
|
totalHeight += category->totalHeight() + m_categoryMargin;
|
||||||
}
|
}
|
||||||
@ -140,12 +140,12 @@ bool GroupView::isIndexHidden(const QModelIndex &index) const
|
|||||||
|
|
||||||
Group *GroupView::category(const QModelIndex &index) const
|
Group *GroupView::category(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
return category(index.data(CategorizedViewRoles::CategoryRole).toString());
|
return category(index.data(GroupViewRoles::GroupRole).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
Group *GroupView::category(const QString &cat) const
|
Group *GroupView::category(const QString &cat) const
|
||||||
{
|
{
|
||||||
for (auto group : m_categories)
|
for (auto group : m_groups)
|
||||||
{
|
{
|
||||||
if (group->text == cat)
|
if (group->text == cat)
|
||||||
{
|
{
|
||||||
@ -157,9 +157,9 @@ Group *GroupView::category(const QString &cat) const
|
|||||||
|
|
||||||
Group *GroupView::categoryAt(const QPoint &pos) const
|
Group *GroupView::categoryAt(const QPoint &pos) const
|
||||||
{
|
{
|
||||||
for (auto group : m_categories)
|
for (auto group : m_groups)
|
||||||
{
|
{
|
||||||
if(group->pointIntersect(pos) & Group::CheckboxHit)
|
if(group->hitScan(pos) & Group::CheckboxHit)
|
||||||
{
|
{
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
@ -420,9 +420,9 @@ void GroupView::paintEvent(QPaintEvent *event)
|
|||||||
QPainter painter(this->viewport());
|
QPainter painter(this->viewport());
|
||||||
|
|
||||||
int y = -verticalOffset();
|
int y = -verticalOffset();
|
||||||
for (int i = 0; i < m_categories.size(); ++i)
|
for (int i = 0; i < m_groups.size(); ++i)
|
||||||
{
|
{
|
||||||
Group *category = m_categories.at(i);
|
Group *category = m_groups.at(i);
|
||||||
category->drawHeader(&painter, y);
|
category->drawHeader(&painter, y);
|
||||||
y += category->totalHeight() + m_categoryMargin;
|
y += category->totalHeight() + m_categoryMargin;
|
||||||
}
|
}
|
||||||
@ -457,6 +457,10 @@ void GroupView::paintEvent(QPaintEvent *event)
|
|||||||
itemDelegate()->paint(&painter, option, index);
|
itemDelegate()->paint(&painter, option, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Drop indicators for manual reordering...
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
if (!m_lastDragPosition.isNull())
|
if (!m_lastDragPosition.isNull())
|
||||||
{
|
{
|
||||||
QPair<Group *, int> pair = rowDropPos(m_lastDragPosition);
|
QPair<Group *, int> pair = rowDropPos(m_lastDragPosition);
|
||||||
@ -464,7 +468,7 @@ void GroupView::paintEvent(QPaintEvent *event)
|
|||||||
int row = pair.second;
|
int row = pair.second;
|
||||||
if (category)
|
if (category)
|
||||||
{
|
{
|
||||||
int internalRow = row - category->firstRow;
|
int internalRow = row - category->firstItemIndex;
|
||||||
QLine line;
|
QLine line;
|
||||||
if (internalRow >= category->numItems())
|
if (internalRow >= category->numItems())
|
||||||
{
|
{
|
||||||
@ -482,6 +486,7 @@ void GroupView::paintEvent(QPaintEvent *event)
|
|||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupView::resizeEvent(QResizeEvent *event)
|
void GroupView::resizeEvent(QResizeEvent *event)
|
||||||
@ -552,7 +557,7 @@ void GroupView::dropEvent(QDropEvent *event)
|
|||||||
if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex()))
|
if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex()))
|
||||||
{
|
{
|
||||||
model()->setData(model()->index(row, 0), categoryText,
|
model()->setData(model()->index(row, 0), categoryText,
|
||||||
CategorizedViewRoles::CategoryRole);
|
GroupViewRoles::GroupRole);
|
||||||
event->setDropAction(Qt::MoveAction);
|
event->setDropAction(Qt::MoveAction);
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
@ -624,7 +629,7 @@ QRect GroupView::geometryRect(const QModelIndex &index) const
|
|||||||
// int y = pos.second;
|
// int y = pos.second;
|
||||||
|
|
||||||
QRect out;
|
QRect out;
|
||||||
out.setTop(cat->top() + cat->headerHeight() + 5 + categoryInternalRowTop(index));
|
out.setTop(cat->verticalPosition() + cat->headerHeight() + 5 + categoryInternalRowTop(index));
|
||||||
out.setLeft(m_spacing + x * (itemWidth() + m_spacing));
|
out.setLeft(m_spacing + x * (itemWidth() + m_spacing));
|
||||||
out.setSize(itemDelegate()->sizeHint(viewOptions(), index));
|
out.setSize(itemDelegate()->sizeHint(viewOptions(), index));
|
||||||
|
|
||||||
@ -717,7 +722,6 @@ QPixmap GroupView::renderToPixmap(const QModelIndexList &indices, QRect *r) cons
|
|||||||
option.rect = paintPairs.at(j).first.translated(-r->topLeft());
|
option.rect = paintPairs.at(j).first.translated(-r->topLeft());
|
||||||
const QModelIndex ¤t = paintPairs.at(j).second;
|
const QModelIndex ¤t = paintPairs.at(j).second;
|
||||||
itemDelegate()->paint(&painter, option, current);
|
itemDelegate()->paint(&painter, option, current);
|
||||||
painter.drawLine(0,0, r->width(), r->height());
|
|
||||||
}
|
}
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
@ -762,7 +766,7 @@ QPair<Group *, int> GroupView::rowDropPos(const QPoint &pos)
|
|||||||
Group *category = 0;
|
Group *category = 0;
|
||||||
{
|
{
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for (auto cat : m_categories)
|
for (auto cat : m_groups)
|
||||||
{
|
{
|
||||||
if (pos.y() > y && pos.y() < (y + cat->headerHeight()))
|
if (pos.y() > y && pos.y() < (y + cat->headerHeight()))
|
||||||
{
|
{
|
||||||
@ -812,7 +816,7 @@ QPair<Group *, int> GroupView::rowDropPos(const QPoint &pos)
|
|||||||
int internalRow = -1;
|
int internalRow = -1;
|
||||||
{
|
{
|
||||||
// FIXME rework the drag and drop code
|
// FIXME rework the drag and drop code
|
||||||
const int top = category->top();
|
const int top = category->verticalPosition();
|
||||||
for (int r = 0, h = top; r < category->numRows();
|
for (int r = 0, h = top; r < category->numRows();
|
||||||
h += itemHeightForCategoryRow(category, r), ++r)
|
h += itemHeightForCategoryRow(category, r), ++r)
|
||||||
{
|
{
|
||||||
@ -882,19 +886,19 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
|
|||||||
}
|
}
|
||||||
qDebug() << "model row: " << current.row();
|
qDebug() << "model row: " << current.row();
|
||||||
auto cat = category(current);
|
auto cat = category(current);
|
||||||
int i = m_categories.indexOf(cat);
|
int i = m_groups.indexOf(cat);
|
||||||
if(i >= 0)
|
if(i >= 0)
|
||||||
{
|
{
|
||||||
// this is a pile of something foul
|
// this is a pile of something foul
|
||||||
auto real_cat = m_categories[i];
|
auto real_group = m_groups[i];
|
||||||
int beginning_row = 0;
|
int beginning_row = 0;
|
||||||
for(auto catt: m_categories)
|
for(auto group: m_groups)
|
||||||
{
|
{
|
||||||
if(catt == real_cat)
|
if(group == real_group)
|
||||||
break;
|
break;
|
||||||
beginning_row += catt->numRows();
|
beginning_row += group->numRows();
|
||||||
}
|
}
|
||||||
qDebug() << "category: " << real_cat->text;
|
qDebug() << "category: " << real_group->text;
|
||||||
QPair<int, int> pos = categoryInternalPosition(current);
|
QPair<int, int> pos = categoryInternalPosition(current);
|
||||||
int row = beginning_row + pos.second;
|
int row = beginning_row + pos.second;
|
||||||
qDebug() << "row: " << row;
|
qDebug() << "row: " << row;
|
||||||
|
25
GroupView.h
25
GroupView.h
@ -4,11 +4,11 @@
|
|||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
|
||||||
struct CategorizedViewRoles
|
struct GroupViewRoles
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
CategoryRole = Qt::UserRole,
|
GroupRole = Qt::UserRole,
|
||||||
ProgressValueRole,
|
ProgressValueRole,
|
||||||
ProgressMaximumRole
|
ProgressMaximumRole
|
||||||
};
|
};
|
||||||
@ -24,7 +24,7 @@ public:
|
|||||||
GroupView(QWidget *parent = 0);
|
GroupView(QWidget *parent = 0);
|
||||||
~GroupView();
|
~GroupView();
|
||||||
|
|
||||||
virtual QRect geometryRect(const QModelIndex &index) const;
|
QRect geometryRect(const QModelIndex &index) const;
|
||||||
virtual QRect visualRect(const QModelIndex &index) const override;
|
virtual QRect visualRect(const QModelIndex &index) const override;
|
||||||
QModelIndex indexAt(const QPoint &point) const;
|
QModelIndex indexAt(const QPoint &point) const;
|
||||||
void setSelection(const QRect &rect,
|
void setSelection(const QRect &rect,
|
||||||
@ -54,22 +54,21 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
|
virtual QModelIndex moveCursor(CursorAction cursorAction,
|
||||||
override;
|
Qt::KeyboardModifiers modifiers) override;
|
||||||
|
|
||||||
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const override;
|
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const override;
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
slots:
|
slots:
|
||||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
||||||
const QVector<int> &roles);
|
const QVector<int> &roles) override;
|
||||||
virtual void rowsInserted(const QModelIndex &parent, int start, int end);
|
virtual void rowsInserted(const QModelIndex &parent, int start, int end) override;
|
||||||
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
|
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
|
||||||
virtual void updateGeometries();
|
virtual void updateGeometries() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool isIndexHidden(const QModelIndex &index) const;
|
virtual bool isIndexHidden(const QModelIndex &index) const override;
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void mouseMoveEvent(QMouseEvent *event) override;
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
@ -87,7 +86,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
friend struct Group;
|
friend struct Group;
|
||||||
|
|
||||||
QList<Group *> m_categories;
|
QList<Group *> m_groups;
|
||||||
|
|
||||||
int m_leftMargin;
|
int m_leftMargin;
|
||||||
int m_rightMargin;
|
int m_rightMargin;
|
||||||
|
@ -8,8 +8,8 @@ GroupedProxyModel::GroupedProxyModel(QObject *parent) : QSortFilterProxyModel(pa
|
|||||||
|
|
||||||
bool GroupedProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
bool GroupedProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
{
|
{
|
||||||
const QString leftCategory = left.data(CategorizedViewRoles::CategoryRole).toString();
|
const QString leftCategory = left.data(GroupViewRoles::GroupRole).toString();
|
||||||
const QString rightCategory = right.data(CategorizedViewRoles::CategoryRole).toString();
|
const QString rightCategory = right.data(GroupViewRoles::GroupRole).toString();
|
||||||
if (leftCategory == rightCategory)
|
if (leftCategory == rightCategory)
|
||||||
{
|
{
|
||||||
return left.row() < right.row();
|
return left.row() < right.row();
|
||||||
|
@ -253,8 +253,8 @@ void ListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
|||||||
}
|
}
|
||||||
|
|
||||||
drawProgressOverlay(painter, opt,
|
drawProgressOverlay(painter, opt,
|
||||||
index.data(CategorizedViewRoles::ProgressValueRole).toInt(),
|
index.data(GroupViewRoles::ProgressValueRole).toInt(),
|
||||||
index.data(CategorizedViewRoles::ProgressMaximumRole).toInt());
|
index.data(GroupViewRoles::ProgressMaximumRole).toInt());
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
4
main.cpp
4
main.cpp
@ -36,7 +36,7 @@ QStandardItem *createItem(const Qt::GlobalColor color, const QString &text,
|
|||||||
QStandardItem *item = new QStandardItem;
|
QStandardItem *item = new QStandardItem;
|
||||||
item->setText(text);
|
item->setText(text);
|
||||||
item->setData(icon(color), Qt::DecorationRole);
|
item->setData(icon(color), Qt::DecorationRole);
|
||||||
item->setData(category, CategorizedViewRoles::CategoryRole);
|
item->setData(category, GroupViewRoles::GroupRole);
|
||||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
// progresser->addTrackedIndex(item);
|
// progresser->addTrackedIndex(item);
|
||||||
return item;
|
return item;
|
||||||
@ -46,7 +46,7 @@ QStandardItem *createItem(const int index, const QString &category)
|
|||||||
QStandardItem *item = new QStandardItem;
|
QStandardItem *item = new QStandardItem;
|
||||||
item->setText(QString("Item #%1").arg(index));
|
item->setText(QString("Item #%1").arg(index));
|
||||||
item->setData(icon(index), Qt::DecorationRole);
|
item->setData(icon(index), Qt::DecorationRole);
|
||||||
item->setData(category, CategorizedViewRoles::CategoryRole);
|
item->setData(category, GroupViewRoles::GroupRole);
|
||||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
// progresser->addTrackedIndex(item);
|
// progresser->addTrackedIndex(item);
|
||||||
return item;
|
return item;
|
||||||
|
8
main.h
8
main.h
@ -21,7 +21,7 @@ public:
|
|||||||
|
|
||||||
QStandardItem *addTrackedIndex(QStandardItem *item)
|
QStandardItem *addTrackedIndex(QStandardItem *item)
|
||||||
{
|
{
|
||||||
item->setData(1000, CategorizedViewRoles::ProgressMaximumRole);
|
item->setData(1000, GroupViewRoles::ProgressMaximumRole);
|
||||||
m_items.append(item);
|
m_items.append(item);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@ -33,10 +33,10 @@ slots:
|
|||||||
QList<QStandardItem *> toRemove;
|
QList<QStandardItem *> toRemove;
|
||||||
for (auto item : m_items)
|
for (auto item : m_items)
|
||||||
{
|
{
|
||||||
int maximum = item->data(CategorizedViewRoles::ProgressMaximumRole).toInt();
|
int maximum = item->data(GroupViewRoles::ProgressMaximumRole).toInt();
|
||||||
int value = item->data(CategorizedViewRoles::ProgressValueRole).toInt();
|
int value = item->data(GroupViewRoles::ProgressValueRole).toInt();
|
||||||
int newvalue = std::min(value + 3, maximum);
|
int newvalue = std::min(value + 3, maximum);
|
||||||
item->setData(newvalue, CategorizedViewRoles::ProgressValueRole);
|
item->setData(newvalue, GroupViewRoles::ProgressValueRole);
|
||||||
|
|
||||||
if(newvalue >= maximum)
|
if(newvalue >= maximum)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user