2 * \file GuiSelectionManager.h
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Richard Kimberly Heck
9 * Full author contact details are available in file CREDITS.
12 #ifndef GUISELECTIONMANAGER_H
13 #define GUISELECTIONMANAGER_H
17 class QAbstractItemModel;
21 class QAbstractItemView;
23 template <class T, class U> class QMap;
28 /** Class to manage a collection of widgets that allows selection
29 * of items from a list of available items. Adapted from code originally
30 * written for GuiCitationDialog.
31 * Note that this is a not a QWidget, though it could be converted to
32 * one. Rather, the managed widgets---see constructor for description
33 * of them---should be created independently, and then passed to the
36 class GuiSelectionManager : public QObject
42 GuiSelectionManager(QObject * parent,
43 QAbstractItemView * availableLV,
44 QAbstractItemView * selectedLV,
49 QAbstractItemModel * availableModel,
50 QAbstractItemModel * selectedModel,
51 int const main_sel_col = 0);
52 /// Sets the state of the various push buttons, depending upon the
53 /// state of the widgets. (E.g., "delete" is enabled only if the
54 /// selection is non-empty.)
55 /// Note: this is separated out into updateAddPB(), etc, below,
56 /// for easy over-riding of these functions.
59 /// Not strictly a matter of focus, which may be elsewhere, but
60 /// whether selectedLV is `more focused' than availableLV. Intended
61 /// to be used, for example, in displaying information about a
62 /// highlighted item: should it be the highlighted available item
63 /// or the highlighted selected item that is displayed?
64 bool selectedFocused() const { return selectedHasFocus_; }
65 /// Returns the selected index. Note that this will depend upon
66 /// selectedFocused().
67 QModelIndex getSelectedIndex(int const c = 0) const;
69 void allowMultiSelection(bool b) { allow_multi_selection_ = b; }
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 QAbstractItemModel * 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 *) override;
136 void updateButtons();
140 virtual void updateAddPB();
142 virtual void updateDelPB();
144 virtual void updateDownPB();
146 virtual void updateUpPB();
148 bool selectedHasFocus_;
152 bool allow_multi_selection_;
155 } // namespace frontend
158 #endif // GUISELECTIONMANAGER