/***************************************************************************
- * Copyright (C) 2005-2015 by the Quassel Project *
+ * Copyright (C) 2005-2018 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
#include <QDebug>
FlatProxyModel::FlatProxyModel(QObject *parent)
- : QAbstractProxyModel(parent),
- _rootSourceItem(0)
+ : QAbstractProxyModel(parent)
{
}
QModelIndex FlatProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
{
if (!sourceIndex.isValid())
- return QModelIndex();
+ return {};
SourceItem *sourceItem = sourceToInternal(sourceIndex);
Q_ASSERT(sourceItem);
QModelIndex FlatProxyModel::mapToSource(const QModelIndex &proxyIndex) const
{
if (!proxyIndex.isValid())
- return QModelIndex();
+ return {};
Q_ASSERT(proxyIndex.model() == this);
Q_ASSERT(_rootSourceItem);
qWarning() << "FlatProxyModel::mapToSource(): couldn't find source index for" << proxyIndex;
Q_ASSERT(false);
- return QModelIndex(); // make compilers happy :)
+ return {}; // make compilers happy :)
}
QModelIndex currentParent = currentRange.topLeft().parent();
Q_ASSERT(currentParent == currentRange.bottomRight().parent());
- SourceItem *parentItem = 0;
+ SourceItem *parentItem = nullptr;
if (!itemLookup.contains(currentParent)) {
parentItem = sourceToInternal(currentParent);
itemLookup[currentParent] = parentItem;
for (int i = 0; i < proxySelection.count(); i++) {
const QItemSelectionRange &range = proxySelection[i];
- SourceItem *topLeftItem = 0;
- SourceItem *bottomRightItem = 0;
- SourceItem *currentItem = static_cast<SourceItem *>(range.topLeft().internalPointer());
+ SourceItem *topLeftItem = nullptr;
+ SourceItem *bottomRightItem = nullptr;
+ auto *currentItem = static_cast<SourceItem *>(range.topLeft().internalPointer());
int row = range.topLeft().row();
int left = range.topLeft().column();
int right = range.bottomRight().column();
else {
Q_ASSERT(topLeftItem && bottomRightItem);
sourceSelection << QItemSelectionRange(mapToSource(createIndex(topLeftItem->pos(), left, topLeftItem)), mapToSource(createIndex(bottomRightItem->pos(), right, bottomRightItem)));
- topLeftItem = 0;
- bottomRightItem = 0;
+ topLeftItem = nullptr;
+ bottomRightItem = nullptr;
}
// update loop vars
row++;
}
- Q_ASSERT(topLeftItem && bottomRightItem); // there should be one range left.
- sourceSelection << QItemSelectionRange(mapToSource(createIndex(topLeftItem->pos(), left, topLeftItem)), mapToSource(createIndex(bottomRightItem->pos(), right, bottomRightItem)));
+ if (topLeftItem && bottomRightItem) { // there should be one range left.
+ sourceSelection << QItemSelectionRange(mapToSource(createIndex(topLeftItem->pos(), left, topLeftItem)), mapToSource(createIndex(bottomRightItem->pos(), right, bottomRightItem)));
+ }
}
return sourceSelection;
void FlatProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
{
if (QAbstractProxyModel::sourceModel()) {
- disconnect(QAbstractProxyModel::sourceModel(), 0, this, 0);
+ disconnect(QAbstractProxyModel::sourceModel(), nullptr, this, nullptr);
}
QAbstractProxyModel::setSourceModel(sourceModel);
emit layoutChanged();
if (sourceModel) {
- connect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)),
- this, SLOT(on_columnsAboutToBeInserted(const QModelIndex &, int, int)));
- connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)),
- this, SLOT(on_columnsAboutToBeRemoved(const QModelIndex &, int, int)));
- connect(sourceModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)),
- this, SLOT(on_columnsInserted(const QModelIndex &, int, int)));
- connect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
- this, SLOT(on_columnsRemoved(const QModelIndex &, int, int)));
-
- connect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
- this, SLOT(on_dataChanged(const QModelIndex &, const QModelIndex &)));
+ connect(sourceModel, &QAbstractItemModel::columnsAboutToBeInserted,
+ this, &FlatProxyModel::on_columnsAboutToBeInserted);
+ connect(sourceModel, &QAbstractItemModel::columnsAboutToBeRemoved,
+ this, &FlatProxyModel::on_columnsAboutToBeRemoved);
+ connect(sourceModel, &QAbstractItemModel::columnsInserted,
+ this, &FlatProxyModel::on_columnsInserted);
+ connect(sourceModel, &QAbstractItemModel::columnsRemoved,
+ this, &FlatProxyModel::on_columnsRemoved);
+
+ connect(sourceModel, &QAbstractItemModel::dataChanged,
+ this, &FlatProxyModel::on_dataChanged);
// on_headerDataChanged(Qt::Orientation orientation, int first, int last)
- connect(sourceModel, SIGNAL(layoutAboutToBeChanged()),
- this, SLOT(on_layoutAboutToBeChanged()));
- connect(sourceModel, SIGNAL(layoutChanged()),
- this, SLOT(on_layoutChanged()));
+ connect(sourceModel, &QAbstractItemModel::layoutAboutToBeChanged,
+ this, &FlatProxyModel::on_layoutAboutToBeChanged);
+ connect(sourceModel, &QAbstractItemModel::layoutChanged,
+ this, &FlatProxyModel::on_layoutChanged);
- connect(sourceModel, SIGNAL(modelAboutToBeReset()),
- this, SLOT(on_modelAboutToBeReset()));
+ connect(sourceModel, &QAbstractItemModel::modelAboutToBeReset,
+ this, &FlatProxyModel::on_modelAboutToBeReset);
// void on_modelReset()
- connect(sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
- this, SLOT(on_rowsAboutToBeInserted(const QModelIndex &, int, int)));
- connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
- this, SLOT(on_rowsAboutToBeRemoved(const QModelIndex &, int, int)));
- connect(sourceModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
- this, SLOT(on_rowsInserted(const QModelIndex &, int, int)));
- connect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
- this, SLOT(on_rowsRemoved(const QModelIndex &, int, int)));
+ connect(sourceModel, &QAbstractItemModel::rowsAboutToBeInserted,
+ this, &FlatProxyModel::on_rowsAboutToBeInserted);
+ connect(sourceModel, &QAbstractItemModel::rowsAboutToBeRemoved,
+ this, &FlatProxyModel::on_rowsAboutToBeRemoved);
+ connect(sourceModel, &QAbstractItemModel::rowsInserted,
+ this, &FlatProxyModel::on_rowsInserted);
+ connect(sourceModel, &QAbstractItemModel::rowsRemoved,
+ this, &FlatProxyModel::on_rowsRemoved);
}
}
SourceItem *lastItem = insertSubTreeHelper(newSubTree, newSubTree, source_idx);
Q_ASSERT(lastItem);
- Q_ASSERT(lastItem->next() == 0);
+ Q_ASSERT(lastItem->next() == nullptr);
if (emitInsert)
beginInsertRows(QModelIndex(), newSubTree->pos(), lastItem->pos());
FlatProxyModel::SourceItem *FlatProxyModel::insertSubTreeHelper(SourceItem *parentItem, SourceItem *lastItem_, const QModelIndex &source_idx)
{
SourceItem *lastItem = lastItem_;
- SourceItem *newItem = 0;
+ SourceItem *newItem = nullptr;
for (int row = 0; row < sourceModel()->rowCount(source_idx); row++) {
newItem = new SourceItem(row, parentItem);
newItem->setPos(lastItem->pos() + 1);
{
if (parent.isValid()) {
qWarning() << "FlatProxyModel::index() called with valid parent:" << parent;
- return QModelIndex();
+ return {};
}
if (!_rootSourceItem) {
qWarning() << "FlatProxyModel::index() while model has no root Item";
- return QModelIndex();
+ return {};
}
SourceItem *item = _rootSourceItem;
item = item->findChild(row);
if (!item) {
qWarning() << "FlatProxyModel::index() no such row:" << row;
- return QModelIndex();
+ return {};
}
}
{
Q_UNUSED(index)
// this is a flat model
- return QModelIndex();
+ return {};
}
SourceItem *nextItem = prevItem->next();
- SourceItem *newItem = 0;
+ SourceItem *newItem = nullptr;
int newPos = prevItem->pos() + 1;
for (int row = start; row <= end; row++) {
newItem = new SourceItem(row, sourceItem);
// SourceItem
// ========================================
FlatProxyModel::SourceItem::SourceItem(int row, SourceItem *parent)
- : _parent(parent),
- _pos(-1),
- _next(0)
+ : _parent(parent)
{
if (parent) {
parent->_childs.insert(row, this);