This commit is contained in:
fourtf 2020-02-20 23:37:46 +01:00
parent d6c3c99605
commit 4a69095d5f
4 changed files with 21 additions and 17 deletions

View file

@ -205,9 +205,7 @@ public:
assert(row >= 0 && row < this->rows_.size() && column >= 0 && assert(row >= 0 && row < this->rows_.size() && column >= 0 &&
column < this->columnCount_); column < this->columnCount_);
return this->rows_[row].items[column]->flags() | return this->rows_[row].items[column]->flags();
Qt::ItemFlag::ItemIsDragEnabled |
Qt::ItemFlag::ItemIsDropEnabled;
} }
QStandardItem *getItem(int row, int column) QStandardItem *getItem(int row, int column)

View file

@ -1,5 +1,7 @@
#include "CommandModel.hpp" #include "CommandModel.hpp"
#include "util/StandardItemHelper.hpp"
namespace chatterino { namespace chatterino {
// commandmodel // commandmodel
@ -20,12 +22,8 @@ Command CommandModel::getItemFromRow(std::vector<QStandardItem *> &row,
void CommandModel::getRowFromItem(const Command &item, void CommandModel::getRowFromItem(const Command &item,
std::vector<QStandardItem *> &row) std::vector<QStandardItem *> &row)
{ {
row[0]->setData(item.name, Qt::DisplayRole); setStringItem(row[0], item.name);
row[0]->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | setStringItem(row[1], item.func);
Qt::ItemIsEditable);
row[1]->setData(item.func, Qt::DisplayRole);
row[1]->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable |
Qt::ItemIsEditable);
} }
} // namespace chatterino } // namespace chatterino

View file

@ -4,12 +4,20 @@
namespace chatterino { 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, static void setBoolItem(QStandardItem *item, bool value,
bool userCheckable = true, bool selectable = true) bool userCheckable = true, bool selectable = true)
{ {
item->setFlags(Qt::ItemFlags( item->setFlags(
Qt::ItemIsEnabled | (selectable ? Qt::ItemIsSelectable : 0) | Qt::ItemFlags(defaultItemFlags(selectable) |
(userCheckable ? Qt::ItemIsUserCheckable : 0))); (userCheckable ? Qt::ItemIsUserCheckable : 0)));
item->setCheckState(value ? Qt::Checked : Qt::Unchecked); 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) bool editable = true, bool selectable = true)
{ {
item->setData(value, Qt::EditRole); item->setData(value, Qt::EditRole);
item->setFlags(Qt::ItemFlags(Qt::ItemIsEnabled | item->setFlags(Qt::ItemFlags(defaultItemFlags(selectable) |
(selectable ? Qt::ItemIsSelectable : 0) |
(editable ? (Qt::ItemIsEditable) : 0))); (editable ? (Qt::ItemIsEditable) : 0)));
} }
@ -28,7 +35,7 @@ static void setFilePathItem(QStandardItem *item, const QUrl &value,
item->setData(value, Qt::UserRole); item->setData(value, Qt::UserRole);
item->setData(value.fileName(), Qt::DisplayRole); item->setData(value.fileName(), Qt::DisplayRole);
item->setFlags( item->setFlags(
Qt::ItemFlags(Qt::ItemIsEnabled | Qt::ItemFlags(defaultItemFlags(selectable) |
(selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags))); (selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags)));
} }
@ -37,14 +44,14 @@ static void setColorItem(QStandardItem *item, const QColor &value,
{ {
item->setData(value, Qt::DecorationRole); item->setData(value, Qt::DecorationRole);
item->setFlags( item->setFlags(
Qt::ItemFlags(Qt::ItemIsEnabled | Qt::ItemFlags(defaultItemFlags(selectable) |
(selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags))); (selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags)));
} }
static QStandardItem *emptyItem() static QStandardItem *emptyItem()
{ {
auto *item = new QStandardItem(); auto *item = new QStandardItem();
item->setFlags(Qt::ItemFlags(0)); item->setFlags(Qt::ItemFlags());
return item; return item;
} }

View file

@ -51,6 +51,7 @@ CommandPage::CommandPage()
Command{"/command", "I made a new command HeyGuys"}); Command{"/command", "I made a new command HeyGuys"});
}); });
// TODO: asyncronously check path
if (QFile(c1settingsPath()).exists()) if (QFile(c1settingsPath()).exists())
{ {
auto button = new QPushButton("Import commands from Chatterino 1"); auto button = new QPushButton("Import commands from Chatterino 1");