36 using namespace LeechCraft::Util;
39 : QAbstractItemModel (parent)
40 , DefaultAcceptsRowImpl_ (false)
54 return mapped.model ()->columnCount (mapped);
57 return Headers_.size ();
62 if (orient != Qt::Horizontal || role != Qt::DisplayRole)
65 return Headers_.at (column);
73 return mapped.data (role);
82 return mapped.flags ();
87 if (parent.isValid () || !hasIndex (row, column))
88 return QModelIndex ();
90 return createIndex (row, column);
96 return QModelIndex ();
101 if (!parent.isValid ())
104 for (models_t::const_iterator i =
Models_.begin (),
107 result += RowCount (*i);
113 return mapped.model ()->rowCount (mapped);
119 if (!sourceIndex.isValid ())
120 return QModelIndex ();
122 const QAbstractItemModel *model = sourceIndex.model ();
127 int sourceRow = sourceIndex.row ();
128 int sourceColumn = sourceIndex.column ();
129 void *sourcePtr = sourceIndex.internalPointer ();
130 quint32 sourceId = sourceIndex.internalId ();
133 return createIndex (sourceRow + startingRow, sourceColumn, sourcePtr);
135 return createIndex (sourceRow + startingRow, sourceColumn, sourceId);
140 if (!proxyIndex.isValid ())
141 return QModelIndex ();
143 int proxyRow = proxyIndex.row ();
144 int proxyColumn = proxyIndex.column ();
152 catch (
const std::runtime_error& e)
155 Q_FOREACH (QAbstractItemModel *model,
Models_)
156 models << model->objectName ();
157 qWarning () << Q_FUNC_INFO
168 return (*modIter)->index (proxyRow - startingRow, proxyColumn, QModelIndex ());
173 throw std::runtime_error (
"You should not set source model via setSourceModel()");
186 int rows = RowCount (model);
187 bool wouldInsert =
false;
195 SIGNAL (columnsAboutToBeInserted (
const QModelIndex&,
int,
int)),
199 SIGNAL (columnsAboutToBeRemoved (
const QModelIndex&,
int,
int)),
203 SIGNAL (columnsInserted (
const QModelIndex&,
int,
int)),
207 SIGNAL (columnsRemoved (
const QModelIndex&,
int,
int)),
211 SIGNAL (dataChanged (
const QModelIndex&,
const QModelIndex&)),
215 SIGNAL (layoutAboutToBeChanged ()),
217 SIGNAL (layoutAboutToBeChanged ()));
219 SIGNAL (layoutChanged ()),
221 SIGNAL (layoutChanged ()));
223 SIGNAL (modelAboutToBeReset ()),
225 SIGNAL (modelAboutToBeReset ()));
227 SIGNAL (modelReset ()),
229 SIGNAL (modelReset ()));
231 SIGNAL (rowsAboutToBeInserted (
const QModelIndex&,
int,
int)),
235 SIGNAL (rowsAboutToBeRemoved (
const QModelIndex&,
int,
int)),
239 SIGNAL (rowsInserted (
const QModelIndex&,
int,
int)),
243 SIGNAL (rowsRemoved (
const QModelIndex&,
int,
int)),
262 models_t::iterator i =
FindModel (model);
266 qWarning () << Q_FUNC_INFO <<
"not found model" << model;
270 int rows = RowCount (model);
271 bool wouldRemove =
false;
278 beginRemoveRows (QModelIndex (), startingRow, startingRow + rows - 1);
293 for (models_t::const_iterator i =
Models_.begin (); i != it; ++i)
294 result += RowCount (*i);
303 for (models_t::const_iterator i =
Models_.begin (),
304 end =
Models_.end (); i != end; ++i)
306 counter += RowCount (*i);
312 QString msg = Q_FUNC_INFO;
313 msg +=
": not found ";
314 msg += QString::number (row);
315 throw std::runtime_error (qPrintable (msg));
323 for (models_t::iterator i =
Models_.begin (),
324 end =
Models_.end (); i != end; ++i)
326 counter += RowCount (*i);
332 QString msg = Q_FUNC_INFO;
333 msg +=
": not found ";
334 msg += QString::number (row);
335 throw std::runtime_error (qPrintable (msg));
340 QList<QAbstractItemModel*> result;
341 Q_FOREACH (QPointer<QAbstractItemModel> p,
Models_)
349 qWarning () <<
"model" << sender ()
350 <<
"called handleColumnsAboutToBeInserted, ignoring it";
356 qWarning () <<
"model" << sender ()
357 <<
"called handleColumnsAboutToBeRemoved, ignoring it";
363 qWarning () <<
"model" << sender ()
364 <<
"called handleColumnsInserted, ignoring it";
370 qWarning () <<
"model" << sender ()
371 <<
"called handleColumnsRemoved, ignoring it";
376 const QModelIndex& bottomRight)
384 QAbstractItemModel *model =
static_cast<QAbstractItemModel*
> (sender ());
387 first + startingRow, last + startingRow);
393 QAbstractItemModel *model =
static_cast<QAbstractItemModel*
> (sender ());
398 first + startingRow, last + startingRow);
400 catch (
const std::exception& e)
402 qWarning () << Q_FUNC_INFO
424 DefaultAcceptsRowImpl_ =
true;
428 int MergeModel::RowCount (QAbstractItemModel *model)
const
433 int orig = model->rowCount ();
434 if (DefaultAcceptsRowImpl_)
438 for (
int i = 0; i < orig; ++i)
virtual void setSourceModel(QAbstractItemModel *)
const_iterator GetModelForRow(int row, int *starting=0) const
virtual QModelIndex mapToSource(const QModelIndex &index) const
virtual QModelIndex mapFromSource(const QModelIndex &index) const
virtual bool AcceptsRow(QAbstractItemModel *model, int row) const
void SetHeaders(const QStringList &headers)
virtual QVariant headerData(int, Qt::Orientation, int=Qt::DisplayRole) const
virtual void handleRowsInserted(const QModelIndex &, int, int)
virtual int columnCount(const QModelIndex &=QModelIndex()) const
virtual void handleColumnsRemoved(const QModelIndex &, int, int)
void AddModel(QAbstractItemModel *model)
void RemoveModel(QAbstractItemModel *model)
virtual QModelIndex index(int, int, const QModelIndex &=QModelIndex()) const
virtual QVariant data(const QModelIndex &, int=Qt::DisplayRole) const
virtual void handleRowsAboutToBeInserted(const QModelIndex &, int, int)
virtual void handleColumnsAboutToBeRemoved(const QModelIndex &, int, int)
models_t::const_iterator const_iterator
models_t::iterator iterator
QList< QAbstractItemModel * > GetAllModels() const
Returns all models intalled into this one.
MergeModel(const QStringList &, QObject *=0)
int GetStartingRow(const_iterator it) const
virtual void handleColumnsAboutToBeInserted(const QModelIndex &, int, int)
virtual void handleColumnsInserted(const QModelIndex &, int, int)
const_iterator FindModel(const QAbstractItemModel *model) const
virtual Qt::ItemFlags flags(const QModelIndex &) const
virtual void handleDataChanged(const QModelIndex &, const QModelIndex &)
virtual QModelIndex parent(const QModelIndex &) const
virtual void handleRowsAboutToBeRemoved(const QModelIndex &, int, int)
virtual void handleRowsRemoved(const QModelIndex &, int, int)
virtual int rowCount(const QModelIndex &=QModelIndex()) const