Isis Developer Reference
AbstractTableModel.h
Go to the documentation of this file.
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:
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:
100 void filterCountsChanged(int visibleRows, int totalRows);
101 void treeSelectionChanged(QList<AbstractTreeItem *>);
102 void tableSelectionChanged(QList<AbstractTreeItem *>);
103
105
106 protected:
109 const AbstractTreeModel *getDataModel() const;
110 virtual QList< AbstractTreeItem * > getSortedItems(int, int,
112 virtual QList< AbstractTreeItem * > getSortedItems(
116 QList< AbstractTreeItem * > newlySelectedItems,
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:
156 class LessThanFunctorData;
157
163 class LessThanFunctor : public std::function <bool(AbstractTreeItem *const &, AbstractTreeItem *const &)> {
164 public:
165 LessThanFunctor(TableColumn const *someColumn);
166 LessThanFunctor(LessThanFunctor const &);
167 ~LessThanFunctor();
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
193 class LessThanFunctorData : public QSharedData {
194 public:
195 LessThanFunctorData();
196 LessThanFunctorData(LessThanFunctorData const &);
197 ~LessThanFunctorData();
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
223 class SortingCanceledException : public QException {
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.
Definition AbstractTableDelegate.h:33
Translates the tree model into a table model.
Definition AbstractTableModel.h:48
void filterProgressRangeChanged(int, int)
virtual const AbstractTableDelegate * getDelegate() const
Definition AbstractTableModel.cpp:162
virtual void updateSort()
Definition AbstractTableModel.cpp:201
virtual int getVisibleRowCount() const =0
void rebuildProgressRangeChanged(int, int)
virtual bool isFiltering() const
Definition AbstractTableModel.cpp:116
virtual bool sortingOn() const
Definition AbstractTableModel.cpp:147
virtual QList< AbstractTreeItem * > getSelectedItems()=0
virtual QList< AbstractTreeItem * > getItems(AbstractTreeItem *, AbstractTreeItem *)=0
virtual void rebuildSort()
Definition AbstractTableModel.cpp:419
virtual QString getWarningMessage(AbstractTreeItem const *, TableColumn const *, QString valueToSave) const =0
virtual void applyFilter()
Definition AbstractTableModel.cpp:167
AbstractTreeModel * getDataModel()
Definition AbstractTableModel.cpp:205
virtual void setSortLimit(int)
Definition AbstractTableModel.cpp:139
void userWarning(AbstractTableModel::Warning)
virtual void setGlobalSelection(bool selected)=0
Warning
Definition AbstractTableModel.h:54
@ None
Definition AbstractTableModel.h:55
@ SortingDisabled
Definition AbstractTableModel.h:56
@ SortingTableSizeLimitReached
Definition AbstractTableModel.h:57
virtual ~AbstractTableModel()
Definition AbstractTableModel.cpp:78
virtual void sort()
Definition AbstractTableModel.cpp:172
virtual void reverseOrder(TableColumn *)
Definition AbstractTableModel.cpp:197
virtual TableColumnList * createColumns()=0
virtual QList< AbstractTreeItem * > getSortedItems(int, int, AbstractTreeModel::InterestingItems)
Definition AbstractTableModel.cpp:215
virtual void setSortingEnabled(bool)
Definition AbstractTableModel.cpp:126
virtual QList< AbstractTreeItem * > getItems(int, int)=0
virtual TableColumnList * getColumns()
Definition AbstractTableModel.cpp:152
virtual int indexOfVisibleItem(AbstractTreeItem const *item) const =0
void sortProgressRangeChanged(int, int)
void treeSelectionChanged(QList< AbstractTreeItem * >)
void tableSelectionChanged(QList< AbstractTreeItem * >)
void handleTreeSelectionChanged(QList< AbstractTreeItem * > newlySelectedItems, AbstractTreeItem::InternalPointerType)
Definition AbstractTableModel.cpp:299
virtual bool isSorting() const
Definition AbstractTableModel.cpp:111
virtual int sortLimit() const
Definition AbstractTableModel.cpp:134
AbstractTableModel(AbstractTreeModel *, AbstractTableDelegate *)
Definition AbstractTableModel.cpp:33
virtual bool sortingIsEnabled() const
Definition AbstractTableModel.cpp:121
void filterCountsChanged(int visibleRows, int totalRows)
void rebuildProgressChanged(int)
Base class for an item in the tree.
Definition AbstractTreeItem.h:39
InternalPointerType
Definition AbstractTreeItem.h:44
Base class for tree models.
Definition AbstractTreeModel.h:48
InterestingItems
Definition AbstractTreeModel.h:52
A leaf item that is not ready for user interaction.
Definition BusyLeafItem.h:33
Definition TableColumn.h:26
Definition TableColumnList.h:30
This is free and unencumbered software released into the public domain.
Definition AbstractTableModel.h:24
This is free and unencumbered software released into the public domain.
Definition BoxcarCachingAlgorithm.h:13
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16