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;
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 descripton
33 * of them---should be created independently, and then passed to the
36 class GuiSelectionManager : public QObject
43 QAbstractItemView * availableLV,
44 QListView * selectedLV,
49 QAbstractListModel * availableModel,
50 QAbstractListModel * selectedModel);
51 /// Sets the state of the various push buttons, depending upon the
52 /// state of the widgets. (E.g., "delete" is enabled only if the
53 /// selection is non-empty.)
54 /// Note: this is separated out into updateAddPB(), etc, below,
55 /// for easy over-riding of these functions.
58 /// Not strictly a matter of focus, which may be elsewhere, but
59 /// whether selectedLV is `more focused' than availableLV. Intended
60 /// to be used, for example, in displaying information about a
61 /// highlighted item: should it be the highlighted available item
62 /// or the highlighted selected item that is displayed?
63 bool selectedFocused() { return selectedHasFocus_; };
66 /// Emitted when the list of selected items has changed.
67 void selectionChanged();
68 /// Emitted when something has changed that might lead the containing
69 /// dialog to want to update---the focused subwidget or selected item.
70 /// (Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.)
71 /// NOTE: No automatic update of the button state is done here. If you
72 /// just want to do that, connect updateHook() to updateView(). Much of the
73 /// time, though, you will want to do a bit more processing first, so
74 /// you can connect to some other function that itself calls updateView().
76 /// Emitted on Ctrl-Enter in the availableLV. Intended to be connected
77 /// to an "OK" event in the parent dialog.
82 /// Given a QModelIndex from availableLV, determines whether it has
83 /// been selected (i.e., is also in selectedLV).
84 bool isSelected(const QModelIndex & idx);
86 bool insertRowToSelected(int i, QMap<int, QVariant> const & itemData);
88 QAbstractItemView * availableLV;
90 QListView * selectedLV;
94 QPushButton * deletePB;
100 QAbstractListModel * availableModel;
102 QAbstractListModel * selectedModel;
106 void availableChanged(const QModelIndex & idx, const QModelIndex &);
108 void selectedChanged(const QModelIndex & idx, const QModelIndex &);
110 virtual void addPB_clicked();
112 virtual void deletePB_clicked();
114 virtual void upPB_clicked();
116 virtual void downPB_clicked();
118 void availableLV_clicked(const QModelIndex &);
120 void availableLV_doubleClicked(const QModelIndex &);
122 void selectedLV_clicked(const QModelIndex &);
124 bool eventFilter(QObject *, QEvent *);
128 virtual void updateAddPB();
130 virtual void updateDelPB();
132 virtual void updateDownPB();
134 virtual void updateUpPB();
136 bool selectedHasFocus_;
139 } // namespace frontend
142 #endif // GUISELECTIONMANAGER