]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiSelectionManager.h
Show suggestions containing the input in the command buffer
[features.git] / src / frontends / qt / GuiSelectionManager.h
1 /**
2  * \file GuiSelectionManager.h
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Richard Kimberly Heck
7  * \author Et Alia
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GUISELECTIONMANAGER_H
13 #define GUISELECTIONMANAGER_H
14
15 #include <QObject>
16
17 class QAbstractItemModel;
18 class QModelIndex;
19 class QPushButton;
20 class QVariant;
21 class QAbstractItemView;
22 class QItemSelection;
23 template <class T, class U> class QMap;
24
25 namespace lyx {
26 namespace frontend {
27
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
34  *  constructor.
35  */
36 class GuiSelectionManager : public QObject
37 {
38         Q_OBJECT
39
40 public:
41         ///
42         GuiSelectionManager(QObject * parent,
43                                                 QAbstractItemView * availableLV,
44                                                 QAbstractItemView * selectedLV,
45                                                 QPushButton * addPB,
46                                                 QPushButton * delPB,
47                                                 QPushButton * upPB,
48                                                 QPushButton * downPB,
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.
57         void update();
58
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;
68         ///
69         void allowMultiSelection(bool b) { allow_multi_selection_ = b; }
70
71 Q_SIGNALS:
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().
81         void updateHook();
82         /// Emitted on Ctrl-Enter in the availableLV. Intended to be connected
83         /// to an "OK" event in the parent dialog.
84         void okHook();
85
86
87 protected:
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);
91         ///
92         bool insertRowToSelected(int i, QMap<int, QVariant> const & itemData);
93         ///
94         bool insertRowToSelected(int i, QMap<int, QMap<int, QVariant>> &);
95         ///
96         QAbstractItemView * availableLV;
97         ///
98         QAbstractItemView * selectedLV;
99         ///
100         QPushButton * addPB;
101         ///
102         QPushButton * deletePB;
103         ///
104         QPushButton * upPB;
105         ///
106         QPushButton * downPB;
107         ///
108         QAbstractItemModel * availableModel;
109         ///
110         QAbstractItemModel * selectedModel;
111
112 protected Q_SLOTS:
113         ///
114         void availableChanged(QModelIndex const & idx, QModelIndex const &);
115         ///
116         void selectedChanged(QModelIndex const & idx, QModelIndex const &);
117         ///
118         void availableChanged(QItemSelection const & qis, QItemSelection const &);
119         ///
120         void selectedChanged(QItemSelection const & qis, QItemSelection const &);
121         ///
122         void selectedEdited();
123         ///
124         virtual void addPB_clicked();
125         ///
126         virtual void deletePB_clicked();
127         ///
128         virtual void upPB_clicked();
129         ///
130         virtual void downPB_clicked();
131         ///
132         void availableLV_doubleClicked(const QModelIndex &);
133         ///
134         bool eventFilter(QObject *, QEvent *) override;
135         ///
136         void updateButtons();
137
138 private:
139         ///
140         virtual void updateAddPB();
141         ///
142         virtual void updateDelPB();
143         ///
144         virtual void updateDownPB();
145         ///
146         virtual void updateUpPB();
147         ///
148         bool selectedHasFocus_;
149         ///
150         int main_sel_col_;
151         ///
152         bool allow_multi_selection_;
153 };
154
155 } // namespace frontend
156 } // namespace lyx
157
158 #endif  // GUISELECTIONMANAGER