| 40 | }; |
| 41 | } |
| 42 | ScriptPage::ScriptPage(QWidget *parent) : SettingPage(parent) |
| 43 | { |
| 44 | ScriptModel *model = new ScriptModel(this); |
| 45 | ScriptProxyModel *proxyModel = new ScriptProxyModel(this); |
| 46 | proxyModel->setSourceModel(model); |
| 47 | ScriptItemDelegate *delegate = new ScriptItemDelegate(this); |
| 48 | |
| 49 | QTreeView *scriptView=new ScriptView(this); |
| 50 | scriptView->setRootIsDecorated(false); |
| 51 | scriptView->setSelectionMode(QAbstractItemView::SingleSelection); |
| 52 | scriptView->setModel(proxyModel); |
| 53 | scriptView->setFont(QFont(GlobalObjects::normalFont, 11)); |
| 54 | scriptView->header()->setFont(QFont(GlobalObjects::normalFont, 12)); |
| 55 | scriptView->setAlternatingRowColors(true); |
| 56 | scriptView->setItemDelegate(delegate); |
| 57 | new FloatScrollBar(scriptView->verticalScrollBar(), scriptView); |
| 58 | scriptView->hideColumn((int)ScriptModel::Columns::ID); |
| 59 | scriptView->setMouseTracking(true); |
| 60 | |
| 61 | |
| 62 | QComboBox *typeCombo = new ElaComboBox(this); |
| 63 | typeCombo->addItems(model->scriptTypes); |
| 64 | typeCombo->addItem(tr("All")); |
| 65 | typeCombo->setCurrentIndex(model->scriptTypes.size()); |
| 66 | QObject::connect(typeCombo,(void (QComboBox:: *)(int))&QComboBox::currentIndexChanged, this, [=](int index){ |
| 67 | if(index == model->scriptTypes.size()) proxyModel->setType(-1); |
| 68 | else proxyModel->setType(index); |
| 69 | }); |
| 70 | |
| 71 | QObject::connect(delegate, &ScriptItemDelegate::settingClicked, this, [=](const QModelIndex &index){ |
| 72 | auto sindex = proxyModel->mapToSource(index).siblingAtColumn((int)ScriptModel::Columns::ID); |
| 73 | auto s = GlobalObjects::scriptManager->getScript(sindex.data().toString()); |
| 74 | ScriptSettingDialog dialog(s, this); |
| 75 | if (QDialog::Accepted==dialog.exec()) |
| 76 | { |
| 77 | for(auto iter = dialog.changedItems.begin(); iter!=dialog.changedItems.end();++iter) |
| 78 | { |
| 79 | s->setOption(iter.key(), iter.value()); |
| 80 | } |
| 81 | } |
| 82 | }); |
| 83 | QObject::connect(scriptView, &QTreeView::doubleClicked,[=](const QModelIndex &sindex){ |
| 84 | if(!sindex.isValid()) return; |
| 85 | auto index = proxyModel->mapToSource(sindex).siblingAtColumn((int)ScriptModel::Columns::ID); |
| 86 | auto s = GlobalObjects::scriptManager->getScript(index.data().toString()); |
| 87 | if(s->settings().size()==0) return; |
| 88 | ScriptSettingDialog dialog(s, this); |
| 89 | if(QDialog::Accepted==dialog.exec()) |
| 90 | { |
| 91 | for(auto iter = dialog.changedItems.begin(); iter!=dialog.changedItems.end();++iter) |
| 92 | { |
| 93 | s->setOption(iter.key(), iter.value()); |
| 94 | } |
| 95 | } |
| 96 | }); |
| 97 | QAction *actRemove = new QAction(tr("Remove"), this); |
| 98 | QObject::connect(actRemove, &QAction::triggered, this, [=](){ |
| 99 | auto selection = scriptView->selectionModel()->selectedRows((int)ScriptModel::Columns::ID); |
nothing calls this directly
no test coverage detected