Quark  0.1
AbstractItemModelMenuAdapter.h++
Go to the documentation of this file.
1 #ifndef __libquark_gui_AbstractItemModelMenuAdapter_hxx
2 #define __libquark_gui_AbstractItemModelMenuAdapter_hxx
3 
4 class QAbstractItemModel;
5 class QAction;
6 class QMenu;
7 class QModelIndex;
8 
9 #include <QFlags>
10 #include <QList>
11 #include <QObject>
12 #include <QActionGroup>
13 
14 #include <quark/Quark.h++>
15 
16 namespace quark {
17 namespace gui {
18 
27 {
28  Q_OBJECT;
29 
30  public:
31 
33  enum Option
34  {
40  InsertAtTop = 1 << 0,
45  Checkable = 1 << 1,
51  Exclusive = 1 << 2
52  };
53 
54  Q_DECLARE_FLAGS(Options, Option);
55 
57  AbstractItemModelMenuAdapter(const QAbstractItemModel *model, QMenu *menu,
58  Options options = 0);
59 
62 
67  void sync();
68 
69  protected:
70 
72  virtual QString getMenuLabelForRow(int row) const = 0;
73  virtual void handleRowSelection(int row) = 0;
74  void setSelectedRow(int row);
77  private slots:
78 
79  void removeItems(const QModelIndex &parent, int start, int end);
80  void insertItems(const QModelIndex &parent, int start, int end);
81  void moveItems(const QModelIndex &sourceParent, int sourceStart,
82  int sourceEnd, const QModelIndex &destParent, int destRow);
83  void updateItems(const QModelIndex &topLeft, const QModelIndex &bottomRight);
84  void actionTriggered();
85 
86  private:
87 
88  const QAbstractItemModel *_model;
89  QMenu *_menu;
90  QList<QAction *> _actions;
91  QActionGroup *_actionGroup;
92  Options _options;
93  int _fixedActions;
94  int _menuOffset;
95  QAction *_lastAction;
96 };
97 
98 } // namespace gui
99 } // namespace quark
100 
102  quark::gui::AbstractItemModelMenuAdapter::Options);
103 
104 #endif // __libquark_gui_AbstractItemModelMenuAdapter_hxx
A non-parameterized abstract base class for Quark item model menu adapters.
Definition: AbstractItemModelMenuAdapter.h++:26
Option
Item model menu adapter options.
Definition: AbstractItemModelMenuAdapter.h++:33
Definition: BarChartView.h++:6
Q_DECLARE_OPERATORS_FOR_FLAGS(quark::gui::AbstractItemModelMenuAdapter::Options)
#define LIBQUARK_API
Definition: Quark.h++:18