diff --git a/src/common/SignalVectorModel.hpp b/src/common/SignalVectorModel.hpp index bacb6c4df..bb7cd7c05 100644 --- a/src/common/SignalVectorModel.hpp +++ b/src/common/SignalVectorModel.hpp @@ -205,9 +205,7 @@ public: assert(row >= 0 && row < this->rows_.size() && column >= 0 && column < this->columnCount_); - return this->rows_[row].items[column]->flags() | - Qt::ItemFlag::ItemIsDragEnabled | - Qt::ItemFlag::ItemIsDropEnabled; + return this->rows_[row].items[column]->flags(); } QStandardItem *getItem(int row, int column) diff --git a/src/controllers/commands/CommandModel.cpp b/src/controllers/commands/CommandModel.cpp index 4a55907d0..d12a81c69 100644 --- a/src/controllers/commands/CommandModel.cpp +++ b/src/controllers/commands/CommandModel.cpp @@ -1,5 +1,7 @@ #include "CommandModel.hpp" +#include "util/StandardItemHelper.hpp" + namespace chatterino { // commandmodel @@ -20,12 +22,8 @@ Command CommandModel::getItemFromRow(std::vector &row, void CommandModel::getRowFromItem(const Command &item, std::vector &row) { - row[0]->setData(item.name, Qt::DisplayRole); - row[0]->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | - Qt::ItemIsEditable); - row[1]->setData(item.func, Qt::DisplayRole); - row[1]->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | - Qt::ItemIsEditable); + setStringItem(row[0], item.name); + setStringItem(row[1], item.func); } } // namespace chatterino diff --git a/src/util/StandardItemHelper.hpp b/src/util/StandardItemHelper.hpp index 47e4db14b..f9caeb0a6 100644 --- a/src/util/StandardItemHelper.hpp +++ b/src/util/StandardItemHelper.hpp @@ -4,12 +4,20 @@ namespace chatterino { +static auto defaultItemFlags(bool selectable) +{ + return Qt::ItemIsEnabled | + (selectable ? Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | + Qt::ItemIsDropEnabled + : Qt::ItemFlag()); +} + static void setBoolItem(QStandardItem *item, bool value, bool userCheckable = true, bool selectable = true) { - item->setFlags(Qt::ItemFlags( - Qt::ItemIsEnabled | (selectable ? Qt::ItemIsSelectable : 0) | - (userCheckable ? Qt::ItemIsUserCheckable : 0))); + item->setFlags( + Qt::ItemFlags(defaultItemFlags(selectable) | + (userCheckable ? Qt::ItemIsUserCheckable : 0))); item->setCheckState(value ? Qt::Checked : Qt::Unchecked); } @@ -17,8 +25,7 @@ static void setStringItem(QStandardItem *item, const QString &value, bool editable = true, bool selectable = true) { item->setData(value, Qt::EditRole); - item->setFlags(Qt::ItemFlags(Qt::ItemIsEnabled | - (selectable ? Qt::ItemIsSelectable : 0) | + item->setFlags(Qt::ItemFlags(defaultItemFlags(selectable) | (editable ? (Qt::ItemIsEditable) : 0))); } @@ -28,7 +35,7 @@ static void setFilePathItem(QStandardItem *item, const QUrl &value, item->setData(value, Qt::UserRole); item->setData(value.fileName(), Qt::DisplayRole); item->setFlags( - Qt::ItemFlags(Qt::ItemIsEnabled | + Qt::ItemFlags(defaultItemFlags(selectable) | (selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags))); } @@ -37,14 +44,14 @@ static void setColorItem(QStandardItem *item, const QColor &value, { item->setData(value, Qt::DecorationRole); item->setFlags( - Qt::ItemFlags(Qt::ItemIsEnabled | + Qt::ItemFlags(defaultItemFlags(selectable) | (selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags))); } static QStandardItem *emptyItem() { auto *item = new QStandardItem(); - item->setFlags(Qt::ItemFlags(0)); + item->setFlags(Qt::ItemFlags()); return item; } diff --git a/src/widgets/settingspages/CommandPage.cpp b/src/widgets/settingspages/CommandPage.cpp index 6df83105d..c3470c4b1 100644 --- a/src/widgets/settingspages/CommandPage.cpp +++ b/src/widgets/settingspages/CommandPage.cpp @@ -51,6 +51,7 @@ CommandPage::CommandPage() Command{"/command", "I made a new command HeyGuys"}); }); + // TODO: asyncronously check path if (QFile(c1settingsPath()).exists()) { auto button = new QPushButton("Import commands from Chatterino 1");