2 * \file GuiIdListModel.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Some of this code is based upon qstringlistmodel.{h,cpp}, which is
9 * part of the Qt toolkit, copyright (C) 1992-2007 Trolltech ASA, and
10 * released under the General Public License.
12 * Full author contact details are available in file CREDITS.
17 #include "GuiIdListModel.h"
24 QVariant GuiIdListModel::data(QModelIndex const & index, int role) const
26 int const row = index.row();
29 if (role == Qt::DisplayRole || role == Qt::EditRole)
30 return userData_[row].uiString;
31 if (role == Qt::UserRole)
32 return userData_[row].idString;
37 bool GuiIdListModel::setData (QModelIndex const & index,
38 const QVariant & value, int role)
40 int const row = index.row();
43 if (role == Qt::DisplayRole || role == Qt::EditRole) {
44 userData_[row].uiString = value;
45 dataChanged(index, index);
48 if (role == Qt::UserRole) {
49 userData_[row].idString = value;
50 dataChanged(index, index);
57 bool GuiIdListModel::insertRows(int row, int count,
58 QModelIndex const & /*parent*/)
62 vector<OurData>::iterator it = userData_.begin() + row;
64 beginInsertRows(QModelIndex(), row, row + count - 1);
65 userData_.insert(it, count, v);
71 bool GuiIdListModel::removeRows(int row, int count,
72 QModelIndex const & /*parent*/)
74 if (!rowIsValid(row) || row + count > int(userData_.size()) ||
79 vector<OurData>::iterator it = userData_.begin() + row;
80 beginRemoveRows(QModelIndex(), row, row + count - 1);
81 userData_.erase(it, it + count);
87 void GuiIdListModel::insertRow(int const i, std::string const & uiString,
88 std::string const & idString)
91 setUIString(i, uiString);
92 setIDString(i, idString);
97 GuiIdListModel::itemData(QModelIndex const & index ) const
99 int const row = index.row();
100 if (!rowIsValid(row))
101 return QMap<int, QVariant>();
102 QMap<int, QVariant> qm = QAbstractListModel::itemData(index);
103 qm[Qt::UserRole] = userData_[row].idString;
107 /* The following functions are currently unused but are retained here in
108 case they should at some point be useful.
110 QStringList GuiIdListModel::getIDStringList() const {
112 vector<OurData>::const_iterator it = userData_.begin();
113 vector<OurData>::const_iterator end = userData_.end();
114 for (; it != end; ++it)
115 qsl.append(it->idString.toString());
120 void GuiIdListModel::insertRow(int const i, QString const & uiString,
121 QString const & idString)
124 setUIString(i, uiString);
125 setIDString(i, idString);
128 bool GuiIdListModel::containsID(QVariant const & q) const
130 vector<OurData>::const_iterator it = userData_.begin();
131 vector<OurData>::const_iterator end = userData_.end();
132 for (; it != end; ++it)
133 if (it->idString == q)