X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiIdListModel.cpp;h=a8d3107ba7a492ce381dd3771ab309f0718be9c0;hb=43c09d723435a5b203f2ac0c39e2086de836b386;hp=2d15b0efabf511c46c25b3660e67fbdbac4c8dcc;hpb=2c382f2f471023d8a8fd16052e2bbf441a9cb980;p=lyx.git diff --git a/src/frontends/qt4/GuiIdListModel.cpp b/src/frontends/qt4/GuiIdListModel.cpp index 2d15b0efab..a8d3107ba7 100644 --- a/src/frontends/qt4/GuiIdListModel.cpp +++ b/src/frontends/qt4/GuiIdListModel.cpp @@ -16,11 +16,15 @@ #include "GuiIdListModel.h" +#include "support/lassert.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(); @@ -28,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(); @@ -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 } @@ -60,9 +76,8 @@ bool GuiIdListModel::insertRows(int row, int count, if (!rowIsValid(row)) return false; vector::iterator it = userData_.begin() + row; - OurData const v; beginInsertRows(QModelIndex(), row, row + count - 1); - userData_.insert(it, count, v); + userData_.insert(it, count, OurData()); endInsertRows(); return true; } @@ -86,10 +101,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); } @@ -114,32 +137,6 @@ int GuiIdListModel::findIDString(std::string const & idString) return -1; } - -#if 0 -// 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::const_iterator it = userData_.begin(); - vector::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); -} - -#endif - } // namespace frontend } // namespace lyx