@ -35,95 +35,86 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QListView>
|
||||
#include <QLineEdit>
|
||||
#include <QScrollBar>
|
||||
#include <QCache>
|
||||
#include "VisualGroup.h"
|
||||
#include <QLineEdit>
|
||||
#include <QListView>
|
||||
#include <QScrollBar>
|
||||
#include <functional>
|
||||
#include "VisualGroup.h"
|
||||
|
||||
struct InstanceViewRoles
|
||||
{
|
||||
enum
|
||||
{
|
||||
GroupRole = Qt::UserRole,
|
||||
ProgressValueRole,
|
||||
ProgressMaximumRole
|
||||
};
|
||||
struct InstanceViewRoles {
|
||||
enum { GroupRole = Qt::UserRole, ProgressValueRole, ProgressMaximumRole };
|
||||
};
|
||||
|
||||
class InstanceView : public QAbstractItemView
|
||||
{
|
||||
class InstanceView : public QAbstractItemView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InstanceView(QWidget *parent = 0);
|
||||
public:
|
||||
InstanceView(QWidget* parent = 0);
|
||||
~InstanceView();
|
||||
|
||||
void setModel(QAbstractItemModel *model) override;
|
||||
void setModel(QAbstractItemModel* model) override;
|
||||
|
||||
using visibilityFunction = std::function<bool(const QString &)>;
|
||||
void setSourceOfGroupCollapseStatus(visibilityFunction f) {
|
||||
fVisibility = f;
|
||||
}
|
||||
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;
|
||||
QRect geometryRect(const QModelIndex& index) const;
|
||||
/// return visual rectangle occupied by the specified model item
|
||||
virtual QRect visualRect(const QModelIndex &index) const override;
|
||||
virtual QRect visualRect(const QModelIndex& index) const override;
|
||||
/// 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;
|
||||
virtual QModelIndex indexAt(const QPoint& point) const override;
|
||||
QString groupNameAt(const QPoint& point);
|
||||
void setSelection(const QRect& rect, const QItemSelectionModel::SelectionFlags commands) override;
|
||||
|
||||
virtual int horizontalOffset() const override;
|
||||
virtual int verticalOffset() const override;
|
||||
virtual void scrollContentsBy(int dx, int dy) override;
|
||||
virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
|
||||
virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible) override;
|
||||
|
||||
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
|
||||
|
||||
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const override;
|
||||
virtual QRegion visualRegionForSelection(const QItemSelection& selection) const override;
|
||||
|
||||
int spacing() const { return m_spacing; };
|
||||
void setPaintCat(bool visible);
|
||||
|
||||
public slots:
|
||||
public slots:
|
||||
virtual void updateGeometries() override;
|
||||
|
||||
protected slots:
|
||||
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) override;
|
||||
virtual void rowsInserted(const QModelIndex &parent, int start, int end) override;
|
||||
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
|
||||
protected slots:
|
||||
virtual void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) override;
|
||||
virtual void rowsInserted(const QModelIndex& parent, int start, int end) override;
|
||||
virtual void rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end) override;
|
||||
void modelReset();
|
||||
void rowsRemoved();
|
||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override;
|
||||
void currentChanged(const QModelIndex& current, const QModelIndex& previous) override;
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void droppedURLs(QList<QUrl> urls);
|
||||
void groupStateChanged(QString group, bool collapsed);
|
||||
|
||||
protected:
|
||||
bool isIndexHidden(const QModelIndex &index) const override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
protected:
|
||||
bool isIndexHidden(const QModelIndex& index) const override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent* event) override;
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dragMoveEvent(QDragMoveEvent* event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
void startDrag(Qt::DropActions supportedActions) override;
|
||||
|
||||
void updateScrollbar();
|
||||
|
||||
private:
|
||||
private:
|
||||
friend struct VisualGroup;
|
||||
QList<VisualGroup *> m_groups;
|
||||
QList<VisualGroup*> m_groups;
|
||||
|
||||
visibilityFunction fVisibility;
|
||||
|
||||
@ -135,7 +126,7 @@ private:
|
||||
int m_spacing = 5;
|
||||
int m_itemWidth = 100;
|
||||
int m_currentItemsPerRow = -1;
|
||||
int m_currentCursorColumn= -1;
|
||||
int m_currentCursorColumn = -1;
|
||||
mutable QCache<int, QRect> geometryCache;
|
||||
bool m_catVisible = false;
|
||||
QPixmap m_catPixmap;
|
||||
@ -144,30 +135,27 @@ private:
|
||||
QPoint m_pressedPosition;
|
||||
QPersistentModelIndex m_pressedIndex;
|
||||
bool m_pressedAlreadySelected;
|
||||
VisualGroup *m_pressedCategory;
|
||||
VisualGroup* m_pressedCategory;
|
||||
QItemSelectionModel::SelectionFlag m_ctrlDragSelectionFlag;
|
||||
QPoint m_lastDragPosition;
|
||||
|
||||
VisualGroup *category(const QModelIndex &index) const;
|
||||
VisualGroup *category(const QString &cat) const;
|
||||
VisualGroup *categoryAt(const QPoint &pos, VisualGroup::HitResults & result) const;
|
||||
VisualGroup* category(const QModelIndex& index) const;
|
||||
VisualGroup* category(const QString& cat) const;
|
||||
VisualGroup* categoryAt(const QPoint& pos, VisualGroup::HitResults& result) const;
|
||||
|
||||
int itemsPerRow() const
|
||||
{
|
||||
return m_currentItemsPerRow;
|
||||
};
|
||||
int itemsPerRow() const { return m_currentItemsPerRow; };
|
||||
int contentWidth() const;
|
||||
|
||||
private: /* methods */
|
||||
private: /* methods */
|
||||
int itemWidth() const;
|
||||
int calculateItemsPerRow() const;
|
||||
int verticalScrollToValue(const QModelIndex &index, const QRect &rect, QListView::ScrollHint hint) const;
|
||||
QPixmap renderToPixmap(const QModelIndexList &indices, QRect *r) const;
|
||||
QList<std::pair<QRect, QModelIndex>> draggablePaintPairs(const QModelIndexList &indices, QRect *r) const;
|
||||
int verticalScrollToValue(const QModelIndex& index, const QRect& rect, QListView::ScrollHint hint) const;
|
||||
QPixmap renderToPixmap(const QModelIndexList& indices, QRect* r) const;
|
||||
QList<std::pair<QRect, QModelIndex>> draggablePaintPairs(const QModelIndexList& indices, QRect* r) const;
|
||||
|
||||
bool isDragEventAccepted(QDropEvent *event);
|
||||
bool isDragEventAccepted(QDropEvent* event);
|
||||
|
||||
std::pair<VisualGroup *, VisualGroup::HitResults> rowDropPos(const QPoint &pos);
|
||||
std::pair<VisualGroup*, VisualGroup::HitResults> rowDropPos(const QPoint& pos);
|
||||
|
||||
QPoint offset() const;
|
||||
};
|
||||
|
Reference in New Issue
Block a user