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 QAbstractListModel;
22 class QAbstractItemView;
24 template <class T, class U> class QMap;
29 /** Class to manage a collection of widgets that allows selection
30 * of items from a list of available items. Adapted from code originally
31 * written for GuiCitationDialog.
32 * Note that this is a not a QWidget, though it could be converted to
33 * one. Rather, the managed widgets---see constructor for descripton
34 * of them---should be created independently, and then passed to the
37 class GuiSelectionManager : public QObject
44 QAbstractItemView * availableLV,
45 QListView * selectedLV,
50 QAbstractListModel * availableModel,
51 QAbstractListModel * selectedModel);
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() const;
70 /// Emitted when the list of selected items has changed.
71 void selectionChanged();
72 /// Emitted when something has changed that might lead the containing
73 /// dialog to want to update---the focused subwidget or selected item.
74 /// (Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.)
75 /// NOTE: No automatic update of the button state is done here. If you
76 /// just want to do that, connect updateHook() to updateView(). Much of the
77 /// time, though, you will want to do a bit more processing first, so
78 /// you can connect to some other function that itself calls updateView().
80 /// Emitted on Ctrl-Enter in the availableLV. Intended to be connected
81 /// to an "OK" event in the parent dialog.
86 /// Given a QModelIndex from availableLV, determines whether it has
87 /// been selected (i.e., is also in selectedLV).
88 bool isSelected(const QModelIndex & idx);
90 bool insertRowToSelected(int i, QMap<int, QVariant> const & itemData);
92 QAbstractItemView * availableLV;
94 QListView * selectedLV;
98 QPushButton * deletePB;
102 QPushButton * downPB;
104 QAbstractListModel * availableModel;
106 QAbstractListModel * selectedModel;
110 void availableChanged(QModelIndex const & idx, QModelIndex const &);
112 void selectedChanged(QModelIndex const & idx, QModelIndex const &);
114 void availableChanged(QItemSelection const & qis, QItemSelection const &);
116 void selectedChanged(QItemSelection const & qis, QItemSelection const &);
118 virtual void addPB_clicked();
120 virtual void deletePB_clicked();
122 virtual void upPB_clicked();
124 virtual void downPB_clicked();
126 void availableLV_doubleClicked(const QModelIndex &);
128 bool eventFilter(QObject *, QEvent *);
132 virtual void updateAddPB();
134 virtual void updateDelPB();
136 virtual void updateDownPB();
138 virtual void updateUpPB();
140 bool selectedHasFocus_;
143 } // namespace frontend
146 #endif // GUISELECTIONMANAGER