Beispiel #1
0
void FlatToFoldersProxyModel::SetSourceModel (QAbstractItemModel *model)
{
    if (SourceModel_)
        disconnect (SourceModel_,
                    0,
                    this,
                    0);

    SourceModel_ = model;

    if (model)
    {
        // We don't support changing columns (yet) so don't connect
        // to columns* signals.
        connect (model,
                 SIGNAL (headerDataChanged (Qt::Orientation, int, int)),
                 this,
                 SIGNAL (headerDataChanged (Qt::Orientation, int, int)));
        connect (model,
                 SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
                 this,
                 SLOT (handleDataChanged (const QModelIndex&, const QModelIndex&)));
        connect (model,
                 SIGNAL (layoutAboutToBeChanged ()),
                 this,
                 SIGNAL (layoutAboutToBeChanged ()));
        connect (model,
                 SIGNAL (layoutChanged ()),
                 this,
                 SIGNAL (layoutChanged ()));
        connect (model,
                 SIGNAL (modelReset ()),
                 this,
                 SLOT (handleModelReset ()));
        connect (model,
                 SIGNAL (rowsInserted (const QModelIndex&,
                                       int, int)),
                 this,
                 SLOT (handleRowsInserted (const QModelIndex&,
                                           int, int)));
        connect (model,
                 SIGNAL (rowsAboutToBeRemoved (const QModelIndex&,
                                               int, int)),
                 this,
                 SLOT (handleRowsAboutToBeRemoved (const QModelIndex&,
                         int, int)));
    }

    handleModelReset ();
}
Beispiel #2
0
	void MergeModel::AddModel (QAbstractItemModel *model)
	{
		if (!model)
			return;

		Models_.push_back (model);

		connect (model,
				SIGNAL (columnsAboutToBeInserted (const QModelIndex&, int, int)),
				this,
				SLOT (handleColumnsAboutToBeInserted (const QModelIndex&, int, int)));
		connect (model,
				SIGNAL (columnsAboutToBeRemoved (const QModelIndex&, int, int)),
				this,
				SLOT (handleColumnsAboutToBeRemoved (const QModelIndex&, int, int)));
		connect (model,
				SIGNAL (columnsInserted (const QModelIndex&, int, int)),
				this,
				SLOT (handleColumnsInserted (const QModelIndex&, int, int)));
		connect (model,
				SIGNAL (columnsRemoved (const QModelIndex&, int, int)),
				this,
				SLOT (handleColumnsRemoved (const QModelIndex&, int, int)));
		connect (model,
				SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
				this,
				SLOT (handleDataChanged (const QModelIndex&, const QModelIndex&)));
		connect (model,
				SIGNAL (layoutAboutToBeChanged ()),
				this,
				SLOT (handleModelAboutToBeReset ()));
		connect (model,
				SIGNAL (layoutChanged ()),
				this,
				SLOT (handleModelReset ()));
		connect (model,
				SIGNAL (modelAboutToBeReset ()),
				this,
				SLOT (handleModelAboutToBeReset ()));
		connect (model,
				SIGNAL (modelReset ()),
				this,
				SLOT (handleModelReset ()));
		connect (model,
				SIGNAL (rowsAboutToBeInserted (const QModelIndex&, int, int)),
				this,
				SLOT (handleRowsAboutToBeInserted (const QModelIndex&, int, int)));
		connect (model,
				SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
				this,
				SLOT (handleRowsAboutToBeRemoved (const QModelIndex&, int, int)));
		connect (model,
				SIGNAL (rowsInserted (const QModelIndex&, int, int)),
				this,
				SLOT (handleRowsInserted (const QModelIndex&, int, int)));
		connect (model,
				SIGNAL (rowsRemoved (const QModelIndex&, int, int)),
				this,
				SLOT (handleRowsRemoved (const QModelIndex&, int, int)));

		if (const auto rc = model->rowCount ())
		{
			beginInsertRows ({}, rowCount ({}), rowCount ({}) + rc - 1);

			for (auto i = 0; i < rc; ++i)
				Root_->AppendChild (model, model->index (i, 0), Root_);

			endInsertRows ();
		}
	}