modernize: Pass arguments by value and move in constructors
[quassel.git] / src / qtui / settingspages / corehighlightsettingspage.cpp
index 9d2f155..9315f3f 100644 (file)
@@ -129,74 +129,153 @@ void CoreHighlightSettingsPage::setupRuleTable(QTableWidget *table) const
     table->verticalHeader()->hide();
     table->setShowGrid(false);
 
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn)->setToolTip(
-                tr("Enable/disable this rule"));
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn)->setWhatsThis(
-                table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn)->toolTip());
-
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn)->setToolTip(
-                tr("Phrase to match"));
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn)->setWhatsThis(
-                table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn)->toolTip());
-
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn)->setToolTip(
-                tr("<b>RegEx</b>: This option determines if the highlight rule, <i>Sender</i>, and "
-                   "<i>Channel</i> should be interpreted as <b>regular expressions</b> or just as "
-                   "keywords."));
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn)->setWhatsThis(
-                table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn)->toolTip());
-
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn)->setToolTip(
-                tr("<b>CS</b>: This option determines if the highlight rule, <i>Sender</i>, and "
-                   "<i>Channel</i> should be interpreted <b>case sensitive</b>."));
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn)->setWhatsThis(
-                table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn)->toolTip());
-
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn)->setToolTip(
-                tr("<p><b>Sender</b>: Semicolon separated list of <i>nick!ident@host</i> names, "
-                   "leave blank to match any nickname.</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>Alice!*; Bob!*@example.com; Carol*!*; !Caroline!*</i><br />"
-                   "would match on <i>Alice</i>, <i>Bob</i> with hostmask <i>example.com</i>, and "
-                   "any nickname starting with <i>Carol</i> except for <i>Caroline</i><br />"
-                   "<p>If only inverted names are specified, it will match anything except for "
-                   "what's specified (implicit wildcard).</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>!Announce*!*; !Wheatley!aperture@*</i><br />"
-                   "would match anything except for <i>Wheatley</i> with ident <i>aperture</i> or "
-                   "any nickname starting with <i>Announce</i></p>"));
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn)->setWhatsThis(
-                table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn)->toolTip());
-
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)->setToolTip(
-                tr("<p><b>Channel</b>: Semicolon separated list of channel names, leave blank to "
-                   "match any name.</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>#quassel*; #foobar; !#quasseldroid</i><br />"
-                   "would match on <i>#foobar</i> and any channel starting with <i>#quassel</i> "
-                   "except for <i>#quasseldroid</i><br />"
-                   "<p>If only inverted names are specified, it will match anything except for "
-                   "what's specified (implicit wildcard).</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>!#quassel*; !#foobar</i><br />"
-                   "would match anything except for <i>#foobar</i> or any channel starting with "
-                   "<i>#quassel</i></p>"));
-    table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)->setWhatsThis(
-                table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)->toolTip());
-
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
-    table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::EnableColumn, QHeaderView::ResizeToContents);
-    table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::NameColumn, QHeaderView::Stretch);
-    table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::RegExColumn, QHeaderView::ResizeToContents);
-    table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::CsColumn, QHeaderView::ResizeToContents);
-    table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::ChanColumn, QHeaderView::ResizeToContents);
-#else
+    setupTableTooltips(table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn),
+                       table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn),
+                       table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn),
+                       table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn),
+                       table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn),
+                       table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn));
+
     table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::EnableColumn, QHeaderView::ResizeToContents);
     table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::NameColumn, QHeaderView::Stretch);
     table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::RegExColumn, QHeaderView::ResizeToContents);
     table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::CsColumn, QHeaderView::ResizeToContents);
+    table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::SenderColumn, QHeaderView::ResizeToContents);
     table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::ChanColumn, QHeaderView::ResizeToContents);
