diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 4a748c73..ddc2e072 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -1033,6 +1033,9 @@ void Settings::CompilerSets::deleteSet(int index) for (int i=index;i=mList.size()) { + mDefaultIndex = mList.size()-1; + } } Settings::CompilerSetList &Settings::CompilerSets::list() diff --git a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp index f72386da..3c7268d4 100644 --- a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp @@ -1,7 +1,9 @@ #include "compilersetdirectorieswidget.h" #include "ui_compilersetdirectorieswidget.h" +#include #include +#include CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) : QWidget(parent), @@ -11,6 +13,9 @@ CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) : mModel = new CompilerSetDirectoriesWidget::ListModel(); ui->listView->setModel(mModel); + connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged, + this, &CompilerSetDirectoriesWidget::selectionChanged); + ui->listView->setSelectionMode(QAbstractItemView::SingleSelection); } CompilerSetDirectoriesWidget::~CompilerSetDirectoriesWidget() @@ -21,6 +26,8 @@ CompilerSetDirectoriesWidget::~CompilerSetDirectoriesWidget() void CompilerSetDirectoriesWidget::setDirList(const QStringList &list) { mModel->setStringList(list); + QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes(); + ui->btnDelete->setEnabled(lst.count()>0); } QStringList CompilerSetDirectoriesWidget::dirList() const @@ -30,7 +37,49 @@ QStringList CompilerSetDirectoriesWidget::dirList() const Qt::ItemFlags CompilerSetDirectoriesWidget::ListModel::flags(const QModelIndex &index) const { + Qt::ItemFlags flags = Qt::NoItemFlags; if (index.isValid()) { - return Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable; + flags = Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable ; + } else if (index.row() ==-1) { + // -1 means it's a drop target? + flags = Qt::ItemIsDropEnabled; + } + return flags; +} + +void CompilerSetDirectoriesWidget::on_btnAdd_pressed() +{ + QString folder = QFileDialog::getExistingDirectory(this,tr("Choose Folder")); + if (!folder.isEmpty()) { + int row = mModel->rowCount(); + mModel->insertRow(row); + QModelIndex index= mModel->index(row,0); + mModel->setData(index,folder,Qt::DisplayRole); } } + +void CompilerSetDirectoriesWidget::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) +{ + ui->btnDelete->setEnabled(!selected.isEmpty()); +} + +void CompilerSetDirectoriesWidget::on_btnDelete_pressed() +{ + QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes(); + if (lst.count()>0) { + mModel->removeRow(lst[0].row()); + } +} + + +void CompilerSetDirectoriesWidget::on_btnRemoveInvalid_pressed() +{ + QStringList lst; + for (const QString& folder : dirList() ) { + QFileInfo info(folder); + if (info.exists() && info.isDir() ) { + lst.append(folder); + } + } + setDirList(lst); +} diff --git a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h index 4491bcb7..102c8b05 100644 --- a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h +++ b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h @@ -8,6 +8,7 @@ namespace Ui { class CompilerSetDirectoriesWidget; } +class QItemSelection; class CompilerSetDirectoriesWidget : public QWidget { @@ -24,6 +25,15 @@ public: void setDirList(const QStringList& list); QStringList dirList() const; +private slots: + void on_btnDelete_pressed(); + + void on_btnAdd_pressed(); + + void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); + + void on_btnRemoveInvalid_pressed(); + private: Ui::CompilerSetDirectoriesWidget *ui; ListModel* mModel; diff --git a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.ui b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.ui index c2603fa3..405bf877 100644 --- a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.ui +++ b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.ui @@ -24,7 +24,7 @@ - + Add @@ -37,12 +37,12 @@ - true + false - + Delete @@ -55,12 +55,12 @@ - true + false - + Remove Invalid @@ -76,7 +76,7 @@ Qt::ToolButtonIconOnly - true + false diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp index df00604f..f42a2c8c 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp @@ -59,7 +59,7 @@ void resetOptionTabs(Settings::PCompilerSet pSet,QTabWidget* pTab) pTab->addTab(pWidget,pOption->section); pWidget->setLayout(new QGridLayout()); } - QGridLayout *pLayout = (QGridLayout*)pWidget->layout(); + QGridLayout *pLayout = static_cast(pWidget->layout()); int row = pLayout->rowCount(); pLayout->addWidget(new QLabel(pOption->name),row,0); QComboBox* pCombo = new QComboBox(); @@ -82,7 +82,7 @@ void resetOptionTabs(Settings::PCompilerSet pSet,QTabWidget* pTab) } for (int i=0;icount();i++) { QWidget* pWidget = pTab->widget(i); - QGridLayout *pLayout = (QGridLayout*)pWidget->layout(); + QGridLayout *pLayout = static_cast(pWidget->layout()); int row = pLayout->rowCount(); QSpacerItem* horizontalSpacer = new QSpacerItem(10, 100, QSizePolicy::Minimum, QSizePolicy::Expanding); pLayout->addItem(horizontalSpacer,row,0); @@ -112,18 +112,33 @@ static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSet void CompilerSetOptionWidget::doLoad() { + disconnectInputs(); ui->cbCompilerSet->clear(); + if (pSettings->compilerSets().list().size()<=0) { + ui->btnRenameCompilerSet->setEnabled(false); + ui->btnRemoveCompilerSet->setEnabled(false); + return; + } else { + ui->btnRenameCompilerSet->setEnabled(true); + ui->btnRemoveCompilerSet->setEnabled(true); + } int index=pSettings->compilerSets().defaultIndex(); for (int i=0;icompilerSets().list().size();i++) { ui->cbCompilerSet->addItem(pSettings->compilerSets().list()[i]->name()); } + if (index < 0 || index>=ui->cbCompilerSet->count()) { + index = 0; + } ui->cbCompilerSet->setCurrentIndex(index); - - //reloadCurrentCompilerSet(); + reloadCurrentCompilerSet(); + connectInputs(); } void CompilerSetOptionWidget::doSave() { + if (pSettings->compilerSets().list().size()>0) { + saveCurrentCompilerSet(); + } pSettings->compilerSets().saveSets(); } @@ -131,8 +146,11 @@ void CompilerSetOptionWidget::on_cbCompilerSet_currentIndexChanged(int index) { if (index<0) return; + setSettingsChanged(); pSettings->compilerSets().setDefaultIndex(index); + disconnectInputs(); reloadCurrentCompilerSet(); + connectInputs(); } void CompilerSetOptionWidget::reloadCurrentCompilerSet() @@ -145,7 +163,50 @@ void CompilerSetOptionWidget::reloadCurrentCompilerSet() mCIncludeDirWidget->setDirList(pSet->CIncludeDirs()); mCppIncludeDirWidget->setDirList(pSet->CppIncludeDirs()); - connectInputs(); +} + +void CompilerSetOptionWidget::saveCurrentCompilerSet() +{ + Settings::PCompilerSet pSet = pSettings->compilerSets().defaultSet(); + + pSet->setUseCustomCompileParams(ui->chkUseCustomCompilerParams->isChecked()); + pSet->setCustomCompileParams(ui->txtCustomCompileParams->toPlainText()); + pSet->setUseCustomLinkParams(ui->chkUseCustomLinkParams->isChecked()); + pSet->setCustomLinkParams(ui->txtCustomLinkParams->toPlainText()); + pSet->setStaticLink(ui->chkStaticLink->isChecked()); + pSet->setAutoAddCharsetParams(ui->chkAutoAddCharset->isChecked()); + + pSet->setCCompiler(ui->txtCCompiler->text()); + pSet->setCppCompiler(ui->txtCppCompiler->text()); + pSet->setMake(ui->txtMake->text()); + pSet->setDebugger(ui->txtDebugger->text()); + pSet->setResourceCompiler(ui->txtResourceCompiler->text()); + pSet->setProfiler(ui->txtProfiler->text()); + + pSet->binDirs()=mBinDirWidget->dirList(); + + pSet->libDirs()=mLibDirWidget->dirList(); + pSet->CIncludeDirs()=mCIncludeDirWidget->dirList(); + pSet->CppIncludeDirs()=mCppIncludeDirWidget->dirList(); + + //read values in the options widget + QTabWidget* pTab = ui->optionTabs; + for (int i=0;icount();i++) { + QString section = pTab->tabText(i); + QWidget* pWidget = pTab->widget(i); + QGridLayout* pLayout = static_cast(pWidget->layout()); + if (pLayout != nullptr) { + for (int j=1;jrowCount()-1;j++) { + QString name = static_cast(pLayout->itemAtPosition(j,0)->widget())->text(); + QComboBox* pCombo = static_cast(pLayout->itemAtPosition(j,1)->widget()); + for (PCompilerOption pOption: pSet->options()) { + if (pOption->section == section && pOption->name == name) { + pOption->value = pCombo->currentIndex(); + } + } + } + } + } } void CompilerSetOptionWidget::on_btnFindCompilers_pressed() @@ -180,8 +241,15 @@ void CompilerSetOptionWidget::on_btnAddCompilerSetByFolder_pressed() void CompilerSetOptionWidget::on_btnRenameCompilerSet_pressed() { - QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("New name")); + QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("New name"),QLineEdit::Normal, + pSettings->compilerSets().defaultSet()->name()); if (!name.isEmpty()) pSettings->compilerSets().defaultSet()->setName(name); doLoad(); } + +void CompilerSetOptionWidget::on_btnRemoveCompilerSet_pressed() +{ + pSettings->compilerSets().deleteSet(ui->cbCompilerSet->currentIndex()); + doLoad(); +} diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.h b/RedPandaIDE/settingsdialog/compilersetoptionwidget.h index 5f961150..ae1a5438 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.h +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.h @@ -31,6 +31,7 @@ protected: void doSave() override; private: void reloadCurrentCompilerSet(); + void saveCurrentCompilerSet(); private slots: void on_cbCompilerSet_currentIndexChanged(int index); @@ -38,6 +39,7 @@ private slots: void on_btnAddBlankCompilerSet_pressed(); void on_btnAddCompilerSetByFolder_pressed(); void on_btnRenameCompilerSet_pressed(); + void on_btnRemoveCompilerSet_pressed(); }; #endif // COMPILERSETOPTIONWIDGET_H diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp index a702df98..576b62ee 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.cpp +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -90,7 +90,7 @@ void SettingsDialog::on_btnOk_pressed() void SettingsDialog::saveCurrentPageSettings(bool confirm) { - if (ui->scrollArea->widget()!=ui->scrollAreaWidgetContents) + if (ui->scrollArea->widget()==ui->scrollAreaWidgetContents) return; SettingsWidget* pWidget = (SettingsWidget*) ui->scrollArea->widget(); if (!pWidget->isSettingsChanged()) @@ -99,8 +99,8 @@ void SettingsDialog::saveCurrentPageSettings(bool confirm) if (QMessageBox::information(this,tr("Save Changes"), tr("There are changes in the settings, do you want to save them before swtich to other page?"), QMessageBox::Yes, QMessageBox::No)!=QMessageBox::Yes) { - return; + return; + } } pWidget->save(); - ui->btnApply->setEnabled(false); } diff --git a/RedPandaIDE/settingsdialog/settingswidget.cpp b/RedPandaIDE/settingsdialog/settingswidget.cpp index f9dfc85b..8d5d7b94 100644 --- a/RedPandaIDE/settingsdialog/settingswidget.cpp +++ b/RedPandaIDE/settingsdialog/settingswidget.cpp @@ -24,13 +24,32 @@ void SettingsWidget::init() void SettingsWidget::load() { doLoad(); - mSettingsChanged = false; + clearSettingsChanged(); } void SettingsWidget::save() { doSave(); - mSettingsChanged = false; + clearSettingsChanged(); +} + +void SettingsWidget::connectAbstractItemView(QAbstractItemView *pView) +{ + connect(pView->model(),&QAbstractItemModel::rowsInserted,this,&SettingsWidget::setSettingsChanged); + connect(pView->model(),&QAbstractItemModel::rowsMoved,this,&SettingsWidget::setSettingsChanged); + connect(pView->model(),&QAbstractItemModel::rowsRemoved,this,&SettingsWidget::setSettingsChanged); + connect(pView->model(),&QAbstractItemModel::dataChanged,this,&SettingsWidget::setSettingsChanged); + connect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged); +} + +void SettingsWidget::disconnectAbstractItemView(QAbstractItemView *pView) +{ + disconnect(pView->model(),&QAbstractItemModel::rowsInserted,this,&SettingsWidget::setSettingsChanged); + disconnect(pView->model(),&QAbstractItemModel::rowsMoved,this,&SettingsWidget::setSettingsChanged); + disconnect(pView->model(),&QAbstractItemModel::rowsRemoved,this,&SettingsWidget::setSettingsChanged); + disconnect(pView->model(),&QAbstractItemModel::dataChanged,this,&SettingsWidget::setSettingsChanged); + disconnect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged); + } void SettingsWidget::connectInputs() @@ -48,11 +67,30 @@ void SettingsWidget::connectInputs() connect(p, QOverload::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged); } for (QAbstractItemView* p: findChildren()) { - connect(p, &QAbstractItemView::activated,this, &SettingsWidget::setSettingsChanged); + connectAbstractItemView(p); } } +void SettingsWidget::disconnectInputs() +{ + for (QLineEdit* p:findChildren()) { + disconnect(p, &QLineEdit::textChanged, this, &SettingsWidget::setSettingsChanged); + } + for (QCheckBox* p:findChildren()) { + disconnect(p, &QCheckBox::stateChanged, this, &SettingsWidget::setSettingsChanged); + } + for (QPlainTextEdit* p:findChildren()) { + disconnect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged); + } + for (QComboBox* p: findChildren()) { + disconnect(p, QOverload::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged); + } + for (QAbstractItemView* p: findChildren()) { + disconnectAbstractItemView(p); + } +} + const QString &SettingsWidget::group() { return mGroup; diff --git a/RedPandaIDE/settingsdialog/settingswidget.h b/RedPandaIDE/settingsdialog/settingswidget.h index adf790c6..ce43956f 100644 --- a/RedPandaIDE/settingsdialog/settingswidget.h +++ b/RedPandaIDE/settingsdialog/settingswidget.h @@ -3,6 +3,7 @@ #include +class QAbstractItemView; class SettingsWidget : public QWidget { Q_OBJECT @@ -17,16 +18,21 @@ signals: void settingsChanged(bool changed); protected: - void connectInputs(); virtual void doLoad() = 0; virtual void doSave() = 0; + void connectAbstractItemView(QAbstractItemView* pView); + void disconnectAbstractItemView(QAbstractItemView* pView); public: const QString& group(); const QString& name(); bool isSettingsChanged(); + void connectInputs(); + void disconnectInputs(); public slots: void setSettingsChanged(); void clearSettingsChanged(); +private: + private: bool mSettingsChanged; QString mGroup;