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 int GuiIdListModel::findIDString(std::string const & idString)
109 vector<OurData>::const_iterator it = userData_.begin();
110 vector<OurData>::const_iterator end = userData_.end();
111 for (; it != end; ++it)
112 if (fromqstr(it->idString.toString()) == idString)
113 return it - userData_.begin();
119 // The following functions are currently unused but are retained here in
120 // case they should at some point be useful.
122 QStringList GuiIdListModel::getIDStringList() const
125 vector<OurData>::const_iterator it = userData_.begin();
126 vector<OurData>::const_iterator end = userData_.end();
127 for (; it != end; ++it)
128 qsl.append(it->idString.toString());
133 void GuiIdListModel::insertRow(int const i, QString const & uiString,
134 QString const & idString)
137 setUIString(i, uiString);
138 setIDString(i, idString);
143 } // namespace frontend