diff --git a/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp b/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp index 530503a3..61ebee51 100644 --- a/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp @@ -51,7 +51,7 @@ ToolsGeneralWidget::ToolsGeneralWidget(const QString &name, const QString &group QItemSelectionModel *m=ui->lstTools->selectionModel(); ui->lstTools->setModel(&mToolsModel); delete m; - mEditType = EditType::None; + mCurrentEditingRow = -1; showEditPanel(false); connect(ui->lstTools->selectionModel(), &QItemSelectionModel::currentRowChanged, this,&ToolsGeneralWidget::onToolsCurrentChanged); @@ -94,9 +94,11 @@ void ToolsGeneralWidget::onToolsCurrentChanged(const QModelIndex ¤t, const void ToolsGeneralWidget::finishEditing(bool askSave, const QModelIndex& itemIndex) { auto action = finally([this]{ + mEdited = false; + mCurrentEditingRow = -1; showEditPanel(false); }); - if (mEditType == EditType::None) + if (mCurrentEditingRow == -1) return; if (!mEdited) return; @@ -113,19 +115,13 @@ void ToolsGeneralWidget::finishEditing(bool askSave, const QModelIndex& itemInde tr("Title shouldn't be empty!")); return; } - mEditType = EditType::None; - QModelIndex index=itemIndex.isValid()?itemIndex:ui->lstTools->currentIndex(); - if (!index.isValid()) - return; - - PToolItem item = mToolsModel.getTool(index.row()); + PToolItem item = mToolsModel.getTool(mCurrentEditingRow); item->workingDirectory = ui->txtDirectory->text(); item->parameters = ui->txtParameters->text(); item->program = ui->txtProgram->text(); item->title = ui->txtTitle->text(); item->inputOrigin = static_cast(ui->cbInput->currentIndex()); item->outputTarget = static_cast(ui->cbOutput->currentIndex()); - mEdited=false; } void ToolsGeneralWidget::prepareEdit(const PToolItem& item) @@ -186,14 +182,23 @@ void ToolsModel::addTool(PToolItem item) endInsertRows(); } -PToolItem ToolsModel::getTool(int index) +PToolItem ToolsModel::getTool(int row) { - return mTools[index]; + return mTools[row]; } -void ToolsModel::removeTool(int index) +void ToolsModel::updateTool(int row, PToolItem item) { - mTools.removeAt(index); + mTools[row] = item; + QModelIndex index=createIndex(row, 0); + emit dataChanged(index, index); +} + +void ToolsModel::removeTool(int row) +{ + beginRemoveRows(QModelIndex(),row,row); + mTools.removeAt(row); + endRemoveRows(); } int ToolsModel::rowCount(const QModelIndex &) const diff --git a/RedPandaIDE/settingsdialog/toolsgeneralwidget.h b/RedPandaIDE/settingsdialog/toolsgeneralwidget.h index 625c6d03..57dc2c11 100644 --- a/RedPandaIDE/settingsdialog/toolsgeneralwidget.h +++ b/RedPandaIDE/settingsdialog/toolsgeneralwidget.h @@ -34,8 +34,9 @@ public: const QList &tools() const; void setTools(const QList &newTools); void addTool(PToolItem item); - PToolItem getTool(int index); - void removeTool(int index); + PToolItem getTool(int row); + void updateTool(int row, PToolItem item); + void removeTool(int row); private: QList mTools; @@ -51,10 +52,6 @@ class ToolsGeneralWidget : public SettingsWidget { Q_OBJECT public: - enum class EditType { - Edit, - None - }; explicit ToolsGeneralWidget(const QString& name, const QString& group, QWidget *parent = nullptr); ~ToolsGeneralWidget(); private: @@ -82,8 +79,8 @@ private: Ui::ToolsGeneralWidget *ui; MacroInfoModel mMacroInfoModel; ToolsModel mToolsModel; - EditType mEditType; bool mEdited; + int mCurrentEditingRow; // SettingsWidget interface protected: