diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 6516f522..3c7bd1c9 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -1584,15 +1584,34 @@ void Project::loadOptions(SimpleIni& ini) ); setCompilerSet(pSettings->compilerSets().defaultIndex()); } - SimpleIni::TNamesDepend oKeys; - ini.GetAllKeys("CompilerSettings", oKeys); - for(const SimpleIni::Entry& entry:oKeys) { - QString key(entry.pItem); - PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key); - if (pOption) { - mOptions.compilerOptions.insert( - key, - ini.GetValue("CompilerSettings", entry.pItem, "")); + + QByteArray oldCompilerOptions = ini.GetValue("Project", "CompilerSettings", ""); + if (!oldCompilerOptions.isEmpty()) { + for (int i=0;icompilerSets().getKeyFromCompilerCompatibleIndex(i); + PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key); + if (pOption) { + int val = Settings::CompilerSet::charToValue(oldCompilerOptions[i]); + if (pOption->choices.isEmpty()) { + if (val>0) + mOptions.compilerOptions.insert(key,""); + } else { + if (val>0 && val <= pOption->choices.length()) + mOptions.compilerOptions.insert(key,pOption->choices[val-1].second); + } + } + } + } else { + SimpleIni::TNamesDepend oKeys; + ini.GetAllKeys("CompilerSettings", oKeys); + for(const SimpleIni::Entry& entry:oKeys) { + QString key(entry.pItem); + PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key); + if (pOption) { + mOptions.compilerOptions.insert( + key, + ini.GetValue("CompilerSettings", entry.pItem, "")); + } } } diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 10137e58..b086ac0a 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -1495,7 +1495,13 @@ Settings::CompilerSet::CompilerSet(const Settings::CompilerSet &set): bool Settings::CompilerSet::setCompileOption(const QString &key, int valIndex) { PCompilerOption op = pSettings->compilerSets().getCompilerOption(key); - if (op && valIndex>=0 && valIndex < op->choices.length()) { + if (!op) + return false; + if (op->choices.isEmpty()) { + if (valIndex==1) + mCompileOptions.insert(key,""); + return true; + } else if (valIndex>0 && valIndex <= op->choices.length()) { mCompileOptions.insert(key,op->choices[valIndex].second); return true; } @@ -2218,12 +2224,7 @@ void Settings::CompilerSet::setIniOptions(const QByteArray &value) mCompileOptions.clear(); for (int i=0;icompilerSets().getKeyFromCompilerCompatibleIndex(i); - PCompilerOption p = pSettings->compilerSets().getCompilerOption(key); - if (p) { - int v = charToValue(value[i]); - if (v > 0 && v<= p->choices.length()) - mCompileOptions.insert(key,p->choices[v-1].second); - } + setCompileOption(key,charToValue(value[i])); } } @@ -2646,6 +2647,7 @@ void Settings::CompilerSets::saveSet(int index) savePath("windres", pSet->resourceCompiler()); savePath("profiler", pSet->profiler()); + mSettings->mSettings.remove("Options"); // Save option string for (const QString& optionKey : pSet->compileOptions().keys()) { mSettings->mSettings.setValue(optionKey, pSet->compileOptions().value(optionKey)); @@ -2718,9 +2720,11 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index) QByteArray iniOptions = mSettings->mSettings.value("Options","").toByteArray(); if (!iniOptions.isEmpty()) pSet->setIniOptions(iniOptions); - foreach (const QString &optionKey, mSettings->mSettings.allKeys()) { - if (mCompilerOptions.contains(optionKey)) { - pSet->setCompileOption(optionKey, mSettings->mSettings.value(optionKey).toString()); + else { + foreach (const QString &optionKey, mSettings->mSettings.allKeys()) { + if (mCompilerOptions.contains(optionKey)) { + pSet->setCompileOption(optionKey, mSettings->mSettings.value(optionKey).toString()); + } } } @@ -2930,10 +2934,7 @@ void Settings::CompilerSets::addOption(const QString &key, const QString &name, pOption->isCpp = isCpp; pOption->isLinker = isLinker; pOption->setting= setting; - if (choices.isEmpty()) { - pOption->choices.append(QPair(QObject::tr("On"),"")); - } else - pOption->choices = choices; + pOption->choices = choices; mCompilerOptions.insert(key,pOption); } diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp index fbc339fa..0cbe50d9 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp @@ -95,20 +95,26 @@ void resetOptionTabs(Settings::PCompilerSet pSet,QTabWidget* pTab) } QGridLayout *pLayout = static_cast(pWidget->layout()); int row = pLayout->rowCount(); - pLayout->addWidget(new QLabel(pOption->name),row,0); - QComboBox* pCombo = new QComboBox(); - pCombo->addItem(QObject::tr(""),""); - foreach (auto choice, pOption->choices) { - pCombo->addItem("",) - QStringList valueName=choice.split("="); - if (valueName.length()<2) { - pCombo->addItem(""); - } else { - pCombo->addItem(valueName[0]); + QLabel* keyLabel = new QLabel(pOption->key,pWidget); + keyLabel->setVisible(false); + pLayout->addWidget(keyLabel,row,0); + if (pOption->choices.isEmpty()) { + QCheckBox* pCheckbox = new QCheckBox(pWidget); + pCheckbox->setText(pOption->name); + pCheckbox->setChecked(!pSet->getCompileOptionValue(pOption->key).isEmpty()); + pLayout->addWidget(pCheckbox,row,1); + } else { + pLayout->addWidget(new QLabel(pOption->name,pWidget),row,1); + QComboBox* pCombo = new QComboBox(pWidget); + pCombo->addItem("",""); + for (int i=0;ichoices.length();i++) { + const QPair &choice = pOption->choices[i]; + pCombo->addItem(choice.first,choice.second); + if (pSet->getCompileOptionValue(pOption->key) == choice.second) + pCombo->setCurrentIndex(i); } + pLayout->addWidget(pCombo,row,2); } - pCombo->setCurrentIndex(pOption->value); - pLayout->addWidget(pCombo,row,1); } for (int i=0;icount();i++) { QWidget* pWidget = pTab->widget(i); @@ -261,11 +267,23 @@ void CompilerSetOptionWidget::saveCurrentCompilerSet() 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(); + QString key = static_cast(pLayout->itemAtPosition(j,0)->widget())->text(); + PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key); + if (!pOption) + continue; + if (pOption->choices.isEmpty()) { + QCheckBox* pCheckbox = static_cast(pLayout->itemAtPosition(j,1)->widget()); + if (pCheckbox->isChecked()) { + pSet->setCompileOption(key,""); + } else { + pSet->unsetCompileOption(key); + } + } else { + QComboBox* pCombo = static_cast(pLayout->itemAtPosition(j,2)->widget()); + if (!pCombo->currentData().toString().isEmpty()) { + pSet->setCompileOption(key,pCombo->currentData().toString()); + } else { + pSet->unsetCompileOption(key); } } } diff --git a/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp b/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp index 0fc0e40f..73f61959 100644 --- a/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp +++ b/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp @@ -39,7 +39,9 @@ void ProjectCompilerWidget::refreshOptions() return; ui->chkAddCharset->setVisible(pSet->compilerType()!=COMPILER_CLANG); ui->chkAddCharset->setEnabled(pSet->compilerType()!=COMPILER_CLANG); - mOptions = pSet->iniOptions(); + mOptions = pMainWindow->project().options().compilerOptions; + if (mOptions.isEmpty()) + mOptions = pSet->compileOptions(); QTabWidget* pTab = ui->tabOptions; while (pTab->count()>0) { QWidget* p=pTab->widget(0); diff --git a/RedPandaIDE/settingsdialog/projectcompilerwidget.h b/RedPandaIDE/settingsdialog/projectcompilerwidget.h index 7810dcd4..7339a0ea 100644 --- a/RedPandaIDE/settingsdialog/projectcompilerwidget.h +++ b/RedPandaIDE/settingsdialog/projectcompilerwidget.h @@ -17,6 +17,7 @@ #ifndef PROJECTCOMPILERWIDGET_H #define PROJECTCOMPILERWIDGET_H +#include #include #include "settingswidget.h" @@ -35,7 +36,7 @@ private: void refreshOptions(); private: Ui::ProjectCompilerWidget *ui; - QByteArray mOptions; + QMap mOptions; // SettingsWidget interface protected: