X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fignorelistmodel.cpp;h=2f70ada055e0cdaad660828606c3607a678865f7;hp=6f639bd6e4a5f43b367f140c65bd8e61a77b002d;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=5b397a71c0f4827c3050659c39749d78831a0d6d diff --git a/src/qtui/settingspages/ignorelistmodel.cpp b/src/qtui/settingspages/ignorelistmodel.cpp index 6f639bd6..2f70ada0 100644 --- a/src/qtui/settingspages/ignorelistmodel.cpp +++ b/src/qtui/settingspages/ignorelistmodel.cpp @@ -21,20 +21,18 @@ #include "ignorelistmodel.h" #include -#include #include +#include #include "client.h" #include "signalproxy.h" -IgnoreListModel::IgnoreListModel(QObject *parent) - : QAbstractItemModel(parent), - _configChanged(false), - _modelReady(false) +IgnoreListModel::IgnoreListModel(QObject* parent) + : QAbstractItemModel(parent) { // we need this signal for future connects to reset the data; - connect(Client::instance(), SIGNAL(connected()), this, SLOT(clientConnected())); - connect(Client::instance(), SIGNAL(disconnected()), this, SLOT(clientDisconnected())); + connect(Client::instance(), &Client::connected, this, &IgnoreListModel::clientConnected); + connect(Client::instance(), &Client::disconnected, this, &IgnoreListModel::clientDisconnected); if (Client::isConnected()) clientConnected(); @@ -42,8 +40,7 @@ IgnoreListModel::IgnoreListModel(QObject *parent) emit modelReady(false); } - -QVariant IgnoreListModel::data(const QModelIndex &index, int role) const +QVariant IgnoreListModel::data(const QModelIndex& index, int role) const { if (!_modelReady) return QVariant(); @@ -92,6 +89,7 @@ QVariant IgnoreListModel::data(const QModelIndex &index, int role) const else return tr("By Message"); } + // Intentional fallthrough case Qt::EditRole: switch (index.column()) { case 0: @@ -108,8 +106,7 @@ QVariant IgnoreListModel::data(const QModelIndex &index, int role) const } } - -bool IgnoreListModel::setData(const QModelIndex &index, const QVariant &value, int role) +bool IgnoreListModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (!_modelReady) return false; @@ -126,8 +123,7 @@ bool IgnoreListModel::setData(const QModelIndex &index, const QVariant &value, i cloneIgnoreListManager()[index.row()].setIsEnabled(newValue.toBool()); return true; case 1: - cloneIgnoreListManager()[index.row()].setType( - (IgnoreListManager::IgnoreType)newValue.toInt()); + cloneIgnoreListManager()[index.row()].setType((IgnoreListManager::IgnoreType)newValue.toInt()); return true; case 2: if (ignoreListManager().contains(newValue.toString())) { @@ -142,21 +138,18 @@ bool IgnoreListModel::setData(const QModelIndex &index, const QVariant &value, i } } - -bool IgnoreListModel::newIgnoreRule(const IgnoreListManager::IgnoreListItem &item) +bool IgnoreListModel::newIgnoreRule(const IgnoreListManager::IgnoreListItem& item) { - IgnoreListManager &manager = cloneIgnoreListManager(); + IgnoreListManager& manager = cloneIgnoreListManager(); if (manager.contains(item.contents())) return false; beginInsertRows(QModelIndex(), rowCount(), rowCount()); // manager.addIgnoreListItem(item); - manager.addIgnoreListItem(item.type(), item.contents(), item.isRegEx(), item.strictness(), - item.scope(), item.scopeRule(), item.isEnabled()); + manager.addIgnoreListItem(item.type(), item.contents(), item.isRegEx(), item.strictness(), item.scope(), item.scopeRule(), item.isEnabled()); endInsertRows(); return true; } - void IgnoreListModel::loadDefaults() { /*if(!_modelReady) @@ -180,20 +173,18 @@ void IgnoreListModel::loadDefaults() endInsertRows();*/ } - void IgnoreListModel::removeIgnoreRule(int index) { if (index < 0 || index >= rowCount()) return; - IgnoreListManager &manager = cloneIgnoreListManager(); + IgnoreListManager& manager = cloneIgnoreListManager(); beginRemoveRows(QModelIndex(), index, index); manager.removeAt(index); endRemoveRows(); } - -Qt::ItemFlags IgnoreListModel::flags(const QModelIndex &index) const +Qt::ItemFlags IgnoreListModel::flags(const QModelIndex& index) const { if (!index.isValid()) { return Qt::ItemIsDropEnabled; @@ -203,13 +194,10 @@ Qt::ItemFlags IgnoreListModel::flags(const QModelIndex &index) const } } - QVariant IgnoreListModel::headerData(int section, Qt::Orientation orientation, int role) const { QStringList header; - header << tr("Enabled") - << tr("Type") - << tr("Ignore Rule"); + header << tr("Enabled") << tr("Type") << tr("Ignore Rule"); if (orientation == Qt::Horizontal && role == Qt::DisplayRole) return header[section]; @@ -217,18 +205,16 @@ QVariant IgnoreListModel::headerData(int section, Qt::Orientation orientation, i return QVariant(); } - -QModelIndex IgnoreListModel::index(int row, int column, const QModelIndex &parent) const +QModelIndex IgnoreListModel::index(int row, int column, const QModelIndex& parent) const { Q_UNUSED(parent); if (row >= rowCount() || column >= columnCount()) - return QModelIndex(); + return {}; return createIndex(row, column); } - -const IgnoreListManager &IgnoreListModel::ignoreListManager() const +const IgnoreListManager& IgnoreListModel::ignoreListManager() const { if (_configChanged) return _clonedIgnoreListManager; @@ -236,8 +222,7 @@ const IgnoreListManager &IgnoreListModel::ignoreListManager() const return *Client::ignoreListManager(); } - -IgnoreListManager &IgnoreListModel::ignoreListManager() +IgnoreListManager& IgnoreListModel::ignoreListManager() { if (_configChanged) return _clonedIgnoreListManager; @@ -245,8 +230,7 @@ IgnoreListManager &IgnoreListModel::ignoreListManager() return *Client::ignoreListManager(); } - -IgnoreListManager &IgnoreListModel::cloneIgnoreListManager() +IgnoreListManager& IgnoreListModel::cloneIgnoreListManager() { if (!_configChanged) { _clonedIgnoreListManager = *Client::ignoreListManager(); @@ -256,7 +240,6 @@ IgnoreListManager &IgnoreListModel::cloneIgnoreListManager() return _clonedIgnoreListManager; } - void IgnoreListModel::revert() { if (!_configChanged) @@ -268,7 +251,6 @@ void IgnoreListModel::revert() endResetModel(); } - void IgnoreListModel::commit() { if (!_configChanged) @@ -278,7 +260,6 @@ void IgnoreListModel::commit() revert(); } - void IgnoreListModel::initDone() { _modelReady = true; @@ -287,17 +268,15 @@ void IgnoreListModel::initDone() emit modelReady(true); } - void IgnoreListModel::clientConnected() { - connect(Client::ignoreListManager(), SIGNAL(updated()), SLOT(revert())); + connect(Client::ignoreListManager(), &IgnoreListManager::updated, this, &IgnoreListModel::revert); if (Client::ignoreListManager()->isInitialized()) initDone(); else - connect(Client::ignoreListManager(), SIGNAL(initDone()), SLOT(initDone())); + connect(Client::ignoreListManager(), &SyncableObject::initDone, this, &IgnoreListModel::initDone); } - void IgnoreListModel::clientDisconnected() { // clear @@ -308,22 +287,19 @@ void IgnoreListModel::clientDisconnected() emit modelReady(false); } - -const IgnoreListManager::IgnoreListItem &IgnoreListModel::ignoreListItemAt(int row) const +const IgnoreListManager::IgnoreListItem& IgnoreListModel::ignoreListItemAt(int row) const { return ignoreListManager()[row]; } - // FIXME use QModelIndex? -void IgnoreListModel::setIgnoreListItemAt(int row, const IgnoreListManager::IgnoreListItem &item) +void IgnoreListModel::setIgnoreListItemAt(int row, const IgnoreListManager::IgnoreListItem& item) { cloneIgnoreListManager()[row] = item; emit dataChanged(createIndex(row, 0), createIndex(row, 2)); } - -const QModelIndex IgnoreListModel::indexOf(const QString &rule) +const QModelIndex IgnoreListModel::indexOf(const QString& rule) { return createIndex(ignoreListManager().indexOf(rule), 2); }