Isis 3 Programmer Reference
AbstractTableModel.h
1 #ifndef AbstractTableModel_H
2 #define AbstractTableModel_H
3 
4 
5 #include <QException>
6 #include <QExplicitlySharedDataPointer>
7 #include <QObject>
8 #include <QtConcurrent>
9 
10 // can't forward declare the InternalPointerType or InterestingItems enums
11 #include "AbstractTreeItem.h"
12 #include "AbstractTreeModel.h"
13 
14 
15 class QAtomicInt;
16 template< typename T > class QFutureWatcher;
17 class QTimer;
18 template< typename T > class QList;
19 
20 
21 namespace Isis {
22  class AbstractTableDelegate;
23  class AbstractTreeModel;
24  class BusyLeafItem;
25  class TableColumn;
26  class TableColumnList;
27 
40  class AbstractTableModel : public QObject {
41  class LessThanFunctor;
42 
43  Q_OBJECT
44 
45  public:
46  enum Warning {
47  None = 0,
48  SortingDisabled,
49  SortingTableSizeLimitReached
50  };
51 
53  virtual ~AbstractTableModel();
54 
55  virtual QList< AbstractTreeItem * > getItems(int, int) = 0;
57  AbstractTreeItem *) = 0;
58  virtual QList< AbstractTreeItem * > getSelectedItems() = 0;
59  virtual int getVisibleRowCount() const = 0;
60  virtual QString getWarningMessage(AbstractTreeItem const *,
61  TableColumn const *, QString valueToSave) const = 0;
62  virtual int indexOfVisibleItem(AbstractTreeItem const *item) const = 0;
63 
64  virtual bool isSorting() const;
65  virtual bool isFiltering() const;
66  virtual bool sortingIsEnabled() const;
67  virtual void setSortingEnabled(bool);
68  virtual int sortLimit() const;
69  virtual void setSortLimit(int);
70  virtual bool sortingOn() const;
71  virtual TableColumnList *getColumns();
72  virtual const AbstractTableDelegate *getDelegate() const;
73 
74 
75  public slots:
76  virtual void setGlobalSelection(bool selected) = 0;
77  virtual void applyFilter();
78  virtual void sort();
79  virtual void reverseOrder(TableColumn *);
80  virtual void updateSort();
81  virtual void rebuildSort();
82 
83 
84  signals:
85  void modelModified();
86  void filterProgressChanged(int);
87  void rebuildProgressChanged(int);
88  void sortProgressChanged(int);
89  void filterProgressRangeChanged(int, int);
90  void rebuildProgressRangeChanged(int, int);
91  void sortProgressRangeChanged(int, int);
92  void filterCountsChanged(int visibleRows, int totalRows);
93  void treeSelectionChanged(QList<AbstractTreeItem *>);
94  void tableSelectionChanged(QList<AbstractTreeItem *>);
95 
96  void userWarning(AbstractTableModel::Warning);
97 
98  protected:
99  virtual TableColumnList *createColumns() = 0;
100  AbstractTreeModel *getDataModel();
101  const AbstractTreeModel *getDataModel() const;
102  virtual QList< AbstractTreeItem * > getSortedItems(int, int,
103  AbstractTreeModel::InterestingItems);
104  virtual QList< AbstractTreeItem * > getSortedItems(
106  AbstractTreeModel::InterestingItems);
107  void handleTreeSelectionChanged(
108  QList< AbstractTreeItem * > newlySelectedItems,
109  AbstractTreeItem::InternalPointerType);
110 
111 
112  private: // disable copying of this class (these are not implemented)
114  AbstractTableModel &operator=(AbstractTableModel const &);
115 
116 
117  private slots:
118  void cancelSort();
119  void itemsLost();
120  void sortStatusUpdated();
121  void sortFinished();
122 
123 
124  private:
126  void nullify();
127  void setSorting(bool sorting);
128 
129 
130  private:
131  AbstractTreeModel *m_dataModel;
132  AbstractTableDelegate *m_delegate;
133  QList< AbstractTreeItem * > * m_sortedItems;
134  BusyLeafItem *m_busyItem;
135  TableColumnList *m_columns;
136  QTimer *m_sortStatusPoller;
137  LessThanFunctor *m_lessThanFunctor;
138 
139  bool m_sortingEnabled;
140  int m_sortLimit;
141  bool m_sorting;
142  QFutureWatcher< QList< AbstractTreeItem * > > * m_sortingWatcher;
143 
144  static const int SORT_UPDATE_FREQUENCY = 50; // in milliseconds
145 
146 
147  private:
148  class LessThanFunctorData;
149 
155  class LessThanFunctor : public std::binary_function <
156  AbstractTreeItem *const &, AbstractTreeItem *const &, bool > {
157  public:
158  LessThanFunctor(TableColumn const *someColumn);
160  ~LessThanFunctor();
161 
162  int getCompareCount() const;
163  void interrupt();
164  bool interrupted();
165  void reset();
166 
167  bool operator()(AbstractTreeItem *const &,
168  AbstractTreeItem *const &);
169  LessThanFunctor &operator=(LessThanFunctor const &);
170 
171 
172  private:
173  TableColumn const *m_column;
174  QExplicitlySharedDataPointer<LessThanFunctorData> m_sharedData;
175  };
176 
187  public:
191 
192  int getCompareCount() const;
193  void incrementCompareCount();
194 
195  void setInterrupted(bool);
196  bool interrupted();
197 
198 
199  private:
200  QAtomicInt m_compareCount;
201  QAtomicInt m_interruptFlag;
202  };
203 
204 
217  public:
218  void raise() const { throw *this; }
219  QException *clone() const {
220  return new SortingCanceledException(*this);
221  }
222  };
223  };
224 }
225 
226 #endif
Base class for tree models.
Thread-safe exception for cancelling sorting.
For explicit sharing of the comparison counter between multiple copies of a LessThanFunctor object...
Translates the tree model into a table model.
A leaf item that is not ready for user interaction.
Definition: BusyLeafItem.h:25
Base class for delegates which create, read, and save data in the tables.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Base class for an item in the tree.