mirror of
https://github.com/august-alt/gpui.git
synced 2025-03-13 08:58:39 +03:00
chore: add qstandartitem model in scriptscontentwidget
This commit is contained in:
parent
12c5599672
commit
5111883b90
@ -35,7 +35,7 @@ namespace scripts_plugin
|
||||
{
|
||||
ScriptsContentWidget::ScriptsContentWidget(ScriptsSnapIn *sn, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, model(std::make_unique<QStringListModel>())
|
||||
, model(std::make_unique<QStandardItemModel>())
|
||||
, ui(new Ui::ScriptsContentWidget())
|
||||
, snapIn(sn)
|
||||
{
|
||||
@ -58,7 +58,7 @@ void ScriptsContentWidget::setNamespace(bool machineNamespace)
|
||||
|
||||
void ScriptsContentWidget::buildModel()
|
||||
{
|
||||
model = std::make_unique<QStringListModel>();
|
||||
model = std::make_unique<QStandardItemModel>();
|
||||
|
||||
QString startupItem = "Logon";
|
||||
QString shutdownItem = "Logoff";
|
||||
@ -69,9 +69,16 @@ void ScriptsContentWidget::buildModel()
|
||||
shutdownItem = "Shutdown";
|
||||
}
|
||||
|
||||
QStringList list;
|
||||
list << startupItem << shutdownItem;
|
||||
model.get()->setStringList(list);
|
||||
QStandardItem *first = new QStandardItem();
|
||||
QStandardItem *second = new QStandardItem();
|
||||
|
||||
first->setData(QVariant(startupItem), Qt::DisplayRole);
|
||||
second->setData(QVariant(shutdownItem), Qt::DisplayRole);
|
||||
first->setData(QVariant(true));
|
||||
second->setData(QVariant(false));
|
||||
|
||||
model.get()->appendRow(first);
|
||||
model.get()->appendRow(second);
|
||||
|
||||
ui->listView->setModel(model.get());
|
||||
|
||||
@ -85,9 +92,9 @@ void ScriptsContentWidget::startDialog(QItemSelection item)
|
||||
{
|
||||
if (!item.indexes().isEmpty())
|
||||
{
|
||||
auto displayName = model.get()->data(item.indexes().first()).toString();
|
||||
auto isStartupItem = model.get()->data(item.indexes().first(), isStartupRole);
|
||||
|
||||
if ((displayName.compare("Logon") == 0) || (displayName.compare("Startup") == 0))
|
||||
if (isStartupItem.toBool())
|
||||
{
|
||||
isStartupScripts = true;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ private:
|
||||
void buildModel();
|
||||
|
||||
private:
|
||||
std::unique_ptr<QStringListModel> model = nullptr;
|
||||
std::unique_ptr<QStandardItemModel> model = nullptr;
|
||||
|
||||
Ui::ScriptsContentWidget *ui{nullptr};
|
||||
|
||||
@ -76,6 +76,8 @@ private:
|
||||
bool isStartupScripts = false;
|
||||
|
||||
ScriptsSnapIn *snapIn;
|
||||
|
||||
static inline int isStartupRole = Qt::UserRole + 1;
|
||||
};
|
||||
|
||||
} // namespace scripts_plugin
|
||||
|
Loading…
x
Reference in New Issue
Block a user