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 
23 class QAtomicInt;
24 template< typename T > class QFutureWatcher;
25 class QTimer;
26 template< typename T > class QList;
27 
28 
29 namespace 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;
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:
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::binary_function <
164  AbstractTreeItem *const &, AbstractTreeItem *const &, bool > {
165  public:
166  LessThanFunctor(TableColumn const *someColumn);
168  ~LessThanFunctor();
169 
170  int getCompareCount() const;
171  void interrupt();
172  bool interrupted();
173  void reset();
174 
175  bool operator()(AbstractTreeItem *const &,
176  AbstractTreeItem *const &);
177  LessThanFunctor &operator=(LessThanFunctor const &);
178 
179 
180  private:
181  TableColumn const *m_column;
182  QExplicitlySharedDataPointer<LessThanFunctorData> m_sharedData;
183  };
184 
195  public:
199 
200  int getCompareCount() const;
201  void incrementCompareCount();
202 
203  void setInterrupted(bool);
204  bool interrupted();
205 
206 
207  private:
208  QAtomicInt m_compareCount;
209  QAtomicInt m_interruptFlag;
210  };
211 
212 
225  public:
226  void raise() const { throw *this; }
227  QException *clone() const {
228  return new SortingCanceledException(*this);
229  }
230  };
231  };
232 }
233 
234 #endif
Isis::AbstractTableModel::LessThanFunctorData
For explicit sharing of the comparison counter between multiple copies of a LessThanFunctor object.
Definition: AbstractTableModel.h:194
QSharedData
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::AbstractTreeModel
Base class for tree models.
Definition: AbstractTreeModel.h:47
Isis::BusyLeafItem
A leaf item that is not ready for user interaction.
Definition: BusyLeafItem.h:33
Isis::AbstractTableModel::LessThanFunctor
Definition: AbstractTableModel.h:164
Isis::TableColumn
Definition: TableColumn.h:26
Isis::AbstractTableModel
Translates the tree model into a table model.
Definition: AbstractTableModel.h:48
Isis::AbstractTableModel::SortingCanceledException
Thread-safe exception for cancelling sorting.
Definition: AbstractTableModel.h:224
QException
Isis::TableColumnList
Definition: TableColumnList.h:30
QFutureWatcher
This is free and unencumbered software released into the public domain.
Definition: AbstractTableModel.h:24
Isis::AbstractTableDelegate
Base class for delegates which create, read, and save data in the tables.
Definition: AbstractTableDelegate.h:33
QObject
Isis::AbstractTreeItem
Base class for an item in the tree.
Definition: AbstractTreeItem.h:39
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16