Isis 3 Programmer Reference
AbstractTableModel.h
1#ifndef AbstractTableModel_H
2#define AbstractTableModel_H
3
10/* SPDX-License-Identifier: CC0-1.0 */
11
12
13#include <QException>
14#include <QExplicitlySharedDataPointer>
15#include <QObject>
16#include <QtConcurrent>
17
18// can't forward declare the InternalPointerType or InterestingItems enums
19#include "AbstractTreeItem.h"
20#include "AbstractTreeModel.h"
21
22
23class QAtomicInt;
24template< typename T > class QFutureWatcher;
25class QTimer;
26template< typename T > class QList;
27
28
29namespace Isis {
30 class AbstractTableDelegate;
31 class AbstractTreeModel;
32 class BusyLeafItem;
33 class TableColumn;
34 class TableColumnList;
35
48 class AbstractTableModel : public QObject {
49 class LessThanFunctor;
50
51 Q_OBJECT
52
53 public:
54 enum Warning {
55 None = 0,
56 SortingDisabled,
57 SortingTableSizeLimitReached
58 };
59
61 virtual ~AbstractTableModel();
62
63 virtual QList< AbstractTreeItem * > getItems(int, int) = 0;
64 virtual QList< AbstractTreeItem * > getItems(AbstractTreeItem *,
65 AbstractTreeItem *) = 0;
66 virtual QList< AbstractTreeItem * > getSelectedItems() = 0;
67 virtual int getVisibleRowCount() const = 0;
68 virtual QString getWarningMessage(AbstractTreeItem const *,
69 TableColumn const *, QString valueToSave) const = 0;
70 virtual int indexOfVisibleItem(AbstractTreeItem const *item) const = 0;
71
72 virtual bool isSorting() const;
73 virtual bool isFiltering() const;
74 virtual bool sortingIsEnabled() const;
75 virtual void setSortingEnabled(bool);
76 virtual int sortLimit() const;
77 virtual void setSortLimit(int);
78 virtual bool sortingOn() const;
79 virtual TableColumnList *getColumns();
80 virtual const AbstractTableDelegate *getDelegate() const;
81
82
83 public slots:
84 virtual void setGlobalSelection(bool selected) = 0;
85 virtual void applyFilter();
86 virtual void sort();
87 virtual void reverseOrder(TableColumn *);
88 virtual void updateSort();
89 virtual void rebuildSort();
90
91
92 signals:
93 void modelModified();
94 void filterProgressChanged(int);
95 void rebuildProgressChanged(int);
96 void sortProgressChanged(int);
97 void filterProgressRangeChanged(int, int);
98 void rebuildProgressRangeChanged(int, int);
99 void sortProgressRangeChanged(int, int);
100 void filterCountsChanged(int visibleRows, int totalRows);
101 void treeSelectionChanged(QList<AbstractTreeItem *>);
102 void tableSelectionChanged(QList<AbstractTreeItem *>);
103
104 void userWarning(AbstractTableModel::Warning);
105
106 protected:
107 virtual TableColumnList *createColumns() = 0;
108 AbstractTreeModel *getDataModel();
109 const AbstractTreeModel *getDataModel() const;
110 virtual QList< AbstractTreeItem * > getSortedItems(int, int,
111 AbstractTreeModel::InterestingItems);
112 virtual QList< AbstractTreeItem * > getSortedItems(
114 AbstractTreeModel::InterestingItems);
115 void handleTreeSelectionChanged(
116 QList< AbstractTreeItem * > newlySelectedItems,
117 AbstractTreeItem::InternalPointerType);
118
119
120 private: // disable copying of this class (these are not implemented)
122 AbstractTableModel &operator=(AbstractTableModel const &);
123
124
125 private slots:
126 void cancelSort();
127 void itemsLost();
128 void sortStatusUpdated();
129 void sortFinished();
130
131
132 private:
133 QList< AbstractTreeItem * > doSort(QList< AbstractTreeItem * >);
134 void nullify();
135 void setSorting(bool sorting);
136
137
138 private:
139 AbstractTreeModel *m_dataModel;
140 AbstractTableDelegate *m_delegate;
141 QList< AbstractTreeItem * > * m_sortedItems;
142 BusyLeafItem *m_busyItem;
143 TableColumnList *m_columns;
144 QTimer *m_sortStatusPoller;
145 LessThanFunctor *m_lessThanFunctor;
146
147 bool m_sortingEnabled;
148 int m_sortLimit;
149 bool m_sorting;
150 QFutureWatcher< QList< AbstractTreeItem * > > * m_sortingWatcher;
151
152 static const int SORT_UPDATE_FREQUENCY = 50; // in milliseconds
153
154
155 private:
157
163 class LessThanFunctor : public std::function <bool(AbstractTreeItem *const &, AbstractTreeItem *const &)> {
164 public:
165 LessThanFunctor(TableColumn const *someColumn);
168
169 int getCompareCount() const;
170 void interrupt();
171 bool interrupted();
172 void reset();
173
174 bool operator()(AbstractTreeItem *const &,
175 AbstractTreeItem *const &);
176 LessThanFunctor &operator=(LessThanFunctor const &);
177
178
179 private:
180 TableColumn const *m_column;
181 QExplicitlySharedDataPointer<LessThanFunctorData> m_sharedData;
182 };
183
194 public:
198
199 int getCompareCount() const;
200 void incrementCompareCount();
201
202 void setInterrupted(bool);
203 bool interrupted();
204
205
206 private:
207 QAtomicInt m_compareCount;
208 QAtomicInt m_interruptFlag;
209 };
210
211
224 public:
225 void raise() const { throw *this; }
226 QException *clone() const {
227 return new SortingCanceledException(*this);
228 }
229 };
230 };
231}
232
233#endif
Base class for delegates which create, read, and save data in the tables.
For explicit sharing of the comparison counter between multiple copies of a LessThanFunctor object.
Thread-safe exception for cancelling sorting.
Translates the tree model into a table model.
Base class for an item in the tree.
Base class for tree models.
A leaf item that is not ready for user interaction.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16