Reformat, Rename, Redo
This commit is contained in:
parent
c47933d95c
commit
3fb7a0faf0
24
.clang-format
Normal file
24
.clang-format
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
UseTab: true
|
||||||
|
IndentWidth: 4
|
||||||
|
TabWidth: 4
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentFunctionDeclarationAfterType: false
|
||||||
|
NamespaceIndentation: None
|
||||||
|
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
ColumnLimit: 96
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
|
||||||
|
Standard: Cpp11
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpaceAfterControlStatementKeyword: true
|
||||||
|
|
||||||
|
AlignTrailingComments: true
|
||||||
|
SpacesBeforeTrailingComments: 1
|
@ -23,17 +23,17 @@ find_package(Qt5Widgets REQUIRED)
|
|||||||
include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
|
include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
main.cpp
|
main.cpp
|
||||||
main.h
|
main.h
|
||||||
|
|
||||||
CategorizedView.h
|
GroupView.h
|
||||||
CategorizedView.cpp
|
GroupView.cpp
|
||||||
CategorizedViewCategory.h
|
Group.h
|
||||||
CategorizedViewCategory.cpp
|
Group.cpp
|
||||||
CategorizedProxyModel.h
|
GroupedProxyModel.h
|
||||||
CategorizedProxyModel.cpp
|
GroupedProxyModel.cpp
|
||||||
InstanceDelegate.h
|
InstanceDelegate.h
|
||||||
InstanceDelegate.cpp
|
InstanceDelegate.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(GroupView ${SOURCES})
|
add_executable(GroupView ${SOURCES})
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
#ifndef CATEGORIZEDPROXYMODEL_H
|
|
||||||
#define CATEGORIZEDPROXYMODEL_H
|
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
|
||||||
|
|
||||||
class CategorizedProxyModel : public QSortFilterProxyModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
CategorizedProxyModel(QObject *parent = 0);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // CATEGORIZEDPROXYMODEL_H
|
|
@ -1,32 +1,34 @@
|
|||||||
#include "CategorizedViewCategory.h"
|
#include "Group.h"
|
||||||
|
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
|
|
||||||
#include "CategorizedView.h"
|
#include "GroupView.h"
|
||||||
|
|
||||||
CategorizedViewCategory::CategorizedViewCategory(const QString &text, CategorizedView *view)
|
Group::Group(const QString &text, GroupView *view)
|
||||||
: view(view), text(text), collapsed(false)
|
: view(view), text(text), collapsed(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
CategorizedViewCategory::CategorizedViewCategory(const CategorizedViewCategory *other) :
|
Group::Group(const Group *other)
|
||||||
view(other->view), text(other->text), collapsed(other->collapsed), iconRect(other->iconRect), textRect(other->textRect)
|
: view(other->view), text(other->text), collapsed(other->collapsed),
|
||||||
|
iconRect(other->iconRect), textRect(other->textRect)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CategorizedViewCategory::update()
|
void Group::update()
|
||||||
{
|
{
|
||||||
firstRow = firstItem().row();
|
firstRow = 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(view->model()->index(i * view->itemsPerRow() + firstRow, 0));
|
rowHeights[i] = view->categoryRowHeight(
|
||||||
|
view->model()->index(i * view->itemsPerRow() + firstRow, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CategorizedViewCategory::drawHeader(QPainter *painter, const int y)
|
void Group::drawHeader(QPainter *painter, const int y)
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
@ -51,23 +53,27 @@ void CategorizedViewCategory::drawHeader(QPainter *painter, const int y)
|
|||||||
int textWidth = painter->fontMetrics().width(text);
|
int textWidth = painter->fontMetrics().width(text);
|
||||||
textRect = QRect(iconRect.right() + 4, y, textWidth, headerHeight());
|
textRect = QRect(iconRect.right() + 4, y, textWidth, headerHeight());
|
||||||
painter->setBrush(view->viewOptions().palette.text());
|
painter->setBrush(view->viewOptions().palette.text());
|
||||||
view->style()->drawItemText(painter, textRect, Qt::AlignHCenter | Qt::AlignVCenter, view->viewport()->palette(), true, text);
|
view->style()->drawItemText(painter, textRect, Qt::AlignHCenter | Qt::AlignVCenter,
|
||||||
|
view->viewport()->palette(), true, text);
|
||||||
|
|
||||||
// the line
|
// the line
|
||||||
painter->drawLine(textRect.right() + 4, y + headerHeight() / 2, view->contentWidth() - view->m_rightMargin, y + headerHeight() / 2);
|
painter->drawLine(textRect.right() + 4, y + headerHeight() / 2,
|
||||||
|
view->contentWidth() - view->m_rightMargin, y + headerHeight() / 2);
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CategorizedViewCategory::totalHeight() const
|
int Group::totalHeight() const
|
||||||
{
|
{
|
||||||
return headerHeight() + 5 + contentHeight();
|
return headerHeight() + 5 + contentHeight();
|
||||||
}
|
}
|
||||||
int CategorizedViewCategory::headerHeight() const
|
|
||||||
|
int Group::headerHeight() const
|
||||||
{
|
{
|
||||||
return view->viewport()->fontMetrics().height() + 4;
|
return view->viewport()->fontMetrics().height() + 4;
|
||||||
}
|
}
|
||||||
int CategorizedViewCategory::contentHeight() const
|
|
||||||
|
int Group::contentHeight() const
|
||||||
{
|
{
|
||||||
if (collapsed)
|
if (collapsed)
|
||||||
{
|
{
|
||||||
@ -80,14 +86,16 @@ int CategorizedViewCategory::contentHeight() const
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
int CategorizedViewCategory::numRows() const
|
|
||||||
|
int Group::numRows() const
|
||||||
{
|
{
|
||||||
return qMax(1, qCeil((qreal)numItems() / (qreal)view->itemsPerRow()));
|
return qMax(1, qCeil((qreal)numItems() / (qreal)view->itemsPerRow()));
|
||||||
}
|
}
|
||||||
int CategorizedViewCategory::top() const
|
|
||||||
|
int Group::top() const
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
const QList<CategorizedViewCategory *> cats = view->m_categories;
|
const QList<Group *> cats = view->m_categories;
|
||||||
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)
|
||||||
@ -99,7 +107,7 @@ int CategorizedViewCategory::top() const
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QModelIndex> CategorizedViewCategory::items() const
|
QList<QModelIndex> Group::items() const
|
||||||
{
|
{
|
||||||
QList<QModelIndex> indices;
|
QList<QModelIndex> indices;
|
||||||
for (int i = 0; i < view->model()->rowCount(); ++i)
|
for (int i = 0; i < view->model()->rowCount(); ++i)
|
||||||
@ -112,16 +120,19 @@ QList<QModelIndex> CategorizedViewCategory::items() const
|
|||||||
}
|
}
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
int CategorizedViewCategory::numItems() const
|
|
||||||
|
int Group::numItems() const
|
||||||
{
|
{
|
||||||
return items().size();
|
return items().size();
|
||||||
}
|
}
|
||||||
QModelIndex CategorizedViewCategory::firstItem() const
|
|
||||||
|
QModelIndex Group::firstItem() const
|
||||||
{
|
{
|
||||||
QList<QModelIndex> indices = items();
|
QList<QModelIndex> indices = items();
|
||||||
return indices.isEmpty() ? QModelIndex() : indices.first();
|
return indices.isEmpty() ? QModelIndex() : indices.first();
|
||||||
}
|
}
|
||||||
QModelIndex CategorizedViewCategory::lastItem() const
|
|
||||||
|
QModelIndex Group::lastItem() const
|
||||||
{
|
{
|
||||||
QList<QModelIndex> indices = items();
|
QList<QModelIndex> indices = items();
|
||||||
return indices.isEmpty() ? QModelIndex() : indices.last();
|
return indices.isEmpty() ? QModelIndex() : indices.last();
|
@ -1,19 +1,18 @@
|
|||||||
#ifndef CATEGORIZEDVIEWROW_H
|
#pragma once
|
||||||
#define CATEGORIZEDVIEWROW_H
|
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
class CategorizedView;
|
class GroupView;
|
||||||
class QPainter;
|
class QPainter;
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
|
|
||||||
struct CategorizedViewCategory
|
struct Group
|
||||||
{
|
{
|
||||||
CategorizedViewCategory(const QString &text, CategorizedView *view);
|
Group(const QString &text, GroupView *view);
|
||||||
CategorizedViewCategory(const CategorizedViewCategory *other);
|
Group(const Group *other);
|
||||||
CategorizedView *view;
|
GroupView *view;
|
||||||
QString text;
|
QString text;
|
||||||
bool collapsed;
|
bool collapsed;
|
||||||
QRect iconRect;
|
QRect iconRect;
|
||||||
@ -35,5 +34,3 @@ struct CategorizedViewCategory
|
|||||||
QModelIndex firstItem() const;
|
QModelIndex firstItem() const;
|
||||||
QModelIndex lastItem() const;
|
QModelIndex lastItem() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CATEGORIZEDVIEWROW_H
|
|
@ -1,4 +1,4 @@
|
|||||||
#include "CategorizedView.h"
|
#include "GroupView.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@ -11,12 +11,11 @@
|
|||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
|
||||||
#include "CategorizedViewCategory.h"
|
#include "Group.h"
|
||||||
|
|
||||||
template<typename T>
|
template <typename T> bool listsIntersect(const QList<T> &l1, const QList<T> t2)
|
||||||
bool listsIntersect(const QList<T> &l1, const QList<T> t2)
|
|
||||||
{
|
{
|
||||||
foreach (const T &item, l1)
|
for (auto &item : l1)
|
||||||
{
|
{
|
||||||
if (t2.contains(item))
|
if (t2.contains(item))
|
||||||
{
|
{
|
||||||
@ -26,31 +25,33 @@ bool listsIntersect(const QList<T> &l1, const QList<T> t2)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CategorizedView::CategorizedView(QWidget *parent)
|
GroupView::GroupView(QWidget *parent)
|
||||||
: QListView(parent), m_leftMargin(5), m_rightMargin(5), m_bottomMargin(5), m_categoryMargin(5)//, m_updatesDisabled(false), m_categoryEditor(0), m_editedCategory(0)
|
: QListView(parent), m_leftMargin(5), m_rightMargin(5), m_bottomMargin(5),
|
||||||
|
m_categoryMargin(5) //, m_updatesDisabled(false), m_categoryEditor(0), m_editedCategory(0)
|
||||||
{
|
{
|
||||||
setViewMode(IconMode);
|
setViewMode(IconMode);
|
||||||
setMovement(Snap);
|
//setMovement(Snap);
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
setWordWrap(true);
|
setWordWrap(true);
|
||||||
setDragDropMode(QListView::InternalMove);
|
//setDragDropMode(QListView::InternalMove);
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
setSpacing(10);
|
setSpacing(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
CategorizedView::~CategorizedView()
|
GroupView::~GroupView()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_categories);
|
qDeleteAll(m_categories);
|
||||||
m_categories.clear();
|
m_categories.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CategorizedView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
void GroupView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
||||||
|
const QVector<int> &roles)
|
||||||
{
|
{
|
||||||
// if (m_updatesDisabled)
|
// if (m_updatesDisabled)
|
||||||
// {
|
// {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
QListView::dataChanged(topLeft, bottomRight, roles);
|
QListView::dataChanged(topLeft, bottomRight, roles);
|
||||||
|
|
||||||
@ -60,24 +61,25 @@ void CategorizedView::dataChanged(const QModelIndex &topLeft, const QModelIndex
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CategorizedView::rowsInserted(const QModelIndex &parent, int start, int end)
|
void GroupView::rowsInserted(const QModelIndex &parent, int start, int end)
|
||||||
{
|
{
|
||||||
// if (m_updatesDisabled)
|
// if (m_updatesDisabled)
|
||||||
// {
|
// {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
QListView::rowsInserted(parent, start, end);
|
QListView::rowsInserted(parent, start, end);
|
||||||
|
|
||||||
updateGeometries();
|
updateGeometries();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
void CategorizedView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
|
|
||||||
|
void GroupView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
|
||||||
{
|
{
|
||||||
// if (m_updatesDisabled)
|
// if (m_updatesDisabled)
|
||||||
// {
|
// {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
QListView::rowsAboutToBeRemoved(parent, start, end);
|
QListView::rowsAboutToBeRemoved(parent, start, end);
|
||||||
|
|
||||||
@ -85,27 +87,28 @@ void CategorizedView::rowsAboutToBeRemoved(const QModelIndex &parent, int start,
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CategorizedView::updateGeometries()
|
void GroupView::updateGeometries()
|
||||||
{
|
{
|
||||||
QListView::updateGeometries();
|
QListView::updateGeometries();
|
||||||
|
|
||||||
int previousScroll = verticalScrollBar()->value();
|
int previousScroll = verticalScrollBar()->value();
|
||||||
|
|
||||||
QMap<QString, CategorizedViewCategory *> cats;
|
QMap<QString, Group *> cats;
|
||||||
|
|
||||||
for (int i = 0; i < model()->rowCount(); ++i)
|
for (int i = 0; i < model()->rowCount(); ++i)
|
||||||
{
|
{
|
||||||
const QString category = model()->index(i, 0).data(CategorizedViewRoles::CategoryRole).toString();
|
const QString category =
|
||||||
|
model()->index(i, 0).data(CategorizedViewRoles::CategoryRole).toString();
|
||||||
if (!cats.contains(category))
|
if (!cats.contains(category))
|
||||||
{
|
{
|
||||||
CategorizedViewCategory *old = this->category(category);
|
Group *old = this->category(category);
|
||||||
if (old)
|
if (old)
|
||||||
{
|
{
|
||||||
cats.insert(category, new CategorizedViewCategory(old));
|
cats.insert(category, new Group(old));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cats.insert(category, new CategorizedViewCategory(category, this));
|
cats.insert(category, new Group(category, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,14 +133,14 @@ void CategorizedView::updateGeometries()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int totalHeight = 0;
|
int totalHeight = 0;
|
||||||
foreach (const CategorizedViewCategory *category, m_categories)
|
for (auto category : m_categories)
|
||||||
{
|
{
|
||||||
totalHeight += category->totalHeight() + m_categoryMargin;
|
totalHeight += category->totalHeight() + m_categoryMargin;
|
||||||
}
|
}
|
||||||
// remove the last margin (we don't want it)
|
// remove the last margin (we don't want it)
|
||||||
totalHeight -= m_categoryMargin;
|
totalHeight -= m_categoryMargin;
|
||||||
totalHeight += m_bottomMargin;
|
totalHeight += m_bottomMargin;
|
||||||
verticalScrollBar()->setRange(0, totalHeight- height());
|
verticalScrollBar()->setRange(0, totalHeight - height());
|
||||||
}
|
}
|
||||||
|
|
||||||
verticalScrollBar()->setValue(qMin(previousScroll, verticalScrollBar()->maximum()));
|
verticalScrollBar()->setValue(qMin(previousScroll, verticalScrollBar()->maximum()));
|
||||||
@ -145,9 +148,9 @@ void CategorizedView::updateGeometries()
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CategorizedView::isIndexHidden(const QModelIndex &index) const
|
bool GroupView::isIndexHidden(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
CategorizedViewCategory *cat = category(index);
|
Group *cat = category(index);
|
||||||
if (cat)
|
if (cat)
|
||||||
{
|
{
|
||||||
return cat->collapsed;
|
return cat->collapsed;
|
||||||
@ -158,11 +161,12 @@ bool CategorizedView::isIndexHidden(const QModelIndex &index) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CategorizedViewCategory *CategorizedView::category(const QModelIndex &index) const
|
Group *GroupView::category(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
return category(index.data(CategorizedViewRoles::CategoryRole).toString());
|
return category(index.data(CategorizedViewRoles::CategoryRole).toString());
|
||||||
}
|
}
|
||||||
CategorizedViewCategory *CategorizedView::category(const QString &cat) const
|
|
||||||
|
Group *GroupView::category(const QString &cat) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_categories.size(); ++i)
|
for (int i = 0; i < m_categories.size(); ++i)
|
||||||
{
|
{
|
||||||
@ -173,7 +177,8 @@ CategorizedViewCategory *CategorizedView::category(const QString &cat) const
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
CategorizedViewCategory *CategorizedView::categoryAt(const QPoint &pos) const
|
|
||||||
|
Group *GroupView::categoryAt(const QPoint &pos) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_categories.size(); ++i)
|
for (int i = 0; i < m_categories.size(); ++i)
|
||||||
{
|
{
|
||||||
@ -185,25 +190,28 @@ CategorizedViewCategory *CategorizedView::categoryAt(const QPoint &pos) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CategorizedView::itemsPerRow() const
|
int GroupView::itemsPerRow() const
|
||||||
{
|
{
|
||||||
return qFloor((qreal)(contentWidth()) / (qreal)(itemWidth() + spacing()));
|
return qFloor((qreal)(contentWidth()) / (qreal)(itemWidth() + /* spacing */ 10));
|
||||||
}
|
}
|
||||||
int CategorizedView::contentWidth() const
|
|
||||||
|
int GroupView::contentWidth() const
|
||||||
{
|
{
|
||||||
return width() - m_leftMargin - m_rightMargin;
|
return width() - m_leftMargin - m_rightMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CategorizedView::itemWidth() const
|
int GroupView::itemWidth() const
|
||||||
{
|
{
|
||||||
return itemDelegate()->sizeHint(viewOptions(), model()->index(model()->rowCount() -1, 0)).width();
|
return itemDelegate()
|
||||||
|
->sizeHint(viewOptions(), model()->index(model()->rowCount() - 1, 0))
|
||||||
|
.width();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CategorizedView::categoryRowHeight(const QModelIndex &index) const
|
int GroupView::categoryRowHeight(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QModelIndexList indices;
|
QModelIndexList indices;
|
||||||
int internalRow = categoryInternalPosition(index).second;
|
int internalRow = categoryInternalPosition(index).second;
|
||||||
foreach (const QModelIndex &i, category(index)->items())
|
for (auto &i : category(index)->items())
|
||||||
{
|
{
|
||||||
if (categoryInternalPosition(i).second == internalRow)
|
if (categoryInternalPosition(i).second == internalRow)
|
||||||
{
|
{
|
||||||
@ -212,14 +220,15 @@ int CategorizedView::categoryRowHeight(const QModelIndex &index) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
int largestHeight = 0;
|
int largestHeight = 0;
|
||||||
foreach (const QModelIndex &i, indices)
|
for (auto &i : indices)
|
||||||
{
|
{
|
||||||
largestHeight = qMax(largestHeight, itemDelegate()->sizeHint(viewOptions(), i).height());
|
largestHeight =
|
||||||
|
qMax(largestHeight, itemDelegate()->sizeHint(viewOptions(), i).height());
|
||||||
}
|
}
|
||||||
return largestHeight;
|
return largestHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<int, int> CategorizedView::categoryInternalPosition(const QModelIndex &index) const
|
QPair<int, int> GroupView::categoryInternalPosition(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QList<QModelIndex> indices = category(index)->items();
|
QList<QModelIndex> indices = category(index)->items();
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@ -240,9 +249,10 @@ QPair<int, int> CategorizedView::categoryInternalPosition(const QModelIndex &ind
|
|||||||
}
|
}
|
||||||
return qMakePair(x, y);
|
return qMakePair(x, y);
|
||||||
}
|
}
|
||||||
int CategorizedView::categoryInternalRowTop(const QModelIndex &index) const
|
|
||||||
|
int GroupView::categoryInternalRowTop(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
CategorizedViewCategory *cat = category(index);
|
Group *cat = category(index);
|
||||||
int categoryInternalRow = categoryInternalPosition(index).second;
|
int categoryInternalRow = categoryInternalPosition(index).second;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (int i = 0; i < categoryInternalRow; ++i)
|
for (int i = 0; i < categoryInternalRow; ++i)
|
||||||
@ -251,9 +261,11 @@ int CategorizedView::categoryInternalRowTop(const QModelIndex &index) const
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
int CategorizedView::itemHeightForCategoryRow(const CategorizedViewCategory *category, const int internalRow) const
|
|
||||||
|
int GroupView::itemHeightForCategoryRow(const Group *category,
|
||||||
|
const int internalRow) const
|
||||||
{
|
{
|
||||||
foreach (const QModelIndex &i, category->items())
|
for (auto &i : category->items())
|
||||||
{
|
{
|
||||||
QPair<int, int> pos = categoryInternalPosition(i);
|
QPair<int, int> pos = categoryInternalPosition(i);
|
||||||
if (pos.second == internalRow)
|
if (pos.second == internalRow)
|
||||||
@ -264,9 +276,9 @@ int CategorizedView::itemHeightForCategoryRow(const CategorizedViewCategory *cat
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CategorizedView::mousePressEvent(QMouseEvent *event)
|
void GroupView::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
//endCategoryEditor();
|
// endCategoryEditor();
|
||||||
|
|
||||||
QPoint pos = event->pos() + offset();
|
QPoint pos = event->pos() + offset();
|
||||||
QPersistentModelIndex index = indexAt(pos);
|
QPersistentModelIndex index = indexAt(pos);
|
||||||
@ -297,13 +309,15 @@ void CategorizedView::mousePressEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
// signal handlers may change the model
|
// signal handlers may change the model
|
||||||
emit pressed(index);
|
emit pressed(index);
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
// Forces a finalize() even if mouse is pressed, but not on a item
|
// Forces a finalize() even if mouse is pressed, but not on a item
|
||||||
selectionModel()->select(QModelIndex(), QItemSelectionModel::Select);
|
selectionModel()->select(QModelIndex(), QItemSelectionModel::Select);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CategorizedView::mouseMoveEvent(QMouseEvent *event)
|
|
||||||
|
void GroupView::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QPoint topLeft;
|
QPoint topLeft;
|
||||||
QPoint bottomRight = event->pos();
|
QPoint bottomRight = event->pos();
|
||||||
@ -337,10 +351,8 @@ void CategorizedView::mouseMoveEvent(QMouseEvent *event)
|
|||||||
topLeft = bottomRight;
|
topLeft = bottomRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_pressedIndex.isValid()
|
if (m_pressedIndex.isValid() && (state() != DragSelectingState) &&
|
||||||
&& (state() != DragSelectingState)
|
(event->buttons() != Qt::NoButton) && !selectedIndexes().isEmpty())
|
||||||
&& (event->buttons() != Qt::NoButton)
|
|
||||||
&& !selectedIndexes().isEmpty())
|
|
||||||
{
|
{
|
||||||
setState(DraggingState);
|
setState(DraggingState);
|
||||||
return;
|
return;
|
||||||
@ -350,7 +362,8 @@ void CategorizedView::mouseMoveEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
setState(DragSelectingState);
|
setState(DragSelectingState);
|
||||||
QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);
|
QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);
|
||||||
if (m_ctrlDragSelectionFlag != QItemSelectionModel::NoUpdate && command.testFlag(QItemSelectionModel::Toggle))
|
if (m_ctrlDragSelectionFlag != QItemSelectionModel::NoUpdate &&
|
||||||
|
command.testFlag(QItemSelectionModel::Toggle))
|
||||||
{
|
{
|
||||||
command &= ~QItemSelectionModel::Toggle;
|
command &= ~QItemSelectionModel::Toggle;
|
||||||
command |= m_ctrlDragSelectionFlag;
|
command |= m_ctrlDragSelectionFlag;
|
||||||
@ -361,20 +374,21 @@ void CategorizedView::mouseMoveEvent(QMouseEvent *event)
|
|||||||
setSelection(selectionRect, command);
|
setSelection(selectionRect, command);
|
||||||
|
|
||||||
// set at the end because it might scroll the view
|
// set at the end because it might scroll the view
|
||||||
if (index.isValid()
|
if (index.isValid() && (index != selectionModel()->currentIndex()) &&
|
||||||
&& (index != selectionModel()->currentIndex())
|
(index.flags() & Qt::ItemIsEnabled))
|
||||||
&& (index.flags() & Qt::ItemIsEnabled))
|
|
||||||
{
|
{
|
||||||
selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
|
selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CategorizedView::mouseReleaseEvent(QMouseEvent *event)
|
|
||||||
|
void GroupView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QPoint pos = event->pos() + offset();
|
QPoint pos = event->pos() + offset();
|
||||||
QPersistentModelIndex index = indexAt(pos);
|
QPersistentModelIndex index = indexAt(pos);
|
||||||
|
|
||||||
bool click = (index == m_pressedIndex && index.isValid()) || (m_pressedCategory && m_pressedCategory == categoryAt(pos));
|
bool click = (index == m_pressedIndex && index.isValid()) ||
|
||||||
|
(m_pressedCategory && m_pressedCategory == categoryAt(pos));
|
||||||
|
|
||||||
if (click && m_pressedCategory)
|
if (click && m_pressedCategory)
|
||||||
{
|
{
|
||||||
@ -411,23 +425,22 @@ void CategorizedView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
option.state |= QStyle::State_Selected;
|
option.state |= QStyle::State_Selected;
|
||||||
}
|
}
|
||||||
if ((model()->flags(index) & Qt::ItemIsEnabled)
|
if ((model()->flags(index) & Qt::ItemIsEnabled) &&
|
||||||
&& style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this))
|
style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this))
|
||||||
{
|
{
|
||||||
emit activated(index);
|
emit activated(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CategorizedView::mouseDoubleClickEvent(QMouseEvent *event)
|
|
||||||
|
void GroupView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QModelIndex index = indexAt(event->pos());
|
QModelIndex index = indexAt(event->pos());
|
||||||
if (!index.isValid()
|
if (!index.isValid() || !(index.flags() & Qt::ItemIsEnabled) || (m_pressedIndex != index))
|
||||||
|| !(index.flags() & Qt::ItemIsEnabled)
|
|
||||||
|| (m_pressedIndex != index))
|
|
||||||
{
|
{
|
||||||
QMouseEvent me(QEvent::MouseButtonPress,
|
QMouseEvent me(QEvent::MouseButtonPress, event->localPos(), event->windowPos(),
|
||||||
event->localPos(), event->windowPos(), event->screenPos(),
|
event->screenPos(), event->button(), event->buttons(),
|
||||||
event->button(), event->buttons(), event->modifiers());
|
event->modifiers());
|
||||||
mousePressEvent(&me);
|
mousePressEvent(&me);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -435,7 +448,8 @@ void CategorizedView::mouseDoubleClickEvent(QMouseEvent *event)
|
|||||||
QPersistentModelIndex persistent = index;
|
QPersistentModelIndex persistent = index;
|
||||||
emit doubleClicked(persistent);
|
emit doubleClicked(persistent);
|
||||||
}
|
}
|
||||||
void CategorizedView::paintEvent(QPaintEvent *event)
|
|
||||||
|
void GroupView::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPainter painter(this->viewport());
|
QPainter painter(this->viewport());
|
||||||
painter.translate(-offset());
|
painter.translate(-offset());
|
||||||
@ -443,7 +457,7 @@ void CategorizedView::paintEvent(QPaintEvent *event)
|
|||||||
int y = 0;
|
int y = 0;
|
||||||
for (int i = 0; i < m_categories.size(); ++i)
|
for (int i = 0; i < m_categories.size(); ++i)
|
||||||
{
|
{
|
||||||
CategorizedViewCategory *category = m_categories.at(i);
|
Group *category = m_categories.at(i);
|
||||||
category->drawHeader(&painter, y);
|
category->drawHeader(&painter, y);
|
||||||
y += category->totalHeight() + m_categoryMargin;
|
y += category->totalHeight() + m_categoryMargin;
|
||||||
}
|
}
|
||||||
@ -459,10 +473,11 @@ void CategorizedView::paintEvent(QPaintEvent *event)
|
|||||||
QStyleOptionViewItemV4 option(viewOptions());
|
QStyleOptionViewItemV4 option(viewOptions());
|
||||||
option.rect = visualRect(index);
|
option.rect = visualRect(index);
|
||||||
option.widget = this;
|
option.widget = this;
|
||||||
option.features |= wordWrap() ? QStyleOptionViewItemV2::WrapText : QStyleOptionViewItemV2::None;
|
option.features |= QStyleOptionViewItemV2::WrapText; // FIXME: what is the meaning of this anyway?
|
||||||
if (flags & Qt::ItemIsSelectable && selectionModel()->isSelected(index))
|
if (flags & Qt::ItemIsSelectable && selectionModel()->isSelected(index))
|
||||||
{
|
{
|
||||||
option.state |= selectionModel()->isSelected(index) ? QStyle::State_Selected : QStyle::State_None;
|
option.state |= selectionModel()->isSelected(index) ? QStyle::State_Selected
|
||||||
|
: QStyle::State_None;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -478,8 +493,8 @@ void CategorizedView::paintEvent(QPaintEvent *event)
|
|||||||
|
|
||||||
if (!m_lastDragPosition.isNull())
|
if (!m_lastDragPosition.isNull())
|
||||||
{
|
{
|
||||||
QPair<CategorizedViewCategory *, int> pair = rowDropPos(m_lastDragPosition);
|
QPair<Group *, int> pair = rowDropPos(m_lastDragPosition);
|
||||||
CategorizedViewCategory *category = pair.first;
|
Group *category = pair.first;
|
||||||
int row = pair.second;
|
int row = pair.second;
|
||||||
if (category)
|
if (category)
|
||||||
{
|
{
|
||||||
@ -502,19 +517,21 @@ void CategorizedView::paintEvent(QPaintEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CategorizedView::resizeEvent(QResizeEvent *event)
|
|
||||||
|
void GroupView::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
QListView::resizeEvent(event);
|
QListView::resizeEvent(event);
|
||||||
|
|
||||||
// if (m_categoryEditor)
|
// if (m_categoryEditor)
|
||||||
// {
|
// {
|
||||||
// m_categoryEditor->resize(qMax(contentWidth() / 2, m_editedCategory->textRect.width()), m_categoryEditor->height());
|
// m_categoryEditor->resize(qMax(contentWidth() / 2, m_editedCategory->textRect.width()),
|
||||||
// }
|
//m_categoryEditor->height());
|
||||||
|
// }
|
||||||
|
|
||||||
updateGeometries();
|
updateGeometries();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CategorizedView::dragEnterEvent(QDragEnterEvent *event)
|
void GroupView::dragEnterEvent(QDragEnterEvent *event)
|
||||||
{
|
{
|
||||||
if (!isDragEventAccepted(event))
|
if (!isDragEventAccepted(event))
|
||||||
{
|
{
|
||||||
@ -524,7 +541,8 @@ void CategorizedView::dragEnterEvent(QDragEnterEvent *event)
|
|||||||
viewport()->update();
|
viewport()->update();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
void CategorizedView::dragMoveEvent(QDragMoveEvent *event)
|
|
||||||
|
void GroupView::dragMoveEvent(QDragMoveEvent *event)
|
||||||
{
|
{
|
||||||
if (!isDragEventAccepted(event))
|
if (!isDragEventAccepted(event))
|
||||||
{
|
{
|
||||||
@ -534,12 +552,14 @@ void CategorizedView::dragMoveEvent(QDragMoveEvent *event)
|
|||||||
viewport()->update();
|
viewport()->update();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
void CategorizedView::dragLeaveEvent(QDragLeaveEvent *event)
|
|
||||||
|
void GroupView::dragLeaveEvent(QDragLeaveEvent *event)
|
||||||
{
|
{
|
||||||
m_lastDragPosition = QPoint();
|
m_lastDragPosition = QPoint();
|
||||||
viewport()->update();
|
viewport()->update();
|
||||||
}
|
}
|
||||||
void CategorizedView::dropEvent(QDropEvent *event)
|
|
||||||
|
void GroupView::dropEvent(QDropEvent *event)
|
||||||
{
|
{
|
||||||
m_lastDragPosition = QPoint();
|
m_lastDragPosition = QPoint();
|
||||||
|
|
||||||
@ -551,8 +571,8 @@ void CategorizedView::dropEvent(QDropEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<CategorizedViewCategory *, int> dropPos = rowDropPos(event->pos() + offset());
|
QPair<Group *, int> dropPos = rowDropPos(event->pos() + offset());
|
||||||
const CategorizedViewCategory *category = dropPos.first;
|
const Group *category = dropPos.first;
|
||||||
const int row = dropPos.second;
|
const int row = dropPos.second;
|
||||||
|
|
||||||
if (row == -1)
|
if (row == -1)
|
||||||
@ -564,7 +584,8 @@ void CategorizedView::dropEvent(QDropEvent *event)
|
|||||||
const QString categoryText = category->text;
|
const QString categoryText = category->text;
|
||||||
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, CategorizedViewRoles::CategoryRole);
|
model()->setData(model()->index(row, 0), categoryText,
|
||||||
|
CategorizedViewRoles::CategoryRole);
|
||||||
event->setDropAction(Qt::MoveAction);
|
event->setDropAction(Qt::MoveAction);
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
@ -572,7 +593,7 @@ void CategorizedView::dropEvent(QDropEvent *event)
|
|||||||
viewport()->update();
|
viewport()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CategorizedView::startDrag(Qt::DropActions supportedActions)
|
void GroupView::startDrag(Qt::DropActions supportedActions)
|
||||||
{
|
{
|
||||||
QModelIndexList indexes = selectionModel()->selectedIndexes();
|
QModelIndexList indexes = selectionModel()->selectedIndexes();
|
||||||
if (indexes.count() > 0)
|
if (indexes.count() > 0)
|
||||||
@ -585,13 +606,14 @@ void CategorizedView::startDrag(Qt::DropActions supportedActions)
|
|||||||
QRect rect;
|
QRect rect;
|
||||||
QPixmap pixmap = renderToPixmap(indexes, &rect);
|
QPixmap pixmap = renderToPixmap(indexes, &rect);
|
||||||
rect.translate(offset());
|
rect.translate(offset());
|
||||||
//rect.adjust(horizontalOffset(), verticalOffset(), 0, 0);
|
// rect.adjust(horizontalOffset(), verticalOffset(), 0, 0);
|
||||||
QDrag *drag = new QDrag(this);
|
QDrag *drag = new QDrag(this);
|
||||||
drag->setPixmap(pixmap);
|
drag->setPixmap(pixmap);
|
||||||
drag->setMimeData(data);
|
drag->setMimeData(data);
|
||||||
drag->setHotSpot(m_pressedPosition - rect.topLeft());
|
drag->setHotSpot(m_pressedPosition - rect.topLeft());
|
||||||
Qt::DropAction defaultDropAction = Qt::IgnoreAction;
|
Qt::DropAction defaultDropAction = Qt::IgnoreAction;
|
||||||
if (this->defaultDropAction() != Qt::IgnoreAction && (supportedActions & this->defaultDropAction()))
|
if (this->defaultDropAction() != Qt::IgnoreAction &&
|
||||||
|
(supportedActions & this->defaultDropAction()))
|
||||||
{
|
{
|
||||||
defaultDropAction = this->defaultDropAction();
|
defaultDropAction = this->defaultDropAction();
|
||||||
}
|
}
|
||||||
@ -599,7 +621,8 @@ void CategorizedView::startDrag(Qt::DropActions supportedActions)
|
|||||||
{
|
{
|
||||||
const QItemSelection selection = selectionModel()->selection();
|
const QItemSelection selection = selectionModel()->selection();
|
||||||
|
|
||||||
for (auto it = selection.constBegin(); it != selection.constEnd(); ++it) {
|
for (auto it = selection.constBegin(); it != selection.constEnd(); ++it)
|
||||||
|
{
|
||||||
QModelIndex parent = (*it).parent();
|
QModelIndex parent = (*it).parent();
|
||||||
if ((*it).left() != 0)
|
if ((*it).left() != 0)
|
||||||
{
|
{
|
||||||
@ -616,21 +639,21 @@ void CategorizedView::startDrag(Qt::DropActions supportedActions)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect CategorizedView::visualRect(const QModelIndex &index) const
|
QRect GroupView::visualRect(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid() || isIndexHidden(index) || index.column() > 0)
|
if (!index.isValid() || isIndexHidden(index) || index.column() > 0)
|
||||||
{
|
{
|
||||||
return QRect();
|
return QRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CategorizedViewCategory *cat = category(index);
|
const Group *cat = category(index);
|
||||||
QPair<int, int> pos = categoryInternalPosition(index);
|
QPair<int, int> pos = categoryInternalPosition(index);
|
||||||
int x = pos.first;
|
int x = pos.first;
|
||||||
int y = pos.second;
|
int y = pos.second;
|
||||||
|
|
||||||
QRect out;
|
QRect out;
|
||||||
out.setTop(cat->top() + cat->headerHeight() + 5 + categoryInternalRowTop(index));
|
out.setTop(cat->top() + cat->headerHeight() + 5 + categoryInternalRowTop(index));
|
||||||
out.setLeft(spacing() + x * itemWidth() + x * spacing());
|
out.setLeft(/*spacing*/ 10 + x * itemWidth() + x * /*spacing()*/ 10);
|
||||||
out.setSize(itemDelegate()->sizeHint(viewOptions(), index));
|
out.setSize(itemDelegate()->sizeHint(viewOptions(), index));
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
@ -649,7 +672,8 @@ void CategorizedView::startCategoryEditor(Category *category)
|
|||||||
m_categoryEditor->setGeometry(rect);
|
m_categoryEditor->setGeometry(rect);
|
||||||
m_categoryEditor->show();
|
m_categoryEditor->show();
|
||||||
m_categoryEditor->setFocus();
|
m_categoryEditor->setFocus();
|
||||||
connect(m_categoryEditor, &QLineEdit::returnPressed, this, &CategorizedView::endCategoryEditor);
|
connect(m_categoryEditor, &QLineEdit::returnPressed, this,
|
||||||
|
&CategorizedView::endCategoryEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CategorizedView::endCategoryEditor()
|
void CategorizedView::endCategoryEditor()
|
||||||
@ -662,7 +686,8 @@ void CategorizedView::endCategoryEditor()
|
|||||||
m_updatesDisabled = true;
|
m_updatesDisabled = true;
|
||||||
foreach (const QModelIndex &index, itemsForCategory(m_editedCategory))
|
foreach (const QModelIndex &index, itemsForCategory(m_editedCategory))
|
||||||
{
|
{
|
||||||
const_cast<QAbstractItemModel *>(index.model())->setData(index, m_categoryEditor->text(), CategoryRole);
|
const_cast<QAbstractItemModel *>(index.model())->setData(index,
|
||||||
|
m_categoryEditor->text(), CategoryRole);
|
||||||
}
|
}
|
||||||
m_updatesDisabled = false;
|
m_updatesDisabled = false;
|
||||||
delete m_categoryEditor;
|
delete m_categoryEditor;
|
||||||
@ -672,7 +697,7 @@ void CategorizedView::endCategoryEditor()
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QModelIndex CategorizedView::indexAt(const QPoint &point) const
|
QModelIndex GroupView::indexAt(const QPoint &point) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < model()->rowCount(); ++i)
|
for (int i = 0; i < model()->rowCount(); ++i)
|
||||||
{
|
{
|
||||||
@ -684,7 +709,9 @@ QModelIndex CategorizedView::indexAt(const QPoint &point) const
|
|||||||
}
|
}
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
void CategorizedView::setSelection(const QRect &rect, const QItemSelectionModel::SelectionFlags commands)
|
|
||||||
|
void GroupView::setSelection(const QRect &rect,
|
||||||
|
const QItemSelectionModel::SelectionFlags commands)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < model()->rowCount(); ++i)
|
for (int i = 0; i < model()->rowCount(); ++i)
|
||||||
{
|
{
|
||||||
@ -697,10 +724,10 @@ void CategorizedView::setSelection(const QRect &rect, const QItemSelectionModel:
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap CategorizedView::renderToPixmap(const QModelIndexList &indices, QRect *r) const
|
QPixmap GroupView::renderToPixmap(const QModelIndexList &indices, QRect *r) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(r);
|
Q_ASSERT(r);
|
||||||
QList<QPair<QRect, QModelIndex> > paintPairs = draggablePaintPairs(indices, r);
|
auto paintPairs = draggablePaintPairs(indices, r);
|
||||||
if (paintPairs.isEmpty())
|
if (paintPairs.isEmpty())
|
||||||
{
|
{
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
@ -718,16 +745,20 @@ QPixmap CategorizedView::renderToPixmap(const QModelIndexList &indices, QRect *r
|
|||||||
}
|
}
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
QList<QPair<QRect, QModelIndex> > CategorizedView::draggablePaintPairs(const QModelIndexList &indices, QRect *r) const
|
|
||||||
|
QList<QPair<QRect, QModelIndex>>
|
||||||
|
GroupView::draggablePaintPairs(const QModelIndexList &indices, QRect *r) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(r);
|
Q_ASSERT(r);
|
||||||
QRect &rect = *r;
|
QRect &rect = *r;
|
||||||
const QRect viewportRect = viewport()->rect();
|
const QRect viewportRect = viewport()->rect();
|
||||||
QList<QPair<QRect, QModelIndex> > ret;
|
QList<QPair<QRect, QModelIndex>> ret;
|
||||||
for (int i = 0; i < indices.count(); ++i) {
|
for (int i = 0; i < indices.count(); ++i)
|
||||||
|
{
|
||||||
const QModelIndex &index = indices.at(i);
|
const QModelIndex &index = indices.at(i);
|
||||||
const QRect current = visualRect(index);
|
const QRect current = visualRect(index);
|
||||||
if (current.intersects(viewportRect)) {
|
if (current.intersects(viewportRect))
|
||||||
|
{
|
||||||
ret += qMakePair(current, index);
|
ret += qMakePair(current, index);
|
||||||
rect |= current;
|
rect |= current;
|
||||||
}
|
}
|
||||||
@ -736,7 +767,7 @@ QList<QPair<QRect, QModelIndex> > CategorizedView::draggablePaintPairs(const QMo
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CategorizedView::isDragEventAccepted(QDropEvent *event)
|
bool GroupView::isDragEventAccepted(QDropEvent *event)
|
||||||
{
|
{
|
||||||
if (event->source() != this)
|
if (event->source() != this)
|
||||||
{
|
{
|
||||||
@ -746,19 +777,21 @@ bool CategorizedView::isDragEventAccepted(QDropEvent *event)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!model()->canDropMimeData(event->mimeData(), event->dropAction(), rowDropPos(event->pos()).second, 0, QModelIndex()))
|
if (!model()->canDropMimeData(event->mimeData(), event->dropAction(),
|
||||||
|
rowDropPos(event->pos()).second, 0, QModelIndex()))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
QPair<CategorizedViewCategory *, int> CategorizedView::rowDropPos(const QPoint &pos)
|
|
||||||
|
QPair<Group *, int> GroupView::rowDropPos(const QPoint &pos)
|
||||||
{
|
{
|
||||||
// check that we aren't on a category header and calculate which category we're in
|
// check that we aren't on a category header and calculate which category we're in
|
||||||
CategorizedViewCategory *category = 0;
|
Group *category = 0;
|
||||||
{
|
{
|
||||||
int y = 0;
|
int y = 0;
|
||||||
foreach (CategorizedViewCategory *cat, m_categories)
|
foreach(Group * cat, m_categories)
|
||||||
{
|
{
|
||||||
if (pos.y() > y && pos.y() < (y + cat->headerHeight()))
|
if (pos.y() > y && pos.y() < (y + cat->headerHeight()))
|
||||||
{
|
{
|
||||||
@ -789,12 +822,9 @@ QPair<CategorizedViewCategory *, int> CategorizedView::rowDropPos(const QPoint &
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = 0, c = 0;
|
for (int i = 0, c = 0; i < contentWidth(); i += itemWidth + 10 /*spacing()*/, ++c)
|
||||||
i < contentWidth();
|
|
||||||
i += itemWidth + spacing(), ++c)
|
|
||||||
{
|
{
|
||||||
if (pos.x() > (i - itemWidth / 2) &&
|
if (pos.x() > (i - itemWidth / 2) && pos.x() <= (i + itemWidth / 2))
|
||||||
pos.x() <= (i + itemWidth / 2))
|
|
||||||
{
|
{
|
||||||
internalColumn = c;
|
internalColumn = c;
|
||||||
break;
|
break;
|
||||||
@ -812,7 +842,8 @@ QPair<CategorizedViewCategory *, int> CategorizedView::rowDropPos(const QPoint &
|
|||||||
{
|
{
|
||||||
// FIXME rework the drag and drop code
|
// FIXME rework the drag and drop code
|
||||||
const int top = category->top();
|
const int top = category->top();
|
||||||
for (int r = 0, h = top; r < category->numRows(); h += itemHeightForCategoryRow(category, r), ++r)
|
for (int r = 0, h = top; r < category->numRows();
|
||||||
|
h += itemHeightForCategoryRow(category, r), ++r)
|
||||||
{
|
{
|
||||||
if (pos.y() > h && pos.y() < (h + itemHeightForCategoryRow(category, r)))
|
if (pos.y() > h && pos.y() < (h + itemHeightForCategoryRow(category, r)))
|
||||||
{
|
{
|
||||||
@ -844,7 +875,7 @@ QPair<CategorizedViewCategory *, int> CategorizedView::rowDropPos(const QPoint &
|
|||||||
return qMakePair(category, indices.at(categoryRow).row());
|
return qMakePair(category, indices.at(categoryRow).row());
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint CategorizedView::offset() const
|
QPoint GroupView::offset() const
|
||||||
{
|
{
|
||||||
return QPoint(horizontalOffset(), verticalOffset());
|
return QPoint(horizontalOffset(), verticalOffset());
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef WIDGET_H
|
#pragma once
|
||||||
#define WIDGET_H
|
|
||||||
|
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
@ -14,22 +13,25 @@ struct CategorizedViewRoles
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CategorizedViewCategory;
|
struct Group;
|
||||||
|
|
||||||
class CategorizedView : public QListView
|
class GroupView : public QListView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CategorizedView(QWidget *parent = 0);
|
GroupView(QWidget *parent = 0);
|
||||||
~CategorizedView();
|
~GroupView();
|
||||||
|
|
||||||
virtual QRect visualRect(const QModelIndex &index) const;
|
virtual QRect visualRect(const QModelIndex &index) const;
|
||||||
QModelIndex indexAt(const QPoint &point) const;
|
QModelIndex indexAt(const QPoint &point) const;
|
||||||
void setSelection(const QRect &rect, const QItemSelectionModel::SelectionFlags commands) override;
|
void setSelection(const QRect &rect,
|
||||||
|
const QItemSelectionModel::SelectionFlags commands) override;
|
||||||
|
|
||||||
protected slots:
|
protected
|
||||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
slots:
|
||||||
|
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
||||||
|
const QVector<int> &roles);
|
||||||
virtual void rowsInserted(const QModelIndex &parent, int start, int end);
|
virtual void rowsInserted(const QModelIndex &parent, int start, int end);
|
||||||
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
|
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
|
||||||
virtual void updateGeometries();
|
virtual void updateGeometries();
|
||||||
@ -51,20 +53,20 @@ protected:
|
|||||||
void startDrag(Qt::DropActions supportedActions) override;
|
void startDrag(Qt::DropActions supportedActions) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend struct CategorizedViewCategory;
|
friend struct Group;
|
||||||
|
|
||||||
QList<CategorizedViewCategory *> m_categories;
|
QList<Group *> m_categories;
|
||||||
|
|
||||||
int m_leftMargin;
|
int m_leftMargin;
|
||||||
int m_rightMargin;
|
int m_rightMargin;
|
||||||
int m_bottomMargin;
|
int m_bottomMargin;
|
||||||
int m_categoryMargin;
|
int m_categoryMargin;
|
||||||
|
|
||||||
//bool m_updatesDisabled;
|
// bool m_updatesDisabled;
|
||||||
|
|
||||||
CategorizedViewCategory *category(const QModelIndex &index) const;
|
Group *category(const QModelIndex &index) const;
|
||||||
CategorizedViewCategory *category(const QString &cat) const;
|
Group *category(const QString &cat) const;
|
||||||
CategorizedViewCategory *categoryAt(const QPoint &pos) const;
|
Group *categoryAt(const QPoint &pos) const;
|
||||||
|
|
||||||
int itemsPerRow() const;
|
int itemsPerRow() const;
|
||||||
int contentWidth() const;
|
int contentWidth() const;
|
||||||
@ -84,22 +86,22 @@ private:
|
|||||||
QPoint m_pressedPosition;
|
QPoint m_pressedPosition;
|
||||||
QPersistentModelIndex m_pressedIndex;
|
QPersistentModelIndex m_pressedIndex;
|
||||||
bool m_pressedAlreadySelected;
|
bool m_pressedAlreadySelected;
|
||||||
CategorizedViewCategory *m_pressedCategory;
|
Group *m_pressedCategory;
|
||||||
QItemSelectionModel::SelectionFlag m_ctrlDragSelectionFlag;
|
QItemSelectionModel::SelectionFlag m_ctrlDragSelectionFlag;
|
||||||
QPoint m_lastDragPosition;
|
QPoint m_lastDragPosition;
|
||||||
|
|
||||||
QPair<int, int> categoryInternalPosition(const QModelIndex &index) const;
|
QPair<int, int> categoryInternalPosition(const QModelIndex &index) const;
|
||||||
int categoryInternalRowTop(const QModelIndex &index) const;
|
int categoryInternalRowTop(const QModelIndex &index) const;
|
||||||
int itemHeightForCategoryRow(const CategorizedViewCategory *category, const int internalRow) const;
|
int itemHeightForCategoryRow(const Group *category,
|
||||||
|
const int internalRow) const;
|
||||||
|
|
||||||
QPixmap renderToPixmap(const QModelIndexList &indices, QRect *r) const;
|
QPixmap renderToPixmap(const QModelIndexList &indices, QRect *r) const;
|
||||||
QList<QPair<QRect, QModelIndex> > draggablePaintPairs(const QModelIndexList &indices, QRect *r) const;
|
QList<QPair<QRect, QModelIndex>> draggablePaintPairs(const QModelIndexList &indices,
|
||||||
|
QRect *r) const;
|
||||||
|
|
||||||
bool isDragEventAccepted(QDropEvent *event);
|
bool isDragEventAccepted(QDropEvent *event);
|
||||||
|
|
||||||
QPair<CategorizedViewCategory *, int> rowDropPos(const QPoint &pos);
|
QPair<Group *, int> rowDropPos(const QPoint &pos);
|
||||||
|
|
||||||
QPoint offset() const;
|
QPoint offset() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WIDGET_H
|
|
@ -1,12 +1,12 @@
|
|||||||
#include "CategorizedProxyModel.h"
|
#include "GroupedProxyModel.h"
|
||||||
|
|
||||||
#include "CategorizedView.h"
|
#include "GroupView.h"
|
||||||
|
|
||||||
CategorizedProxyModel::CategorizedProxyModel(QObject *parent)
|
GroupedProxyModel::GroupedProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
|
||||||
: QSortFilterProxyModel(parent)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
bool CategorizedProxyModel::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(CategorizedViewRoles::CategoryRole).toString();
|
||||||
const QString rightCategory = right.data(CategorizedViewRoles::CategoryRole).toString();
|
const QString rightCategory = right.data(CategorizedViewRoles::CategoryRole).toString();
|
14
GroupedProxyModel.h
Normal file
14
GroupedProxyModel.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
class GroupedProxyModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
GroupedProxyModel(QObject *parent = 0);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||||
|
};
|
@ -20,7 +20,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QtCore/qmath.h>
|
#include <QtCore/qmath.h>
|
||||||
|
|
||||||
#include "CategorizedView.h"
|
#include "GroupView.h"
|
||||||
|
|
||||||
// Origin: Qt
|
// Origin: Qt
|
||||||
static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &height,
|
static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &height,
|
||||||
@ -88,7 +88,8 @@ void drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO this can be made a lot prettier
|
// TODO this can be made a lot prettier
|
||||||
void drawProgressOverlay(QPainter *painter, const QStyleOptionViewItemV4 &option, const int value, const int maximum)
|
void drawProgressOverlay(QPainter *painter, const QStyleOptionViewItemV4 &option,
|
||||||
|
const int value, const int maximum)
|
||||||
{
|
{
|
||||||
if (maximum == 0 || value == maximum)
|
if (maximum == 0 || value == maximum)
|
||||||
{
|
{
|
||||||
@ -251,7 +252,8 @@ void ListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
|||||||
line.draw(painter, position);
|
line.draw(painter, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawProgressOverlay(painter, opt, index.data(CategorizedViewRoles::ProgressValueRole).toInt(),
|
drawProgressOverlay(painter, opt,
|
||||||
|
index.data(CategorizedViewRoles::ProgressValueRole).toInt(),
|
||||||
index.data(CategorizedViewRoles::ProgressMaximumRole).toInt());
|
index.data(CategorizedViewRoles::ProgressMaximumRole).toInt());
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
@ -20,8 +20,10 @@
|
|||||||
class ListViewDelegate : public QStyledItemDelegate
|
class ListViewDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ListViewDelegate ( QObject* parent = 0 );
|
explicit ListViewDelegate(QObject *parent = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
const QModelIndex &index) const;
|
||||||
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
};
|
};
|
||||||
|
25
main.cpp
25
main.cpp
@ -5,8 +5,8 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
|
||||||
#include "CategorizedView.h"
|
#include "GroupView.h"
|
||||||
#include "CategorizedProxyModel.h"
|
#include "GroupedProxyModel.h"
|
||||||
#include "InstanceDelegate.h"
|
#include "InstanceDelegate.h"
|
||||||
|
|
||||||
Progresser *progresser;
|
Progresser *progresser;
|
||||||
@ -25,18 +25,20 @@ QPixmap icon(const int number)
|
|||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
font.setPixelSize(28);
|
font.setPixelSize(28);
|
||||||
painter.setFont(font);
|
painter.setFont(font);
|
||||||
painter.drawText(QRect(QPoint(0, 0), p.size()), Qt::AlignVCenter | Qt::AlignHCenter, QString::number(number));
|
painter.drawText(QRect(QPoint(0, 0), p.size()), Qt::AlignVCenter | Qt::AlignHCenter,
|
||||||
|
QString::number(number));
|
||||||
painter.end();
|
painter.end();
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
QStandardItem *createItem(const Qt::GlobalColor color, const QString &text, const QString &category)
|
QStandardItem *createItem(const Qt::GlobalColor color, const QString &text,
|
||||||
|
const QString &category)
|
||||||
{
|
{
|
||||||
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, CategorizedViewRoles::CategoryRole);
|
||||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
//progresser->addTrackedIndex(item);
|
// progresser->addTrackedIndex(item);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
QStandardItem *createItem(const int index, const QString &category)
|
QStandardItem *createItem(const int index, const QString &category)
|
||||||
@ -46,7 +48,7 @@ QStandardItem *createItem(const int index, const QString &category)
|
|||||||
item->setData(icon(index), Qt::DecorationRole);
|
item->setData(icon(index), Qt::DecorationRole);
|
||||||
item->setData(category, CategorizedViewRoles::CategoryRole);
|
item->setData(category, CategorizedViewRoles::CategoryRole);
|
||||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
//progresser->addTrackedIndex(item);
|
// progresser->addTrackedIndex(item);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +64,10 @@ int main(int argc, char *argv[])
|
|||||||
model.setRowCount(10);
|
model.setRowCount(10);
|
||||||
model.setColumnCount(1);
|
model.setColumnCount(1);
|
||||||
|
|
||||||
model.setItem(0, createItem(Qt::red, "Red is a color. Some more text. I'm out of ideas. 42. What's your name?", "Colorful"));
|
model.setItem(
|
||||||
|
0, createItem(Qt::red,
|
||||||
|
"Red is a color. Some more text. I'm out of ideas. 42. What's your name?",
|
||||||
|
"Colorful"));
|
||||||
model.setItem(1, createItem(Qt::blue, "Blue", "Colorful"));
|
model.setItem(1, createItem(Qt::blue, "Blue", "Colorful"));
|
||||||
model.setItem(2, createItem(Qt::yellow, "Yellow", "Colorful"));
|
model.setItem(2, createItem(Qt::yellow, "Yellow", "Colorful"));
|
||||||
|
|
||||||
@ -77,13 +82,13 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
for (int i = 0; i < 20; ++i)
|
for (int i = 0; i < 20; ++i)
|
||||||
{
|
{
|
||||||
model.setItem(i + 10, createItem(i+1, "Items 1-20"));
|
model.setItem(i + 10, createItem(i + 1, "Items 1-20"));
|
||||||
}
|
}
|
||||||
|
|
||||||
CategorizedProxyModel pModel;
|
GroupedProxyModel pModel;
|
||||||
pModel.setSourceModel(&model);
|
pModel.setSourceModel(&model);
|
||||||
|
|
||||||
CategorizedView w;
|
GroupView w;
|
||||||
w.setItemDelegate(new ListViewDelegate);
|
w.setItemDelegate(new ListViewDelegate);
|
||||||
w.setModel(&pModel);
|
w.setModel(&pModel);
|
||||||
w.resize(640, 480);
|
w.resize(640, 480);
|
||||||
|
12
main.h
12
main.h
@ -1,5 +1,4 @@
|
|||||||
#ifndef MAIN_H
|
#pragma once
|
||||||
#define MAIN_H
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@ -7,7 +6,7 @@
|
|||||||
#include <QStandardItem>
|
#include <QStandardItem>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "CategorizedView.h"
|
#include "GroupView.h"
|
||||||
|
|
||||||
class Progresser : public QObject
|
class Progresser : public QObject
|
||||||
{
|
{
|
||||||
@ -27,10 +26,11 @@ public:
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
public
|
||||||
|
slots:
|
||||||
void timeout()
|
void timeout()
|
||||||
{
|
{
|
||||||
foreach (QStandardItem *item, m_items)
|
foreach(QStandardItem * item, m_items)
|
||||||
{
|
{
|
||||||
int value = item->data(CategorizedViewRoles::ProgressValueRole).toInt();
|
int value = item->data(CategorizedViewRoles::ProgressValueRole).toInt();
|
||||||
value += qrand() % 3;
|
value += qrand() % 3;
|
||||||
@ -49,5 +49,3 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
QList<QStandardItem *> m_items;
|
QList<QStandardItem *> m_items;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAIN_H
|
|
||||||
|
Loading…
Reference in New Issue
Block a user