mirror-chatterino2/src/util/StandardItemHelper.hpp

52 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
#include <QStandardItem>
namespace chatterino {
static void setBoolItem(QStandardItem *item, bool value,
bool userCheckable = true, bool selectable = true)
{
2019-09-18 13:03:16 +02:00
item->setFlags(Qt::ItemFlags(
Qt::ItemIsEnabled | (selectable ? Qt::ItemIsSelectable : 0) |
(userCheckable ? Qt::ItemIsUserCheckable : 0)));
item->setCheckState(value ? Qt::Checked : Qt::Unchecked);
}
static void setStringItem(QStandardItem *item, const QString &value,
bool editable = true, bool selectable = true)
{
item->setData(value, Qt::EditRole);
2019-09-18 13:03:16 +02:00
item->setFlags(Qt::ItemFlags(Qt::ItemIsEnabled |
(selectable ? Qt::ItemIsSelectable : 0) |
(editable ? (Qt::ItemIsEditable) : 0)));
}
static void setFilePathItem(QStandardItem *item, const QUrl &value,
bool selectable = true)
{
item->setData(value, Qt::UserRole);
item->setData(value.fileName(), Qt::DisplayRole);
item->setFlags(
Qt::ItemFlags(Qt::ItemIsEnabled |
(selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags)));
}
static void setColorItem(QStandardItem *item, const QColor &value,
bool selectable = true)
{
item->setData(value, Qt::DecorationRole);
item->setFlags(
Qt::ItemFlags(Qt::ItemIsEnabled |
(selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags)));
}
static QStandardItem *emptyItem()
{
auto *item = new QStandardItem();
2019-09-18 13:03:16 +02:00
item->setFlags(Qt::ItemFlags(0));
return item;
}
} // namespace chatterino