]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiIdListModel.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiIdListModel.cpp
index 17cab6b20ae0d2ee7bd0820c8ca8b5772009cd4f..d38a087f7c37a4ec82357244f540c77613cef642 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "GuiIdListModel.h"
 
-#include "support/assert.h"
+#include "support/lassert.h"
 
 using std::vector;
 
@@ -31,60 +31,66 @@ QVariant GuiIdListModel::data(QModelIndex const & index, int role) const
        if (!rowIsValid(row))
                return QVariant();
        if (role == Qt::DisplayRole || role == Qt::EditRole)
-               return userData_[row].uiString;
+               return userData_[ulong(row)].uiString;
        if (role == Qt::ToolTipRole) {
-               QString const ttstr = userData_[row].ttString.toString();
-               return !ttstr.isEmpty() ? ttstr : userData_[row].uiString;
+               QString const ttstr = userData_[ulong(row)].ttString.toString();
+               return !ttstr.isEmpty() ? ttstr : userData_[ulong(row)].uiString;
        }
        if (role == Qt::UserRole)
-               return userData_[row].idString;
+               return userData_[ulong(row)].idString;
        return QVariant();
 }
 
 
-bool GuiIdListModel::setData (QModelIndex const & index, 
+bool GuiIdListModel::setData(QModelIndex const & index,
                const QVariant & value, int role)
 {
        int const row = index.row();
        if (!rowIsValid(row))
                return false;
        if (role == Qt::DisplayRole || role == Qt::EditRole) {
-               userData_[row].uiString = value;
+               userData_[ulong(row)].uiString = value;
                dataChanged(index, index);
                return true;
        }
        if (role == Qt::UserRole) {
-               userData_[row].idString = value;
+               userData_[ulong(row)].idString = value;
                dataChanged(index, index);
                return true;
        }
        if (role == Qt::ToolTipRole) {
-               userData_[row].ttString = value;
+               userData_[ulong(row)].ttString = value;
                dataChanged(index, index);
                return true;
        }
+       if (role == Qt::DecorationRole)
+               // nothing to do
+               return true;
+       if (role == Qt::UserRole - 1)
+               // This role is set by Qt <= 5.5 if setEditable()
+               // of the item is false
+               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
+       LATTEST(false);
+       return false;
 }
 
 
-bool GuiIdListModel::insertRows(int row, int count, 
+bool GuiIdListModel::insertRows(int row, int count,
                QModelIndex const & /*parent*/)
 {
        if (!rowIsValid(row))
                return false;
        vector<OurData>::iterator it = userData_.begin() + row;
-       OurData const v;
        beginInsertRows(QModelIndex(), row, row + count - 1);
-       userData_.insert(it, count, v);
+       userData_.insert(it, ulong(count), OurData());
        endInsertRows();
        return true;
 }
 
 
-bool GuiIdListModel::removeRows(int row, int count, 
+bool GuiIdListModel::removeRows(int row, int count,
                QModelIndex const & /*parent*/)
 {
        if (!rowIsValid(row) || row + count > int(userData_.size()) ||
@@ -94,20 +100,20 @@ bool GuiIdListModel::removeRows(int row, int count,
                return true;
        vector<OurData>::iterator it = userData_.begin() + row;
        beginRemoveRows(QModelIndex(), row, row + count - 1);
-       userData_.erase(it, it + count);        
+       userData_.erase(it, it + count);
        endRemoveRows();
        return true;
 }
 
 
-void GuiIdListModel::insertRow(int const i, QString 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, 
+void GuiIdListModel::insertRow(int const i, QString const & uiString,
        std::string const & idString, QString const & ttString)
 {
        insertRows(i, 1);
@@ -123,12 +129,12 @@ QMap<int, QVariant> GuiIdListModel::itemData(QModelIndex const & index) const
        if (!rowIsValid(row))
                return QMap<int, QVariant>();
        QMap<int, QVariant> qm = QAbstractListModel::itemData(index);
-       qm[Qt::UserRole] = userData_[row].idString;
+       qm[Qt::UserRole] = userData_[ulong(row)].idString;
        return qm;
 }
 
 
-int GuiIdListModel::findIDString(std::string const & idString) 
+int GuiIdListModel::findIDString(std::string const & idString)
 {
        vector<OurData>::const_iterator it  = userData_.begin();
        vector<OurData>::const_iterator end = userData_.end();
@@ -138,20 +144,6 @@ int GuiIdListModel::findIDString(std::string const & idString)
        return -1;
 }
 
-
-#if 0
-// 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;
-       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;
-}
-#endif
 } // namespace frontend
 } // namespace lyx