-#endif
+}
+
+
+QString CoreHighlightSettingsPage::getTableTooltip(column tableColumn) const
+{
+    switch (tableColumn) {
+    case CoreHighlightSettingsPage::EnableColumn:
+        return tr("Enable/disable this rule");
+
+    case CoreHighlightSettingsPage::NameColumn:
+        return tr("Phrase to match, leave blank to match any message");
+
+    case CoreHighlightSettingsPage::RegExColumn:
+        return tr("<b>RegEx</b>: This option determines if the highlight rule, <i>Sender</i>, and "
+                  "<i>Channel</i> should be interpreted as <b>regular expressions</b> or just as "
+                  "keywords.");
+
+    case CoreHighlightSettingsPage::CsColumn:
+        return tr("<b>CS</b>: This option determines if the highlight rule, <i>Sender</i>, and "
+                  "<i>Channel</i> should be interpreted <b>case sensitive</b>.");
+
+    case CoreHighlightSettingsPage::SenderColumn:
+        return tr("<p><b>Sender</b>: Semicolon separated list of <i>nick!ident@host</i> names, "
+                  "leave blank to match any nickname.</p>"
+                  "<p><i>Example:</i><br />"
+                  "<i>Alice!*; Bob!*@example.com; Carol*!*; !Caroline!*</i><br />"
+                  "would match on <i>Alice</i>, <i>Bob</i> with hostmask <i>example.com</i>, and "
+                  "any nickname starting with <i>Carol</i> except for <i>Caroline</i><br />"
+                  "<p>If only inverted names are specified, it will match anything except for "
+                  "what's specified (implicit wildcard).</p>"
+                  "<p><i>Example:</i><br />"
+                  "<i>!Announce*!*; !Wheatley!aperture@*</i><br />"
+                  "would match anything except for <i>Wheatley</i> with ident <i>aperture</i> or "
+                  "any nickname starting with <i>Announce</i></p>");
+
+    case CoreHighlightSettingsPage::ChanColumn:
+        return tr("<p><b>Channel</b>: Semicolon separated list of channel/query names, leave blank "
+                  "to match any name.</p>"
+                  "<p><i>Example:</i><br />"
+                  "<i>#quassel*; #foobar; !#quasseldroid</i><br />"
+                  "would match on <i>#foobar</i> and any channel starting with <i>#quassel</i> "
+                  "except for <i>#quasseldroid</i><br />"
+                  "<p>If only inverted names are specified, it will match anything except for "
+                  "what's specified (implicit wildcard).</p>"
+                  "<p><i>Example:</i><br />"
+                  "<i>!#quassel*; !#foobar</i><br />"
+                  "would match anything except for <i>#foobar</i> or any channel starting with "
+                  "<i>#quassel</i></p>");
+
+    default:
+        // This shouldn't happen
+        return "Invalid column type in CoreHighlightSettingsPage::getTableTooltip()";
+    }
+}
+
+
+void CoreHighlightSettingsPage::setupTableTooltips(QWidget *enableWidget, QWidget *nameWidget,
+                                                   QWidget *regExWidget, QWidget *csWidget,
+                                                   QWidget *senderWidget, QWidget *chanWidget) const
+{
+    // Make sure everything's valid
+    Q_ASSERT(enableWidget);
+    Q_ASSERT(nameWidget);
+    Q_ASSERT(regExWidget);
+    Q_ASSERT(csWidget);
+    Q_ASSERT(senderWidget);
+    Q_ASSERT(chanWidget);
+
+    // Set tooltips and "What's this?" prompts
+    // Enabled
+    enableWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::EnableColumn));
+    enableWidget->setWhatsThis(enableWidget->toolTip());
+
+    // Name
+    nameWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::NameColumn));
+    nameWidget->setWhatsThis(nameWidget->toolTip());
+
+    // RegEx enabled
+    regExWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::RegExColumn));
+    regExWidget->setWhatsThis(regExWidget->toolTip());
+
+    // Case-sensitivity
+    csWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::CsColumn));
+    csWidget->setWhatsThis(csWidget->toolTip());
+
+    // Sender
+    senderWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::SenderColumn));
+    senderWidget->setWhatsThis(senderWidget->toolTip());
+
+    // Channel/buffer name
+    chanWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::ChanColumn));
+    chanWidget->setWhatsThis(chanWidget->toolTip());
+}
+
+
+void CoreHighlightSettingsPage::setupTableTooltips(QTableWidgetItem *enableWidget,
+                                                   QTableWidgetItem *nameWidget,
+                                                   QTableWidgetItem *regExWidget,
+                                                   QTableWidgetItem *csWidget,
+                                                   QTableWidgetItem *senderWidget,
+                                                   QTableWidgetItem *chanWidget) const
+{
+    // Make sure everything's valid
+    Q_ASSERT(enableWidget);
+    Q_ASSERT(nameWidget);
+    Q_ASSERT(regExWidget);
+    Q_ASSERT(csWidget);
+    Q_ASSERT(senderWidget);
+    Q_ASSERT(chanWidget);
+
+    // Set tooltips and "What's this?" prompts
+    // Enabled
+    enableWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::EnableColumn));
+    enableWidget->setWhatsThis(enableWidget->toolTip());
+
+    // Name
+    nameWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::NameColumn));
+    nameWidget->setWhatsThis(nameWidget->toolTip());
+
+    // RegEx enabled
+    regExWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::RegExColumn));
+    regExWidget->setWhatsThis(regExWidget->toolTip());
+
+    // Case-sensitivity
+    csWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::CsColumn));
+    csWidget->setWhatsThis(csWidget->toolTip());
+
+    // Sender
+    senderWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::SenderColumn));
+    senderWidget->setWhatsThis(senderWidget->toolTip());
+
+    // Channel/buffer name
+    chanWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::ChanColumn));
+    chanWidget->setWhatsThis(chanWidget->toolTip());
 }
 
 
