/*************************************************************************************************** * Copyright 2023-2024 x-tools-author(x-tools@outlook.com). All rights reserved. * * The file is encoded using "utf8 with bom", it is a part of xTools project. * * xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source * code directory. **************************************************************************************************/ #include "xToolsPrestorerToolUi.h" #include #include #include #include #include #include #include "xToolsMenu.h" #include "xToolsPrestorerTool.h" #include "xToolsPrestorerToolUiEditor.h" #include "xToolsApplication.h" xToolsPrestorerToolUi::xToolsPrestorerToolUi(QWidget *parent) : xToolsTableModelToolUi(parent) { mEditor = new xToolsPrestorerToolUiEditor(xToolsApplication::mainWindow()); mMenu = new xToolsMenu(); } xToolsPrestorerToolUi::~xToolsPrestorerToolUi() {} QMenu *xToolsPrestorerToolUi::menu() { return mMenu; } void xToolsPrestorerToolUi::onBaseToolUiInitialized(xToolsBaseTool *tool, const QString &settingGroup) { xToolsTableModelToolUi::onBaseToolUiInitialized(tool, settingGroup); QList columns; columns << 9; setStretchSections(columns); xToolsPrestorerTool *cookedTool = qobject_cast(tool); auto *model = cookedTool->tableModel().value(); connect(model, &QAbstractTableModel::rowsRemoved, this, &xToolsPrestorerToolUi::updateMenu); connect(model, &QAbstractTableModel::rowsInserted, this, &xToolsPrestorerToolUi::updateMenu); connect(model, &QAbstractTableModel::dataChanged, this, &xToolsPrestorerToolUi::updateMenu); updateMenu(); QList list; list << 10; setStretchSections(list); } QList xToolsPrestorerToolUi::defaultHideColumns() { QList list; auto tb = mTableModelTool->tableModel().value(); for (int i = 0; i < tb->columnCount(); i++) { list.append(i); } list.removeAll(0); list.removeAll(1); list.removeAll(2); list.removeAll(3); list.removeAll(4); list.removeAll(10); return list; } void xToolsPrestorerToolUi::afterRowEdited(int row) { xToolsTableModelToolUi::afterRowEdited(row); updateMenu(); } QDialog *xToolsPrestorerToolUi::itemEditor() { return mEditor; } void xToolsPrestorerToolUi::updateMenu() { auto *cookedTool = qobject_cast(mTableModelTool); auto *model = cookedTool->tableModel().value(); mMenu->clear(); for (int i = 0; i < model->rowCount(); i++) { QString desc = cookedTool->description(i); QAction *a = new QAction(desc, mMenu); mMenu->addAction(a); connect(a, &QAction::triggered, this, [=]() { cookedTool->send(i); }); } }