swift
Loading...
Searching...
No Matches
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"
23#include "misc/variant.h"
24
25class QMimeData;
26class QModelIndex;
27
28namespace swift::misc
29{
30 class CWorker;
31}
32namespace swift::gui::models
33{
36 {
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,
91
94 virtual bool setSortColumnByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex);
95
97 virtual bool setSorting(const swift::misc::CPropertyIndex &propertyIndex,
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
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
183 int m_sortColumn { -1 };
184 bool m_modelDestroyed = false;
189
190 private:
193 std::chrono::milliseconds(500), 10 };
194 };
195
196} // namespace swift::gui::models
197#endif // SWIFT_GUI_MODELS_LISTMODELBASENONTEMPLATE_H
CDropBase()=default
Ctor.
Header data for a table.
Definition columns.h:160
void setDropActions(Qt::DropActions dropActions)
Drop actions.
bool endsWithEmptyColumn() const
Using void column at the end?
virtual Qt::SortOrder getSortOrder() const
Get sort order.
virtual bool hasHighlightedRows() const
Has highlighted rows?
Qt::ItemFlags flags(const QModelIndex &index) const final
void objectChanged(const swift::misc::CVariant &object, const swift::misc::CPropertyIndex &changedIndex)
Template free information, that object changed.
virtual void clearHighlighting()
Remove all highlighting.
virtual void onChangedDigest()=0
Digest signal.
static constexpr int asyncThreshold
Number of elements when to use asynchronous updates.
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.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const final
void modelDataChanged(int count, bool withFilter)
Data changed.
QModelIndex parent(const QModelIndex &child) const final
virtual swift::misc::CPropertyIndex columnToPropertyIndex(int column) const
Column to property index.
void markDestroyed()
Mark as about to be destroyed, normally marked from view.
CListModelBaseNonTemplate(const QString &translationContext, QObject *parent=nullptr)
Constructor.
swift::misc::CPropertyIndexList m_sortTieBreakers
how column values are sorted if equal, if no value is given this is random
QVariant headerData(int section, Qt::Orientation orientation, int role) const final
virtual void setSortColumn(int column)
Set sort column.
const CColumns & getColumns() const
The columns.
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.
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.
virtual swift::misc::CPropertyIndex modelIndexToPropertyIndex(const QModelIndex &index) const
Index to property index.
virtual int propertyIndexToColumn(const swift::misc::CPropertyIndex &propertyIndex) const
Property index to column number.
int columnCount(const QModelIndex &modelIndex=QModelIndex()) const final
Receive 1..n signals, collect them over time, and resend afer n milliseconds.
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:69
Class for doing some arbitrary parcel of work in its own thread.
Definition worker.h:230
Models to be used with views, mainly QTableView.
Free functions in swift::misc.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QStandardItemModel(QObject *parent)
typedef DropActions
SortOrder
#define SWIFT_GUI_EXPORT
Export a class or function from the library.