@@ -287,41 +366,7 @@ void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, int id, const QS
 
     auto *chanNameItem = new QTableWidgetItem(chanName);
 
-    enableItem->setToolTip(tr("Enable/disable this rule"));
-    nameItem->setToolTip(tr("Phrase to match"));
-    regexItem->setToolTip(
-                tr("<b>RegEx</b>: This option determines if the highlight rule, <i>Sender</i>, and "
-                   "<i>Channel</i> should be interpreted as <b>regular expressions</b> or just as "
-                   "keywords."));
-    csItem->setToolTip(
-                tr("<b>CS</b>: This option determines if the highlight rule, <i>Sender</i>, and "
-                   "<i>Channel</i> should be interpreted <b>case sensitive</b>."));
-    senderItem->setToolTip(
-                tr("<p><b>Sender</b>: Semicolon separated list of <i>nick!ident@host</i> names, "
-                   "leave blank to match any nickname.</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>Alice!*; Bob!*@example.com; Carol*!*; !Caroline!*</i><br />"
-                   "would match on <i>Alice</i>, <i>Bob</i> with hostmask <i>example.com</i>, and "
-                   "any nickname starting with <i>Carol</i> except for <i>Caroline</i><br />"
-                   "<p>If only inverted names are specified, it will match anything except for "
-                   "what's specified (implicit wildcard).</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>!Announce*!*; !Wheatley!aperture@*</i><br />"
-                   "would match anything except for <i>Wheatley</i> with ident <i>aperture</i> or "
-                   "any nickname starting with <i>Announce</i></p>"));
-    chanNameItem->setToolTip(
-                tr("<p><b>Channel</b>: Semicolon separated list of channel names, leave blank to "
-                   "match any name.</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>#quassel*; #foobar; !#quasseldroid</i><br />"
-                   "would match on <i>#foobar</i> and any channel starting with <i>#quassel</i> "
-                   "except for <i>#quasseldroid</i><br />"
-                   "<p>If only inverted names are specified, it will match anything except for "
-                   "what's specified (implicit wildcard).</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>!#quassel*; !#foobar</i><br />"
-                   "would match anything except for <i>#foobar</i> or any channel starting with "
-                   "<i>#quassel</i></p>"));
+    setupTableTooltips(enableItem, nameItem, regexItem, csItem, senderItem, chanNameItem);
 
     int lastRow = ui.highlightTable->rowCount() - 1;
     ui.highlightTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem);
