From cdd949efd81e85445b034ae869e48203340c5fea Mon Sep 17 00:00:00 2001 From: Auro <35087590+MrAuro@users.noreply.github.com> Date: Sat, 25 Jun 2022 05:14:19 -0400 Subject: [PATCH] Moved highlight row index numbers to enum (#3829) Co-authored-by: pajlada --- src/controllers/highlights/HighlightModel.cpp | 63 ++++++++++--------- src/controllers/highlights/HighlightModel.hpp | 8 ++- .../settingspages/HighlightingPage.cpp | 3 +- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/controllers/highlights/HighlightModel.cpp b/src/controllers/highlights/HighlightModel.cpp index de945a75..f1473a26 100644 --- a/src/controllers/highlights/HighlightModel.cpp +++ b/src/controllers/highlights/HighlightModel.cpp @@ -74,7 +74,7 @@ void HighlightModel::afterInit() auto selfColor = ColorProvider::instance().color(ColorType::SelfHighlight); setColorItem(usernameRow[Column::Color], *selfColor, false); - this->insertCustomRow(usernameRow, {}); + this->insertCustomRow(usernameRow, HighlightRowIndexes::SelfHighlightRow); // Highlight settings for whispers std::vector whisperRow = this->createRow(); @@ -99,7 +99,7 @@ void HighlightModel::afterInit() // setColorItem(whisperRow[Column::Color], *whisperColor, false); whisperRow[Column::Color]->setFlags(Qt::ItemFlag::NoItemFlags); - this->insertCustomRow(whisperRow, WHISPER_ROW); + this->insertCustomRow(whisperRow, HighlightRowIndexes::WhisperRow); // Highlight settings for subscription messages std::vector subRow = this->createRow(); @@ -121,7 +121,7 @@ void HighlightModel::afterInit() auto subColor = ColorProvider::instance().color(ColorType::Subscription); setColorItem(subRow[Column::Color], *subColor, false); - this->insertCustomRow(subRow, 2); + this->insertCustomRow(subRow, HighlightRowIndexes::SubRow); // Highlight settings for redeemed highlight messages std::vector redeemedRow = this->createRow(); @@ -149,7 +149,7 @@ void HighlightModel::afterInit() ColorProvider::instance().color(ColorType::RedeemedHighlight); setColorItem(redeemedRow[Column::Color], *RedeemedColor, false); - this->insertCustomRow(redeemedRow, 3); + this->insertCustomRow(redeemedRow, HighlightRowIndexes::RedeemedRow); // Highlight settings for first messages std::vector firstMessageRow = this->createRow(); @@ -179,7 +179,8 @@ void HighlightModel::afterInit() ColorProvider::instance().color(ColorType::FirstMessageHighlight); setColorItem(firstMessageRow[Column::Color], *FirstMessageColor, false); - this->insertCustomRow(firstMessageRow, 4); + this->insertCustomRow(firstMessageRow, + HighlightRowIndexes::FirstMessageRow); } void HighlightModel::customRowSetData(const std::vector &row, @@ -191,25 +192,25 @@ void HighlightModel::customRowSetData(const std::vector &row, case Column::Pattern: { if (role == Qt::CheckStateRole) { - if (rowIndex == 0) + if (rowIndex == HighlightRowIndexes::SelfHighlightRow) { getSettings()->enableSelfHighlight.setValue(value.toBool()); } - else if (rowIndex == WHISPER_ROW) + else if (rowIndex == HighlightRowIndexes::WhisperRow) { getSettings()->enableWhisperHighlight.setValue( value.toBool()); } - else if (rowIndex == 2) + else if (rowIndex == HighlightRowIndexes::SubRow) { getSettings()->enableSubHighlight.setValue(value.toBool()); } - else if (rowIndex == 3) + else if (rowIndex == HighlightRowIndexes::RedeemedRow) { getSettings()->enableRedeemedHighlight.setValue( value.toBool()); } - else if (rowIndex == 4) + else if (rowIndex == HighlightRowIndexes::FirstMessageRow) { getSettings()->enableFirstMessageHighlight.setValue( value.toBool()); @@ -220,7 +221,7 @@ void HighlightModel::customRowSetData(const std::vector &row, case Column::ShowInMentions: { if (role == Qt::CheckStateRole) { - if (rowIndex == 0) + if (rowIndex == HighlightRowIndexes::SelfHighlightRow) { getSettings()->showSelfHighlightInMentions.setValue( value.toBool()); @@ -231,27 +232,27 @@ void HighlightModel::customRowSetData(const std::vector &row, case Column::FlashTaskbar: { if (role == Qt::CheckStateRole) { - if (rowIndex == 0) + if (rowIndex == HighlightRowIndexes::SelfHighlightRow) { getSettings()->enableSelfHighlightTaskbar.setValue( value.toBool()); } - else if (rowIndex == WHISPER_ROW) + else if (rowIndex == HighlightRowIndexes::WhisperRow) { getSettings()->enableWhisperHighlightTaskbar.setValue( value.toBool()); } - else if (rowIndex == 2) + else if (rowIndex == HighlightRowIndexes::SubRow) { getSettings()->enableSubHighlightTaskbar.setValue( value.toBool()); } - else if (rowIndex == 3) + else if (rowIndex == HighlightRowIndexes::RedeemedRow) { // getSettings()->enableRedeemedHighlightTaskbar.setValue( // value.toBool()); } - else if (rowIndex == 4) + else if (rowIndex == HighlightRowIndexes::FirstMessageRow) { // getSettings()->enableFirstMessageHighlightTaskbar.setValue( // value.toBool()); @@ -262,27 +263,27 @@ void HighlightModel::customRowSetData(const std::vector &row, case Column::PlaySound: { if (role == Qt::CheckStateRole) { - if (rowIndex == 0) + if (rowIndex == HighlightRowIndexes::SelfHighlightRow) { getSettings()->enableSelfHighlightSound.setValue( value.toBool()); } - else if (rowIndex == WHISPER_ROW) + else if (rowIndex == HighlightRowIndexes::WhisperRow) { getSettings()->enableWhisperHighlightSound.setValue( value.toBool()); } - else if (rowIndex == 2) + else if (rowIndex == HighlightRowIndexes::SubRow) { getSettings()->enableSubHighlightSound.setValue( value.toBool()); } - else if (rowIndex == 3) + else if (rowIndex == HighlightRowIndexes::RedeemedRow) { // getSettings()->enableRedeemedHighlightSound.setValue( // value.toBool()); } - else if (rowIndex == 4) + else if (rowIndex == HighlightRowIndexes::FirstMessageRow) { // getSettings()->enableFirstMessageHighlightSound.setValue( // value.toBool()); @@ -302,27 +303,27 @@ void HighlightModel::customRowSetData(const std::vector &row, // Custom sound file if (role == Qt::UserRole) { - if (rowIndex == 0) + if (rowIndex == HighlightRowIndexes::SelfHighlightRow) { getSettings()->selfHighlightSoundUrl.setValue( value.toString()); } - else if (rowIndex == WHISPER_ROW) + else if (rowIndex == HighlightRowIndexes::WhisperRow) { getSettings()->whisperHighlightSoundUrl.setValue( value.toString()); } - else if (rowIndex == 2) + else if (rowIndex == HighlightRowIndexes::SubRow) { getSettings()->subHighlightSoundUrl.setValue( value.toString()); } - else if (rowIndex == 3) + else if (rowIndex == HighlightRowIndexes::RedeemedRow) { getSettings()->redeemedHighlightSoundUrl.setValue( value.toString()); } - else if (rowIndex == 4) + else if (rowIndex == HighlightRowIndexes::FirstMessageRow) { getSettings()->firstMessageHighlightSoundUrl.setValue( value.toString()); @@ -335,26 +336,26 @@ void HighlightModel::customRowSetData(const std::vector &row, if (role == Qt::DecorationRole) { auto colorName = value.value().name(QColor::HexArgb); - if (rowIndex == 0) + if (rowIndex == HighlightRowIndexes::SelfHighlightRow) { getSettings()->selfHighlightColor.setValue(colorName); } - // else if (rowIndex == WHISPER_ROW) + // else if (rowIndex == HighlightRowIndexes::WhisperRow) // { // getSettings()->whisperHighlightColor.setValue(colorName); // } - else if (rowIndex == 2) + else if (rowIndex == HighlightRowIndexes::SubRow) { getSettings()->subHighlightColor.setValue(colorName); } - else if (rowIndex == 3) + else if (rowIndex == HighlightRowIndexes::RedeemedRow) { getSettings()->redeemedHighlightColor.setValue(colorName); const_cast(ColorProvider::instance()) .updateColor(ColorType::RedeemedHighlight, QColor(colorName)); } - else if (rowIndex == 4) + else if (rowIndex == HighlightRowIndexes::FirstMessageRow) { getSettings()->firstMessageHighlightColor.setValue( colorName); diff --git a/src/controllers/highlights/HighlightModel.hpp b/src/controllers/highlights/HighlightModel.hpp index e57a4bdd..a5bbebc9 100644 --- a/src/controllers/highlights/HighlightModel.hpp +++ b/src/controllers/highlights/HighlightModel.hpp @@ -25,7 +25,13 @@ public: COUNT // keep this as last member of enum }; - constexpr static int WHISPER_ROW = 1; + enum HighlightRowIndexes { + SelfHighlightRow = 0, + WhisperRow = 1, + SubRow = 2, + RedeemedRow = 3, + FirstMessageRow = 4, + }; protected: // turn a vector item into a model row diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index a124f5ff..d75a247a 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -353,7 +353,8 @@ void HighlightingPage::tableCellClicked(const QModelIndex &clicked, using Column = HighlightModel::Column; bool restrictColorRow = (tab == HighlightTab::Messages && - clicked.row() == HighlightModel::WHISPER_ROW); + clicked.row() == + HighlightModel::HighlightRowIndexes::WhisperRow); if (clicked.column() == Column::SoundPath) { this->openSoundDialog(clicked, view, Column::SoundPath);