X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Faliasesmodel.cpp;fp=src%2Fqtui%2Fsettingspages%2Faliasesmodel.cpp;h=0c9e75ff2b2c421cdfc79217e9cef4e5e88d2875;hp=54dbfd9b4b19a74c345447346351894aa605ba8a;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=30b159cb876a9495de42e9a3e70ca050516f0805 diff --git a/src/qtui/settingspages/aliasesmodel.cpp b/src/qtui/settingspages/aliasesmodel.cpp index 54dbfd9b..0c9e75ff 100644 --- a/src/qtui/settingspages/aliasesmodel.cpp +++ b/src/qtui/settingspages/aliasesmodel.cpp @@ -26,7 +26,7 @@ #include "client.h" #include "signalproxy.h" -AliasesModel::AliasesModel(QObject *parent) +AliasesModel::AliasesModel(QObject* parent) : QAbstractItemModel(parent) { // we need this signal for future connects to reset the data; @@ -39,8 +39,7 @@ AliasesModel::AliasesModel(QObject *parent) emit modelReady(false); } - -QVariant AliasesModel::data(const QModelIndex &index, int role) const +QVariant AliasesModel::data(const QModelIndex& index, int role) const { if (!_modelReady) return QVariant(); @@ -55,32 +54,27 @@ QVariant AliasesModel::data(const QModelIndex &index, int role) const return tr("The shortcut for the alias
" "It can be used as a regular slash command.

" "Example: \"foo\" can be used per /foo"); - case 1: - { + case 1: { // To avoid overwhelming the user, organize things into a table QString strTooltip; - QTextStream tooltip( &strTooltip, QIODevice::WriteOnly ); + QTextStream tooltip(&strTooltip, QIODevice::WriteOnly); tooltip << ""; // Function to add a row to the tooltip table - auto addRow = [&]( - const QString& key, const QString& value = QString(), bool condition = true) { + auto addRow = [&](const QString& key, const QString& value = QString(), bool condition = true) { if (condition) { if (value.isEmpty()) { - tooltip << "" - << key << ""; - } else { - tooltip << "" - << key << "" << value << ""; + tooltip << "" << key << ""; + } + else { + tooltip << "" << key << "" << value << ""; } } }; - tooltip << "

" - << tr("The string the shortcut will be expanded to") << "

"; + tooltip << "

" << tr("The string the shortcut will be expanded to") << "

"; - tooltip << "

" - << tr("Special variables") << "

"; + tooltip << "

" << tr("Special variables") << "

"; // Variable option table tooltip << ""; @@ -96,10 +90,8 @@ QVariant AliasesModel::data(const QModelIndex &index, int role) const addRow("$i:account", tr("account of user identified by i'th parameter, or a '*' if logged out or " "unknown")); - addRow("$i:hostname", - tr("hostname of user identified by i'th parameter, or a '*' if unknown")); - addRow("$i:ident", - tr("ident of user identified by i'th parameter, or a '*' if unknown")); + addRow("$i:hostname", tr("hostname of user identified by i'th parameter, or a '*' if unknown")); + addRow("$i:ident", tr("ident of user identified by i'th parameter, or a '*' if unknown")); addRow("$i:identd", tr("ident of user identified by i'th parameter if verified, or a '*' if unknown " "or unverified (prefixed with '~')")); @@ -114,12 +106,10 @@ QVariant AliasesModel::data(const QModelIndex &index, int role) const tooltip << "
"; // Example header - tooltip << "

" - << tr("Multiple commands can be separated with semicolons") << "

"; + tooltip << "

" << tr("Multiple commands can be separated with semicolons") << "

"; // Example tooltip << "

"; - tooltip << QString("

%1 %2
").arg( - tr("Example:"), tr("\"Test $1; Test $2; Test All $0\"")); + tooltip << QString("

%1 %2
").arg(tr("Example:"), tr("\"Test $1; Test $2; Test All $0\"")); tooltip << tr("...will be expanded to three separate messages \"Test 1\", \"Test 2\" " "and \"Test All 1 2 3\" when called like /test 1 2 3") << "