@@ -374,29 +419,7 @@ void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QStr
 
     auto *senderItem = new QTableWidgetItem(sender);
 
-    enableItem->setToolTip(tr("Enable/disable this rule"));
-    nameItem->setToolTip(tr("Phrase to match"));
-    regexItem->setToolTip(
-                tr("<b>RegEx</b>: This option determines if the highlight rule should be "
-                   "interpreted as a <b>regular expression</b> or just as a keyword."));
-    csItem->setToolTip(
-                tr("<b>CS</b>: This option determines if the highlight rule should be interpreted "
-                   "<b>case sensitive</b>."));
-    senderItem->setToolTip(
-                tr("<b>Sender</b>: This option specifies which sender nicknames match.  Leave "
-                   "blank to match any nickname."));
-    chanNameItem->setToolTip(
-                tr("<p><b>Channel</b>: Semicolon separated list of channel names.</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>#quassel*; #foobar; !#quasseldroid</i><br />"
-                   "would match on #foobar and any channel starting with <i>#quassel</i> except "
-                   "for <i>#quasseldroid</i><br />"
-                   "<p>If only inverted names are specified, it will match anything except for "
-                   "what's specified (implicit wildcard).</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>!#quassel*; !#foobar</i><br />"
-                   "would match anything except for #foobar or any channel starting with "
-                   "<i>#quassel</i></p>"));
+    setupTableTooltips(enableItem, nameItem, regexItem, csItem, senderItem, chanNameItem);
 
     int lastRow = ui.ignoredTable->rowCount() - 1;
     ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem);
@@ -515,28 +538,26 @@ void CoreHighlightSettingsPage::highlightTableChanged(QTableWidgetItem *item)
 
     switch (item->column()) {
         case CoreHighlightSettingsPage::EnableColumn:
-            highlightRule.isEnabled = (item->checkState() == Qt::Checked);
+            highlightRule.setIsEnabled(item->checkState() == Qt::Checked);
             break;
         case CoreHighlightSettingsPage::NameColumn:
-            if (item->text() == "")
-                item->setText(tr("this shouldn't be empty"));
-            highlightRule.name = item->text();
+            highlightRule.setContents(item->text());
             break;
         case CoreHighlightSettingsPage::RegExColumn:
-            highlightRule.isRegEx = (item->checkState() == Qt::Checked);
+            highlightRule.setIsRegEx(item->checkState() == Qt::Checked);
             break;
         case CoreHighlightSettingsPage::CsColumn:
-            highlightRule.isCaseSensitive = (item->checkState() == Qt::Checked);
+            highlightRule.setIsCaseSensitive(item->checkState() == Qt::Checked);
             break;
         case CoreHighlightSettingsPage::SenderColumn:
             if (!item->text().isEmpty() && item->text().trimmed().isEmpty())
                 item->setText("");
-            highlightRule.sender = item->text();
+            highlightRule.setSender(item->text());
             break;
         case CoreHighlightSettingsPage::ChanColumn:
             if (!item->text().isEmpty() && item->text().trimmed().isEmpty())
                 item->setText("");
-            highlightRule.chanName = item->text();
+            highlightRule.setChanName(item->text());
             break;
     }
     highlightList[item->row()] = highlightRule;
