]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiIdListModel.h
QDialogButtonBox for the remaining dialogs.
[lyx.git] / src / frontends / qt4 / GuiIdListModel.h
index 09906ff71b9ceca04e2275ffba12f9cfcb81923e..03c891d8efba92a6ea0b8c0122bf51b1b039bb5e 100644 (file)
@@ -28,10 +28,10 @@ namespace frontend {
 /**
  * A QAbstractListModel that associates an identifying string with
  * each item, as well as a display string. The display string is set
- * with setUIString; the identifying string, with setIDString. 
+ * with setUIString; the identifying string, with setIDString.
  *
  * This is intended to be used, for example, with GuiSelectionManager.
- * In that case, one needs to recover from selectedModel which items 
+ * In that case, one needs to recover from selectedModel which items
  * have been selected. One may not wish to do so using the string that
  * is there *displayed*, since, among other things, that string may be
  * translated. So the id can be used to identify the items in this case.
@@ -48,16 +48,16 @@ public:
                { return userData_.size(); }
 
        ///
-       virtual QVariant data(QModelIndex const & index, 
+       virtual QVariant data(QModelIndex const & index,
                              int role = Qt::DisplayRole) const;
        ///
        bool insertRows(int row, int count, QModelIndex const & parent = QModelIndex());
        ///
        bool removeRows(int row, int count, QModelIndex const & parent = QModelIndex());
-       /// 
+       ///
        void clear() { removeRows(0, rowCount()); }
        ///
-       virtual bool setData (QModelIndex const & index, 
+       virtual bool setData (QModelIndex const & index,
                        const QVariant & value, int role = Qt::EditRole );
        ///
        virtual QMap<int, QVariant> itemData(QModelIndex const & index ) const;
@@ -65,54 +65,51 @@ public:
        // New methods
        //////////////////////////////////////////////////////////////////////
        ///
-       void setUIString(QModelIndex const & index, QString const & value)
-                       { setData(index, value); }
-       ///
-       void setUIString(int const i, QString const & value)
-                       { setUIString(index(i), value); }
-       ///
-       void setIDString(QModelIndex const & index, QString const & value)
-                       { setData(index, value, Qt::UserRole); }
-       ///
-       void setIDString(int const i, std::string const & value)
-                       { setIDString(index(i), toqstr(value)); }
+       void insertRow(int const i, QString const & uiString,
+                       std::string const & idString, QString const & ttString);
+       /// A convenience method, setting ttString to the same as uiString
+       void insertRow(int const i, QString const & uiString,
+                       std::string const & idString);
+       /// \return the index of the (first) item with idString
+       /// \return -1 if not found
+       int findIDString(std::string const & idString);
        ///
        virtual QString getIDString(QModelIndex const & index) const
-                       { return data(index, Qt::UserRole).toString(); }
+               { return data(index, Qt::UserRole).toString(); }
        ///
        virtual std::string getIDString(int const i) const
-                       { return fromqstr(getIDString(index(i))); }
-       ///
-       void insertRow(int const i, QString const & uiString, 
-                       std::string const & idString);
-       /* The following functions are currently unused but are retained here in
-          case they should at some point be useful.
+               { return fromqstr(getIDString(index(i))); }
+
+private:
+       /// noncopyable
+       GuiIdListModel(GuiIdListModel const &);
        ///
-       void setUIString(int const i, std::string const & value)
-                       { setUIString(index(i), value); }
+       void operator=(GuiIdListModel const &);
        ///
-       void setIDString(int const i, QString const & value)
-                       { setIDString(index(i), value); }
+       void setUIString(QModelIndex const & index, QString const & value)
+               { setData(index, value); }
        ///
-       QStringList getIDStringList() const;
+       void setUIString(int const i, QString const & value)
+               { setUIString(index(i), value); }
        ///
-       void insertRow(int const i, QString const & uiString, 
-                       QString const & idString);
+       void setIDString(QModelIndex const & index, QString const & value)
+               { setData(index, value, Qt::UserRole); }
        ///
-       void insertRow(int const i, std::string const & uiString, 
-                       std::string const & idString);
-       /// Returns whether the model contains an item with the given ID
-       bool containsID(QVariant const &) const;
-       */
-private:
-       /// noncopyable
-       GuiIdListModel(GuiIdListModel const &);
+       void setIDString(int const i, std::string const & value)
+               { setIDString(index(i), toqstr(value)); }
        ///
-       void operator=(GuiIdListModel const &);
+       void setTTString(QModelIndex const & index, QString const & value)
+               { setData(index, value, Qt::ToolTipRole); }
        ///
+       void setTTString(int const i, QString const & value)
+               { setTTString(index(i), value); }
        struct OurData {
+               /// Qt::DisplayRole and Qt::EditRole
                QVariant uiString;
+               /// Qt::UserRole
                QVariant idString;
+               /// Qt::ToolTipRole
+               QVariant ttString;
        };
        ///
        std::vector<OurData> userData_;
@@ -124,6 +121,6 @@ private:
 };
 
 
-}
-}
-#endif //GUIIDLISTMODEL_H 
+} // namespace frontend
+} // namespace lyx
+#endif //GUIIDLISTMODEL_H