]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiIdListModel.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / GuiIdListModel.cpp
index 5872514d9644c976315ab72d557583d6b0cbaf4f..17cab6b20ae0d2ee7bd0820c8ca8b5772009cd4f 100644 (file)
 
 #include "GuiIdListModel.h"
 
+#include "support/assert.h"
+
 using std::vector;
 
 namespace lyx {
 namespace frontend {
 
+
+// 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();
        if (!rowIsValid(row))
                return QVariant();
-       if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::ToolTipRole)
+       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();
@@ -50,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
 }
 
 
@@ -86,10 +102,18 @@ bool GuiIdListModel::removeRows(int row, int count,
 
 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);
 }
 
 
@@ -116,9 +140,8 @@ int GuiIdListModel::findIDString(std::string const & idString)
 
 
 #if 0
-// The following functions are currently unused but are retained here in
-//   case they should at some point be useful.
-   
+// The following function is currently unused but is retained here in
+//   case it should at some point be useful.
 QStringList GuiIdListModel::getIDStringList() const
 {
        QStringList qsl;
@@ -128,18 +151,7 @@ QStringList GuiIdListModel::getIDStringList() const
                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);
-}
-
 #endif
-
 } // namespace frontend
 } // namespace lyx