X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiSelectionManager.h;h=9875396864da53701896d58cc226f99cd6cdeceb;hb=823263904f35fe0d5beae12e5c057ffbc5de57f9;hp=f97dba29bbeafd82a7b91ecd851cd1588121613c;hpb=9a95d2a936748c057db94a3083c4b9e6587eea0b;p=lyx.git diff --git a/src/frontends/qt4/GuiSelectionManager.h b/src/frontends/qt4/GuiSelectionManager.h index f97dba29bb..9875396864 100644 --- a/src/frontends/qt4/GuiSelectionManager.h +++ b/src/frontends/qt4/GuiSelectionManager.h @@ -9,113 +9,148 @@ * Full author contact details are available in file CREDITS. */ -#ifndef QSELECTIONMANAGER_H -#define QSELECTIONMANAGER_H +#ifndef GUISELECTIONMANAGER_H +#define GUISELECTIONMANAGER_H -#include "Dialog.h" #include -#include -#include -#include -#include -#include +class QAbstractItemModel; +class QAbstractListModel; +class QModelIndex; +class QListView; +class QPushButton; +class QVariant; +class QAbstractItemView; +class QItemSelection; +template class QMap; namespace lyx { namespace frontend { /** Class to manage a collection of widgets that allows selection * of items from a list of available items. Adapted from code originally - * written for GuiCitationDialog. + * written for GuiCitationDialog. * Note that this is a not a QWidget, though it could be converted to - * one. Rather, the managed widgets---see constructor for descripton + * one. Rather, the managed widgets---see constructor for descripton * of them---should be created independently, and then passed to the * constructor. */ -class GuiSelectionManager : public QObject { +class GuiSelectionManager : public QObject +{ Q_OBJECT - public: - /// - GuiSelectionManager( - QListView * availableLV, - QListView * selectedLV, - QPushButton * addPB, - QPushButton * delPB, - QPushButton * upPB, - QPushButton * downPB, - QStringListModel * availableModel, - QStringListModel * selectedModel); - /// Sets the state of the various push buttons, depending upon the - /// state of the widgets. (E.g., "delete" is enabled only if the - /// selection is non-empty.) - virtual void updateView(); - - /// Not strictly a matter of focus, which may be elsewhere, but - /// whether selectedLV is `more focused' than availableLV. Intended - /// to be used, for example, in displaying information about a - /// highlighted item: should it be the highlighted available item - /// or the highlighted selected item that is displayed? - bool selectedFocused() { return selectedHasFocus_; }; +public: + /// + GuiSelectionManager(QObject * parent, + QAbstractItemView * availableLV, + QAbstractItemView * selectedLV, + QPushButton * addPB, + QPushButton * delPB, + QPushButton * upPB, + QPushButton * downPB, + QAbstractItemModel * availableModel, + QAbstractItemModel * selectedModel, + int const main_sel_col = 0); + /// Sets the state of the various push buttons, depending upon the + /// state of the widgets. (E.g., "delete" is enabled only if the + /// selection is non-empty.) + /// Note: this is separated out into updateAddPB(), etc, below, + /// for easy over-riding of these functions. + void update(); - Q_SIGNALS: - ///Emitted when the list of selected items has changed. - void selectionChanged(); - ///Emitted when something has changed that might lead the containing - ///dialog to want to update---the focused subwidget or selected item. - ///(Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.) - ///NOTE: No automatic update of the button state is done here. If you - ///just want to do that, connect updateHook() to updateView(). Much of the - ///time, though, you will want to do a bit more processing first, so - ///you can connect to some other function that itself calls updateView(). - void updateHook(); - ///Emitted on Ctrl-Enter in the availableLV. Intended to be connected - ///to an "OK" event in the parent dialog. - void okHook(); + /// Not strictly a matter of focus, which may be elsewhere, but + /// whether selectedLV is `more focused' than availableLV. Intended + /// to be used, for example, in displaying information about a + /// highlighted item: should it be the highlighted available item + /// or the highlighted selected item that is displayed? + bool selectedFocused() const { return selectedHasFocus_; } + /// Returns the selected index. Note that this will depend upon + /// selectedFocused(). + QModelIndex getSelectedIndex(int const c = 0) const; - - protected: - ///Given a QModelIndex from availableLV, determines whether it has - ///been selected (i.e., is also in selectedLV). - bool isSelected(const QModelIndex & idx); +Q_SIGNALS: + /// Emitted when the list of selected items has changed. + void selectionChanged(); + /// Emitted when something has changed that might lead the containing + /// dialog to want to update---the focused subwidget or selected item. + /// (Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.) + /// NOTE: No automatic update of the button state is done here. If you + /// just want to do that, connect updateHook() to updateView(). Much of the + /// time, though, you will want to do a bit more processing first, so + /// you can connect to some other function that itself calls updateView(). + void updateHook(); + /// Emitted on Ctrl-Enter in the availableLV. Intended to be connected + /// to an "OK" event in the parent dialog. + void okHook(); - protected Q_SLOTS: - /// - void availableChanged(const QModelIndex & idx, const QModelIndex &); - /// - void selectedChanged(const QModelIndex & idx, const QModelIndex &); - /// - void addPB_clicked(); - /// - void deletePB_clicked(); - /// - void upPB_clicked(); - /// - void downPB_clicked(); - /// - void availableLV_clicked(const QModelIndex &); - /// - void availableLV_doubleClicked(const QModelIndex &); - /// - void selectedLV_clicked(const QModelIndex &); - /// - bool eventFilter(QObject *, QEvent *); - private: - QListView * availableLV; - QListView * selectedLV; - QPushButton * addPB; - QPushButton * deletePB; - QPushButton * upPB; - QPushButton * downPB; - QStringListModel * availableModel; - QStringListModel * selectedModel; - Dialog::View * dialog; - - bool selectedHasFocus_; +protected: + /// Given a QModelIndex from availableLV, determines whether it has + /// been selected (i.e., is also in selectedLV). + bool isSelected(const QModelIndex & idx); + /// + bool insertRowToSelected(int i, QMap const & itemData); + /// + bool insertRowToSelected(int i, QMap> &); + /// + QAbstractItemView * availableLV; + /// + QAbstractItemView * selectedLV; + /// + QPushButton * addPB; + /// + QPushButton * deletePB; + /// + QPushButton * upPB; + /// + QPushButton * downPB; + /// + QAbstractItemModel * availableModel; + /// + QAbstractItemModel * selectedModel; + +protected Q_SLOTS: + /// + void availableChanged(QModelIndex const & idx, QModelIndex const &); + /// + void selectedChanged(QModelIndex const & idx, QModelIndex const &); + /// + void availableChanged(QItemSelection const & qis, QItemSelection const &); + /// + void selectedChanged(QItemSelection const & qis, QItemSelection const &); + /// + void selectedEdited(); + /// + virtual void addPB_clicked(); + /// + virtual void deletePB_clicked(); + /// + virtual void upPB_clicked(); + /// + virtual void downPB_clicked(); + /// + void availableLV_doubleClicked(const QModelIndex &); + /// + bool eventFilter(QObject *, QEvent *); + /// + void updateButtons(); + +private: + /// + virtual void updateAddPB(); + /// + virtual void updateDelPB(); + /// + virtual void updateDownPB(); + /// + virtual void updateUpPB(); + /// + bool selectedHasFocus_; + /// + int main_sel_col_; }; } // namespace frontend } // namespace lyx -#endif +#endif // GUISELECTIONMANAGER