work save

This commit is contained in:
Roy Qu 2022-05-12 22:42:19 +08:00
parent 9867d0d931
commit 2f5f1346fd
5 changed files with 83 additions and 42 deletions

View File

@ -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;i<oldCompilerOptions.length();i++) {
QString key = pSettings->compilerSets().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, ""));
}
}
}

View File

@ -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;i<value.length();i++) {
QString key = pSettings->compilerSets().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<QString,QString>(QObject::tr("On"),""));
} else
pOption->choices = choices;
pOption->choices = choices;
mCompilerOptions.insert(key,pOption);
}

View File

@ -95,20 +95,26 @@ void resetOptionTabs(Settings::PCompilerSet pSet,QTabWidget* pTab)
}
QGridLayout *pLayout = static_cast<QGridLayout*>(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;i<pOption->choices.length();i++) {
const QPair<QString,QString> &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;i<pTab->count();i++) {
QWidget* pWidget = pTab->widget(i);
@ -261,11 +267,23 @@ void CompilerSetOptionWidget::saveCurrentCompilerSet()
QGridLayout* pLayout = static_cast<QGridLayout*>(pWidget->layout());
if (pLayout != nullptr) {
for (int j=1;j<pLayout->rowCount()-1;j++) {
QString name = static_cast<QLabel *>(pLayout->itemAtPosition(j,0)->widget())->text();
QComboBox* pCombo = static_cast<QComboBox *>(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<QLabel *>(pLayout->itemAtPosition(j,0)->widget())->text();
PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key);
if (!pOption)
continue;
if (pOption->choices.isEmpty()) {
QCheckBox* pCheckbox = static_cast<QCheckBox *>(pLayout->itemAtPosition(j,1)->widget());
if (pCheckbox->isChecked()) {
pSet->setCompileOption(key,"");
} else {
pSet->unsetCompileOption(key);
}
} else {
QComboBox* pCombo = static_cast<QComboBox *>(pLayout->itemAtPosition(j,2)->widget());
if (!pCombo->currentData().toString().isEmpty()) {
pSet->setCompileOption(key,pCombo->currentData().toString());
} else {
pSet->unsetCompileOption(key);
}
}
}

View File

@ -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);

View File

@ -17,6 +17,7 @@
#ifndef PROJECTCOMPILERWIDGET_H
#define PROJECTCOMPILERWIDGET_H
#include <QMap>
#include <QWidget>
#include "settingswidget.h"
@ -35,7 +36,7 @@ private:
void refreshOptions();
private:
Ui::ProjectCompilerWidget *ui;
QByteArray mOptions;
QMap<QString,QString> mOptions;
// SettingsWidget interface
protected: