GH-851 save, load and use group expansion status
This commit is contained in:
@ -175,6 +175,9 @@ void GroupView::updateGeometries()
|
||||
else
|
||||
{
|
||||
auto cat = new VisualGroup(groupName, this);
|
||||
if(fVisibility) {
|
||||
cat->collapsed = fVisibility(groupName);
|
||||
}
|
||||
cats.insert(groupName, cat);
|
||||
cat->update();
|
||||
}
|
||||
@ -384,6 +387,8 @@ void GroupView::mouseReleaseEvent(QMouseEvent *event)
|
||||
if (state() == ExpandingState)
|
||||
{
|
||||
m_pressedCategory->collapsed = false;
|
||||
emit groupStateChanged(m_pressedCategory->text, false);
|
||||
|
||||
updateGeometries();
|
||||
viewport()->update();
|
||||
event->accept();
|
||||
@ -392,6 +397,8 @@ void GroupView::mouseReleaseEvent(QMouseEvent *event)
|
||||
else if (state() == CollapsingState)
|
||||
{
|
||||
m_pressedCategory->collapsed = true;
|
||||
emit groupStateChanged(m_pressedCategory->text, true);
|
||||
|
||||
updateGeometries();
|
||||
viewport()->update();
|
||||
event->accept();
|
||||
@ -607,8 +614,7 @@ void GroupView::dropEvent(QDropEvent *event)
|
||||
const QString categoryText = category->text;
|
||||
if (model()->dropMimeData(event->mimeData(), Qt::MoveAction, row, 0, QModelIndex()))
|
||||
{
|
||||
model()->setData(model()->index(row, 0), categoryText,
|
||||
GroupViewRoles::GroupRole);
|
||||
model()->setData(model()->index(row, 0), categoryText, GroupViewRoles::GroupRole);
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
event->accept();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <QScrollBar>
|
||||
#include <QCache>
|
||||
#include "VisualGroup.h"
|
||||
#include <functional>
|
||||
|
||||
struct GroupViewRoles
|
||||
{
|
||||
@ -41,6 +42,11 @@ public:
|
||||
|
||||
void setModel(QAbstractItemModel *model) override;
|
||||
|
||||
using visibilityFunction = std::function<bool(const QString &)>;
|
||||
void setSourceOfGroupCollapseStatus(visibilityFunction f) {
|
||||
fVisibility = f;
|
||||
}
|
||||
|
||||
/// return geometry rectangle occupied by the specified model item
|
||||
QRect geometryRect(const QModelIndex &index) const;
|
||||
/// return visual rectangle occupied by the specified model item
|
||||
@ -48,8 +54,7 @@ public:
|
||||
/// get the model index at the specified visual point
|
||||
virtual QModelIndex indexAt(const QPoint &point) const override;
|
||||
QString groupNameAt(const QPoint &point);
|
||||
void setSelection(const QRect &rect,
|
||||
const QItemSelectionModel::SelectionFlags commands) override;
|
||||
void setSelection(const QRect &rect, const QItemSelectionModel::SelectionFlags commands) override;
|
||||
|
||||
virtual int horizontalOffset() const override;
|
||||
virtual int verticalOffset() const override;
|
||||
@ -80,6 +85,7 @@ protected slots:
|
||||
|
||||
signals:
|
||||
void droppedURLs(QList<QUrl> urls);
|
||||
void groupStateChanged(QString group, bool collapsed);
|
||||
|
||||
protected:
|
||||
virtual bool isIndexHidden(const QModelIndex &index) const override;
|
||||
@ -103,6 +109,8 @@ private:
|
||||
friend struct VisualGroup;
|
||||
QList<VisualGroup *> m_groups;
|
||||
|
||||
visibilityFunction fVisibility;
|
||||
|
||||
// geometry
|
||||
int m_leftMargin = 5;
|
||||
int m_rightMargin = 5;
|
||||
|
Reference in New Issue
Block a user