SortFilterModel::SortFilterModel(QObject *parent)
    : QSortFilterProxyModel(parent),
      m_maximumCount(0),
      m_hide(false)
{
    connect(this, SIGNAL(sourceModelChanged()), SIGNAL(modelChanged()));
    connect(this, SIGNAL(sortRoleChanged()), SLOT(manualSort()));
    setDynamicSortFilter(false);
}
 void shouldNotifyWhenChangingSourceModel()
 {
     QSignalSpy spy(model, SIGNAL(sourceModelChanged()));
     model->setSourceModel(topsites);
     QVERIFY(spy.isEmpty());
     TopSitesModel* topsites2 = new TopSitesModel;
     model->setSourceModel(topsites2);
     QCOMPARE(spy.count(), 1);
     QCOMPARE(model->sourceModel(), topsites2);
     model->setSourceModel(0);
     QCOMPARE(spy.count(), 2);
     QCOMPARE(model->sourceModel(), (TopSitesModel*) 0);
     delete topsites2;
 }
/*!
    Sets the given \a sourceModel to be processed by the proxy model.

    Subclasses should call beginResetModel() at the beginning of the method,
    disconnect from the old model, call this method, connect to the new model,
    and call endResetModel().
*/
void QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
{
    Q_D(QAbstractProxyModel);
    if (sourceModel != d->model) {
        if (d->model)
            disconnect(d->model, SIGNAL(destroyed()), this, SLOT(_q_sourceModelDestroyed()));

        if (sourceModel) {
            d->model = sourceModel;
            connect(d->model, SIGNAL(destroyed()), this, SLOT(_q_sourceModelDestroyed()));
        } else {
            d->model = QAbstractItemModelPrivate::staticEmptyModel();
        }
        d->roleNames = d->model->roleNames();
        emit sourceModelChanged(QPrivateSignal());
    }
}
Example #4
0
void SortFilterModel::setModel(QAbstractItemModel *model)
{
    if (model == sourceModel()) {
        return;
    }

    if (sourceModel()) {
        disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(syncRoleNames()));
    }

    QSortFilterProxyModel::setSourceModel(model);

    if (model) {
        connect(model, SIGNAL(modelReset()), this, SLOT(syncRoleNames()));
        syncRoleNames();
    }

    emit sourceModelChanged(model);
}
void SortFilterProxyModel::setSourceModel(QAbstractItemModel * sourceModel) {
    if (sourceModel == this->sourceModel()) return;
    if (!sourceModel->inherits("FileTreeModel")) return;
    QSortFilterProxyModel::setSourceModel(sourceModel);
    emit sourceModelChanged();
}
Example #6
0
void FunnelModel::setSourceModel(AbstractModel *model)
{
    if (m_sourceModel == model) {
        return;
    }

    if (!model) {
        reset();

        return;
    }

    connect(model, SIGNAL(destroyed(QObject*)), this, SLOT(reset()));
    connect(model, SIGNAL(modelReset()), this, SLOT(reset()));

    if (!m_sourceModel) {
        emit beginResetModel();

        m_sourceModel = model;

        emit endResetModel();

        emit countChanged();

        emit sourceModelChanged();

        return;
    }

    int oldCount = m_sourceModel->count();
    int newCount = model->count();

    disconnect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
            this, SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
    disconnect(m_sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
            this, SLOT(sourceRowsRemoved(QModelIndex,int,int)));

    m_sourceModel = model;

    connect(m_sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
            this, SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
    connect(m_sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
            this, SLOT(sourceRowsRemoved(QModelIndex,int,int)));

    if (newCount > oldCount) {
        beginInsertRows(QModelIndex(), oldCount, newCount - 1);

        endInsertRows();
    } else if (newCount < oldCount) {
        if (newCount == 0) {
            beginResetModel();

            endResetModel();
        } else {
            beginRemoveRows(QModelIndex(), newCount, oldCount - 1);

            endRemoveRows();
        }
    }

    if (newCount > 0) {
        emit dataChanged(index(0, 0), index(qMin(oldCount, newCount) - 1, 0));
    }

    if (oldCount != newCount) {
        emit countChanged();
    }

    emit sourceModelChanged();
}
BooksCoverModel::BooksCoverModel(QObject* aParent) :
    QSortFilterProxyModel(aParent)
{
    connect(this, SIGNAL(sourceModelChanged()), SIGNAL(sourceChanged()));
}