]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiIdListModel.cpp
Whitespace.
[lyx.git] / src / frontends / qt4 / GuiIdListModel.cpp
index 807235297affe766b446490c3e613f30972c7914..07b38708faebe7d022cfb813146e7d18277c7ce6 100644 (file)
 
 #include "GuiIdListModel.h"
 
+#include "support/lassert.h"
+
 using std::vector;
 
 namespace lyx {
 namespace frontend {
 
-GuiIdListModel::GuiIdListModel() :
-               QAbstractListModel()
-{}
-
 
+// Note: Any role that is added here must also be added to setData().
 QVariant GuiIdListModel::data(QModelIndex const & index, int role) const
 {
        int const row = index.row();
@@ -33,6 +32,10 @@ QVariant GuiIdListModel::data(QModelIndex const & index, int role) const
                return QVariant();
        if (role == Qt::DisplayRole || role == Qt::EditRole)
                return userData_[row].uiString;
+       if (role == Qt::ToolTipRole) {
+               QString const ttstr = userData_[row].ttString.toString();
+               return !ttstr.isEmpty() ? ttstr : userData_[row].uiString;
+       }
        if (role == Qt::UserRole)
                return userData_[row].idString;
        return QVariant();
@@ -55,7 +58,15 @@ bool GuiIdListModel::setData (QModelIndex const & index,
                dataChanged(index, index);
                return true;
        }
-       return false;
+       if (role == Qt::ToolTipRole) {
+               userData_[row].ttString = value;
+               dataChanged(index, index);
+               return true;
+       }
+       // If we assert here, it's because we're trying to set an
+       // unrecognized role.
+       LASSERT(false, return false);
+       return false; // silence the warning
 }
 
 
@@ -76,7 +87,7 @@ bool GuiIdListModel::insertRows(int row, int count,
 bool GuiIdListModel::removeRows(int row, int count, 
                QModelIndex const & /*parent*/)
 {
-       if (!rowIsValid(row) || row + count > userData_.size() ||
+       if (!rowIsValid(row) || row + count > int(userData_.size()) ||
            count < 0)
                return false;
        if (count == 0)
@@ -89,17 +100,24 @@ bool GuiIdListModel::removeRows(int row, int count,
 }
 
 
-void GuiIdListModel::insertRow(int const i, std::string const & uiString, 
+void GuiIdListModel::insertRow(int const i, QString const & uiString, 
                std::string const & idString)
+{
+       insertRow(i, uiString, idString, uiString);
+}
+
+
+void GuiIdListModel::insertRow(int const i, QString const & uiString, 
+       std::string const & idString, QString const & ttString)
 {
        insertRows(i, 1);
        setUIString(i, uiString);
        setIDString(i, idString);
+       setTTString(i, ttString);
 }
 
 
-QMap<int, QVariant> 
-       GuiIdListModel::itemData(QModelIndex const & index ) const 
+QMap<int, QVariant> GuiIdListModel::itemData(QModelIndex const & index) const
 {
        int const row = index.row();
        if (!rowIsValid(row))
@@ -109,38 +127,17 @@ QMap<int, QVariant>
        return qm;
 }
 
-/* The following functions are currently unused but are retained here in
-   case they should at some point be useful.
-   
-QStringList GuiIdListModel::getIDStringList() const {
-       QStringList qsl;
-       vector<OurData>::const_iterator it  = userData_.begin();
-       vector<OurData>::const_iterator end = userData_.end();
-       for (; it != end; ++it)
-               qsl.append(it->idString.toString());
-       return qsl;
-}
-
 
-void GuiIdListModel::insertRow(int const i, QString const & uiString, 
-               QString const & idString)
-{
-       insertRows(i, 1);
-       setUIString(i, uiString);
-       setIDString(i, idString);
-}
-
-bool GuiIdListModel::containsID(QVariant const & q) const
+int GuiIdListModel::findIDString(std::string const & idString) 
 {
        vector<OurData>::const_iterator it  = userData_.begin();
        vector<OurData>::const_iterator end = userData_.end();
        for (; it != end; ++it)
-               if (it->idString == q)
-                       return true;
-       return false;
+               if (fromqstr(it->idString.toString()) == idString)
+                       return it - userData_.begin();
+       return -1;
 }
-*/
 
-}
-}
+} // namespace frontend
+} // namespace lyx