]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiSelectionManager.h
Run codespell on src/frontends
[lyx.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 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 QAbstractListModel;
19 class QModelIndex;
20 class QListView;
21 class QPushButton;
22 class QVariant;
23 class QAbstractItemView;
24 class QItemSelection;
25 template <class T, class U> class QMap;
26
27 namespace lyx {
28 namespace frontend {
29
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 description
35  *  of them---should be created independently, and then passed to the
36  *  constructor.
37  */
38 class GuiSelectionManager : public QObject
39 {
40         Q_OBJECT
41
42 public:
43         ///
44         GuiSelectionManager(QObject * parent,
45                                                 QAbstractItemView * availableLV,
46                                                 QAbstractItemView * selectedLV,
47                                                 QPushButton * addPB,
48                                                 QPushButton * delPB,
49                                                 QPushButton * upPB,
50                                                 QPushButton * downPB,
51                                                 QAbstractItemModel * 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.
59         void update();
60
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;
70         ///
71         void allowMultiSelection(bool b) { allow_multi_selection_ = b; }
72
73 Q_SIGNALS:
74         /// Emitted when the list of selected items has changed.
75         void selectionChanged();
76         /// Emitted when something has changed that might lead the containing
77         /// dialog to want to update---the focused subwidget or selected item.
78         /// (Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.)
79         /// NOTE: No automatic update of the button state is done here. If you
80         /// just want to do that, connect updateHook() to updateView(). Much of the
81         /// time, though, you will want to do a bit more processing first, so
82         /// you can connect to some other function that itself calls updateView().
83         void updateHook();
84         /// Emitted on Ctrl-Enter in the availableLV. Intended to be connected
85         /// to an "OK" event in the parent dialog.
86         void okHook();
87
88
89 protected:
90         /// Given a QModelIndex from availableLV, determines whether it has
91         /// been selected (i.e., is also in selectedLV).
92         bool isSelected(const QModelIndex & idx);
93         ///
94         bool insertRowToSelected(int i, QMap<int, QVariant> const & itemData);
95         ///
96         bool insertRowToSelected(int i, QMap<int, QMap<int, QVariant>> &);
97         ///
98         QAbstractItemView * availableLV;
99         ///
100         QAbstractItemView * selectedLV;
101         ///
102         QPushButton * addPB;
103         ///
104         QPushButton * deletePB;
105         ///
106         QPushButton * upPB;
107         ///
108         QPushButton * downPB;
109         ///
110         QAbstractItemModel * availableModel;
111         ///
112         QAbstractItemModel * selectedModel;
113
114 protected Q_SLOTS:
115         ///
116         void availableChanged(QModelIndex const & idx, QModelIndex const &);
117         ///
118         void selectedChanged(QModelIndex const & idx, QModelIndex const &);
119         ///
120         void availableChanged(QItemSelection const & qis, QItemSelection const &);
121         ///
122         void selectedChanged(QItemSelection const & qis, QItemSelection const &);
123         ///
124         void selectedEdited();
125         ///
126         virtual void addPB_clicked();
127         ///
128         virtual void deletePB_clicked();
129         ///
130         virtual void upPB_clicked();
131         ///
132         virtual void downPB_clicked();
133         ///
134         void availableLV_doubleClicked(const QModelIndex &);
135         ///
136         bool eventFilter(QObject *, QEvent *);
137         ///
138         void updateButtons();
139
140 private:
141         ///
142         virtual void updateAddPB();
143         ///
144         virtual void updateDelPB();
145         ///
146         virtual void updateDownPB();
147         ///
148         virtual void updateUpPB();
149         ///
150         bool selectedHasFocus_;
151         ///
152         int main_sel_col_;
153         ///
154         bool allow_multi_selection_;
155 };
156
157 } // namespace frontend
158 } // namespace lyx
159
160 #endif  // GUISELECTIONMANAGER