swift
listmodelbasenontemplate.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_GUI_MODELS_LISTMODELBASENONTEMPLATE_H
7 #define SWIFT_GUI_MODELS_LISTMODELBASENONTEMPLATE_H
8 
9 #include <QJsonDocument>
10 #include <QJsonObject>
11 #include <QModelIndex>
12 #include <QStandardItemModel>
13 #include <QString>
14 #include <QStringList>
15 #include <QVariant>
16 #include <QVector>
17 
18 #include "gui/dropbase.h"
19 #include "gui/models/columns.h"
20 #include "gui/swiftguiexport.h"
21 #include "misc/digestsignal.h"
22 #include "misc/propertyindexlist.h"
23 #include "misc/variant.h"
24 
25 class QMimeData;
26 class QModelIndex;
27 
28 namespace swift::misc
29 {
30  class CWorker;
31 }
32 namespace swift::gui::models
33 {
35  class SWIFT_GUI_EXPORT CListModelBaseNonTemplate : public QStandardItemModel, public CDropBase
36  {
37  Q_OBJECT
38 
39  public:
41  static constexpr int asyncThreshold = 50;
42 
44  ~CListModelBaseNonTemplate() override = default;
45 
49  int columnCount(const QModelIndex &modelIndex = QModelIndex()) const final;
50 
52  QVariant headerData(int section, Qt::Orientation orientation, int role) const final;
53 
55  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const final;
56 
58  QModelIndex parent(const QModelIndex &child) const final;
59 
61  Qt::ItemFlags flags(const QModelIndex &index) const final;
62 
64  Qt::DropActions supportedDragActions() const final;
65 
67  Qt::DropActions supportedDropActions() const final;
68 
70  QStringList mimeTypes() const final;
72 
74  virtual swift::misc::CPropertyIndex columnToPropertyIndex(int column) const;
75 
77  virtual int propertyIndexToColumn(const swift::misc::CPropertyIndex &propertyIndex) const;
78 
80  virtual swift::misc::CPropertyIndex modelIndexToPropertyIndex(const QModelIndex &index) const;
81 
83  virtual void setSortColumn(int column) { m_sortColumn = column; }
84 
86  void setNoSorting() { this->setSortColumn(-1); }
87 
89  void sortByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex,
90  Qt::SortOrder order = Qt::AscendingOrder);
91 
94  virtual bool setSortColumnByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex);
95 
97  virtual bool setSorting(const swift::misc::CPropertyIndex &propertyIndex,
98  Qt::SortOrder order = Qt::AscendingOrder);
99 
101  virtual int getSortColumn() const { return m_sortColumn; }
102 
104  swift::misc::CPropertyIndex getSortProperty() const;
105 
107  virtual bool hasValidSortColumn() const;
108 
110  virtual Qt::SortOrder getSortOrder() const { return m_sortOrder; }
111 
113  virtual bool isOrderable() const = 0;
114 
116  void markDestroyed();
117 
119  bool isModelDestroyed();
120 
122  virtual void clearHighlighting();
123 
125  virtual bool hasHighlightedRows() const;
126 
128  void setDropActions(Qt::DropActions dropActions) { m_dropActions = dropActions; }
129 
132  void emitDataChanged(int startRowIndex, int endRowIndex);
133 
135  virtual QJsonObject toJson(bool selectedOnly = false) const = 0;
136 
138  virtual QString toJsonString(QJsonDocument::JsonFormat format = QJsonDocument::Indented,
139  bool selectedOnly = false) const = 0;
140 
142  const CColumns &getColumns() const { return m_columns; }
143 
145  bool endsWithEmptyColumn() const { return m_columns.endsWithEmptyColumn(); }
146 
147  signals:
150 
154  void modelDataChanged(int count, bool withFilter);
155 
157  void modelDataChangedDigest(int count, bool withFilter);
158 
161  void changed();
162 
165 
167  void objectChanged(const swift::misc::CVariant &object, const swift::misc::CPropertyIndex &changedIndex);
168 
169  protected:
171  virtual void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
172  const QVector<int> &roles) = 0;
173 
175  virtual void onChangedDigest() = 0;
176 
180  CListModelBaseNonTemplate(const QString &translationContext, QObject *parent = nullptr);
181 
184  bool m_modelDestroyed = false;
185  Qt::SortOrder m_sortOrder;
186  Qt::DropActions m_dropActions = Qt::IgnoreAction;
189 
190  private:
193  std::chrono::milliseconds(500), 10 };
194  };
195 
196 } // namespace swift::gui::models
197 #endif // SWIFT_GUI_MODELS_LISTMODELBASENONTEMPLATE_H
Utilities for dropping swift value objects.
Definition: dropbase.h:19
Header data for a table.
Definition: columns.h:160
Non templated base class, allows Q_OBJECT and signals to be used.
void setDropActions(Qt::DropActions dropActions)
Drop actions.
bool endsWithEmptyColumn() const
Using void column at the end?
virtual Qt::SortOrder getSortOrder() const
Get sort order.
void objectChanged(const swift::misc::CVariant &object, const swift::misc::CPropertyIndex &changedIndex)
Template free information, that object changed.
virtual void onChangedDigest()=0
Digest signal.
virtual void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)=0
Feedback when QStandardItemModel::dataChanged was called.
void modelDataChangedDigest(int count, bool withFilter)
Data changed, digest version.
void changed()
Model has been changed Triggered with each change, for performance consider using changedDigest.
void modelDataChanged(int count, bool withFilter)
Data changed.
swift::misc::CPropertyIndexList m_sortTieBreakers
how column values are sorted if equal, if no value is given this is random
void asyncUpdateFinished()
Asynchronous update finished.
void changedDigest()
Model has been changed, digest signal.
virtual QString toJsonString(QJsonDocument::JsonFormat format=QJsonDocument::Indented, bool selectedOnly=false) const =0
Convert to JSON string.
const CColumns & getColumns() const
The columns.
virtual QJsonObject toJson(bool selectedOnly=false) const =0
Convert to JSON.
virtual int getSortColumn() const
Get sort column property index.
virtual bool isOrderable() const =0
Orderable, normally use a container swift::misc::IOrderableList.
Receive 1..n signals, collect them over time, and resend afer n milliseconds.
Definition: digestsignal.h:18
Value object encapsulating a list of property indexes.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
Models to be used with views, mainly QTableView.
Free functions in swift::misc.
#define SWIFT_GUI_EXPORT
Export a class or function from the library.