"; @@ -146,8 +136,7 @@ QVariant AliasesModel::data(const QModelIndex &index, int role) const } } - -bool AliasesModel::setData(const QModelIndex &index, const QVariant &value, int role) +bool AliasesModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (!_modelReady) return false; @@ -176,12 +165,11 @@ bool AliasesModel::setData(const QModelIndex &index, const QVariant &value, int } } - void AliasesModel::newAlias() { QString newName("alias"); int i = 0; - AliasManager &manager = cloneAliasManager(); + AliasManager& manager = cloneAliasManager(); while (manager.contains(newName)) { i++; newName = QString("alias%1").arg(i); @@ -191,13 +179,12 @@ void AliasesModel::newAlias() endInsertRows(); } - void AliasesModel::loadDefaults() { if (!_modelReady) return; - AliasManager &manager = cloneAliasManager(); + AliasManager& manager = cloneAliasManager(); if (!manager.isEmpty()) { beginRemoveRows(QModelIndex(), 0, rowCount() - 1); @@ -208,26 +195,24 @@ void AliasesModel::loadDefaults() AliasManager::AliasList defaults = AliasManager::defaults(); beginInsertRows(QModelIndex(), 0, defaults.count() - 1); - foreach(AliasManager::Alias alias, defaults) { + foreach (AliasManager::Alias alias, defaults) { manager.addAlias(alias.name, alias.expansion); } endInsertRows(); } - void AliasesModel::removeAlias(int index) { if (index < 0 || index >= rowCount()) return; - AliasManager &manager = cloneAliasManager(); + AliasManager& manager = cloneAliasManager(); beginRemoveRows(QModelIndex(), index, index); manager.removeAt(index); endRemoveRows(); } - -Qt::ItemFlags AliasesModel::flags(const QModelIndex &index) const +Qt::ItemFlags AliasesModel::flags(const QModelIndex& index) const { if (!index.isValid()) { return Qt::ItemIsDropEnabled; @@ -237,12 +222,10 @@ Qt::ItemFlags AliasesModel::flags(const QModelIndex &index) const } } - QVariant AliasesModel::headerData(int section, Qt::Orientation orientation, int role) const { QStringList header; - header << tr("Alias") - << tr("Expansion"); + header << tr("Alias") << tr("Expansion"); if (orientation == Qt::Horizontal && role == Qt::DisplayRole) return header[section]; @@ -250,8 +233,7 @@ QVariant AliasesModel::headerData(int section, Qt::Orientation orientation, int return QVariant(); } - -QModelIndex AliasesModel::index(int row, int column, const QModelIndex &parent) const +QModelIndex AliasesModel::index(int row, int column, const QModelIndex& parent) const { Q_UNUSED(parent); if (row >= rowCount() || column >= columnCount()) @@ -260,8 +242,7 @@ QModelIndex AliasesModel::index(int row, int column, const QModelIndex &parent) return createIndex(row, column); } - -const AliasManager &AliasesModel::aliasManager() const +const AliasManager& AliasesModel::aliasManager() const { if (_configChanged) return _clonedAliasManager; @@ -269,8 +250,7 @@ const AliasManager &AliasesModel::aliasManager() const return *Client::aliasManager(); } - -AliasManager &AliasesModel::aliasManager() +AliasManager& AliasesModel::aliasManager() { if (_configChanged) return _clonedAliasManager; @@ -278,8 +258,7 @@ AliasManager &AliasesModel::aliasManager() return *Client::aliasManager(); } - -AliasManager &AliasesModel::cloneAliasManager() +AliasManager& AliasesModel::cloneAliasManager() { if (!_configChanged) { _clonedAliasManager = *Client::aliasManager(); @@ -289,7 +268,6 @@ AliasManager &AliasesModel::cloneAliasManager() return _clonedAliasManager; } - void AliasesModel::revert() { if (!_configChanged) @@ -301,7 +279,6 @@ void AliasesModel::revert() endResetModel(); } - void AliasesModel::commit() { if (!_configChanged) @@ -311,7 +288,6 @@ void AliasesModel::commit() revert(); } - void AliasesModel::initDone() { _modelReady = true; @@ -320,7 +296,6 @@ void AliasesModel::initDone() emit modelReady(true); } - void AliasesModel::clientConnected() { connect(Client::aliasManager(), &AliasManager::updated, this, &AliasesModel::revert); @@ -330,7 +305,6 @@ void AliasesModel::clientConnected() connect(Client::aliasManager(), &SyncableObject::initDone, this, &AliasesModel::initDone); } - void AliasesModel::clientDisconnected() { // clear