2 * \file GuiSelectionManager.h
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef GUISELECTIONMANAGER_H
13 #define GUISELECTIONMANAGER_H
17 class QAbstractItemModel;
18 class QAbstractListModel;
23 class QAbstractItemView;
25 template <class T, class U> class QMap;
30 /** Class to manage a collection of widgets that allows selection
31 * of items from a list of available items. Adapted from code originally
32 * written for GuiCitationDialog.
33 * Note that this is a not a QWidget, though it could be converted to
34 * one. Rather, the managed widgets---see constructor for descripton
35 * of them---should be created independently, and then passed to the
38 class GuiSelectionManager : public QObject
44 GuiSelectionManager(QObject * parent,
45 QAbstractItemView * availableLV,
46 QAbstractItemView * selectedLV,
51 QAbstractListModel * availableModel,
52 QAbstractItemModel * selectedModel,
53 int const main_sel_col = 0);
54 /// Sets the state of the various push buttons, depending upon the
55 /// state of the widgets. (E.g., "delete" is enabled only if the
56 /// selection is non-empty.)
57 /// Note: this is separated out into updateAddPB(), etc, below,
58 /// for easy over-riding of these functions.
61 /// Not strictly a matter of focus, which may be elsewhere, but
62 /// whether selectedLV is `more focused' than availableLV. Intended
63 /// to be used, for example, in displaying information about a
64 /// highlighted item: should it be the highlighted available item
65 /// or the highlighted selected item that is displayed?
66 bool selectedFocused() const { return selectedHasFocus_; }
67 /// Returns the selected index. Note that this will depend upon
68 /// selectedFocused().
69 QModelIndex getSelectedIndex(int const c = 0) const;
72 /// Emitted when the list of selected items has changed.
73 void selectionChanged();
74 /// Emitted when something has changed that might lead the containing
75 /// dialog to want to update---the focused subwidget or selected item.
76 /// (Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.)
77 /// NOTE: No automatic update of the button state is done here. If you
78 /// just want to do that, connect updateHook() to updateView(). Much of the
79 /// time, though, you will want to do a bit more processing first, so
80 /// you can connect to some other function that itself calls updateView().
82 /// Emitted on Ctrl-Enter in the availableLV. Intended to be connected
83 /// to an "OK" event in the parent dialog.
88 /// Given a QModelIndex from availableLV, determines whether it has
89 /// been selected (i.e., is also in selectedLV).
90 bool isSelected(const QModelIndex & idx);
92 bool insertRowToSelected(int i, QMap<int, QVariant> const & itemData);
94 bool insertRowToSelected(int i, QMap<int, QMap<int, QVariant>> &);
96 QAbstractItemView * availableLV;
98 QAbstractItemView * selectedLV;
102 QPushButton * deletePB;
106 QPushButton * downPB;
108 QAbstractListModel * availableModel;
110 QAbstractItemModel * selectedModel;
114 void availableChanged(QModelIndex const & idx, QModelIndex const &);
116 void selectedChanged(QModelIndex const & idx, QModelIndex const &);
118 void availableChanged(QItemSelection const & qis, QItemSelection const &);
120 void selectedChanged(QItemSelection const & qis, QItemSelection const &);
122 void selectedEdited();
124 virtual void addPB_clicked();
126 virtual void deletePB_clicked();
128 virtual void upPB_clicked();
130 virtual void downPB_clicked();
132 void availableLV_doubleClicked(const QModelIndex &);
134 bool eventFilter(QObject *, QEvent *);
138 virtual void updateAddPB();
140 virtual void updateDelPB();
142 virtual void updateDownPB();
144 virtual void updateUpPB();
146 bool selectedHasFocus_;
151 } // namespace frontend
154 #endif // GUISELECTIONMANAGER