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, QString const & uiString,
88 std::string const & idString)
91 setUIString(i, uiString);
92 setIDString(i, idString);
96 QMap<int, QVariant> GuiIdListModel::itemData(QModelIndex const & index ) const
98 int const row = index.row();
100 return QMap<int, QVariant>();
101 QMap<int, QVariant> qm = QAbstractListModel::itemData(index);
102 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
113 vector<OurData>::const_iterator it = userData_.begin();
114 vector<OurData>::const_iterator end = userData_.end();
115 for (; it != end; ++it)
116 qsl.append(it->idString.toString());
121 void GuiIdListModel::insertRow(int const i, QString const & uiString,
122 QString const & idString)
125 setUIString(i, uiString);
126 setIDString(i, idString);
129 bool GuiIdListModel::containsID(QVariant const & q) const
131 vector<OurData>::const_iterator it = userData_.begin();
132 vector<OurData>::const_iterator end = userData_.end();
133 for (; it != end; ++it)
134 if (it->idString == q)
140 } // namespace frontend