@@ -554,28 +575,26 @@ void CoreHighlightSettingsPage::ignoredTableChanged(QTableWidgetItem *item)
 
     switch (item->column()) {
         case CoreHighlightSettingsPage::EnableColumn:
-            ignoredRule.isEnabled = (item->checkState() == Qt::Checked);
+            ignoredRule.setIsEnabled(item->checkState() == Qt::Checked);
             break;
         case CoreHighlightSettingsPage::NameColumn:
-            if (item->text() == "")
-                item->setText(tr("this shouldn't be empty"));
-            ignoredRule.name = item->text();
+            ignoredRule.setContents(item->text());
             break;
         case CoreHighlightSettingsPage::RegExColumn:
-            ignoredRule.isRegEx = (item->checkState() == Qt::Checked);
+            ignoredRule.setIsRegEx(item->checkState() == Qt::Checked);
             break;
         case CoreHighlightSettingsPage::CsColumn:
-            ignoredRule.isCaseSensitive = (item->checkState() == Qt::Checked);
+            ignoredRule.setIsCaseSensitive(item->checkState() == Qt::Checked);
             break;
         case CoreHighlightSettingsPage::SenderColumn:
             if (!item->text().isEmpty() && item->text().trimmed().isEmpty())
                 item->setText("");
-            ignoredRule.sender = item->text();
+            ignoredRule.setSender(item->text());
             break;
         case CoreHighlightSettingsPage::ChanColumn:
             if (!item->text().isEmpty() && item->text().trimmed().isEmpty())
                 item->setText("");
-            ignoredRule.chanName = item->text();
+            ignoredRule.setChanName(item->text());
             break;
     }
     ignoredList[item->row()] = ignoredRule;
@@ -591,18 +610,13 @@ void CoreHighlightSettingsPage::load()
     auto ruleManager = Client::highlightRuleManager();
     if (ruleManager) {
         for (auto &rule : ruleManager->highlightRuleList()) {
-            if (rule.isInverse) {
-                addNewIgnoredRow(rule.isEnabled,
-                                 rule.id,
-                                 rule.name,
-                                 rule.isRegEx,
-                                 rule.isCaseSensitive,
-                                 rule.sender,
-                                 rule.chanName);
+            if (rule.isInverse()) {
+                addNewIgnoredRow(rule.isEnabled(), rule.id(), rule.contents(), rule.isRegEx(),
+                                 rule.isCaseSensitive(), rule.sender(), rule.chanName());
             }
             else {
-                addNewHighlightRow(rule.isEnabled, rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.sender,
-                                   rule.chanName);
+                addNewHighlightRow(rule.isEnabled(), rule.id(), rule.contents(), rule.isRegEx(),
+                                   rule.isCaseSensitive(), rule.sender(), rule.chanName());
             }
         }
 
@@ -637,13 +651,15 @@ void CoreHighlightSettingsPage::save()
     clonedManager.clear();
 
     for (auto &rule : highlightList) {
-        clonedManager.addHighlightRule(rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, false,
-                                       rule.sender, rule.chanName);
+        clonedManager.addHighlightRule(rule.id(), rule.contents(), rule.isRegEx(),
+                                       rule.isCaseSensitive(), rule.isEnabled(), false,
+                                       rule.sender(), rule.chanName());
     }
 
     for (auto &rule : ignoredList) {
-        clonedManager.addHighlightRule(rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, true,
-                                       rule.sender, rule.chanName);
+        clonedManager.addHighlightRule(rule.id(), rule.contents(), rule.isRegEx(),
+                                       rule.isCaseSensitive (), rule.isEnabled(), true,
+                                       rule.sender(), rule.chanName());
     }
 
     auto highlightNickType = ui.highlightNicksComboBox->itemData(ui.highlightNicksComboBox->currentIndex()).value<int>();
@@ -661,13 +677,13 @@ int CoreHighlightSettingsPage::nextId()
 {
     int max = 0;
     for (int i = 0; i < highlightList.count(); i++) {
-        int id = highlightList[i].id;
+        int id = highlightList[i].id();
         if (id > max) {
             max = id;
         }
     }
     for (int i = 0; i < ignoredList.count(); i++) {
-        int id = ignoredList[i].id;
+        int id = ignoredList[i].id();
         if (id > max) {
             max = id;
         }