RedPanda-CPP/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp

88 lines
2.9 KiB
C++
Raw Normal View History

2021-12-26 23:18:28 +08:00
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2021-09-15 08:02:08 +08:00
#include "projectcompilerwidget.h"
#include "ui_projectcompilerwidget.h"
#include "../settings.h"
#include "../project.h"
#include "../mainwindow.h"
2021-09-15 08:02:08 +08:00
ProjectCompilerWidget::ProjectCompilerWidget(const QString &name, const QString &group, QWidget *parent) :
SettingsWidget(name,group,parent),
2021-09-15 08:02:08 +08:00
ui(new Ui::ProjectCompilerWidget)
{
ui->setupUi(this);
}
ProjectCompilerWidget::~ProjectCompilerWidget()
{
delete ui;
}
void ProjectCompilerWidget::refreshOptions()
{
Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(ui->cbCompilerSet->currentIndex());
if (!pSet)
return;
ui->chkAddCharset->setVisible(pSet->compilerType()!=COMPILER_CLANG);
ui->chkAddCharset->setEnabled(pSet->compilerType()!=COMPILER_CLANG);
mOptions = pMainWindow->project()->options().compilerOptions;
2022-05-12 22:42:19 +08:00
if (mOptions.isEmpty())
mOptions = pSet->compileOptions();
ui->tabOptions->resetUI(pSet,mOptions);
ui->chkStaticLink->setChecked(pSet->staticLink());
}
void ProjectCompilerWidget::doLoad()
{
ui->chkAddCharset->setChecked(pMainWindow->project()->options().addCharset);
ui->chkStaticLink->setChecked(pMainWindow->project()->options().staticLink);
mOptions = pMainWindow->project()->options().compilerOptions;
ui->cbCompilerSet->setCurrentIndex(pMainWindow->project()->options().compilerSet);
}
void ProjectCompilerWidget::doSave()
{
Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(ui->cbCompilerSet->currentIndex());
if (!pSet)
return;
pMainWindow->project()->setCompilerSet(ui->cbCompilerSet->currentIndex());
pMainWindow->project()->options().compilerOptions = ui->tabOptions->arguments(true);
if (pSet->compilerType()!=COMPILER_CLANG)
pMainWindow->project()->options().addCharset = ui->chkAddCharset->isChecked();
pMainWindow->project()->options().staticLink = ui->chkStaticLink->isChecked();
pMainWindow->project()->saveOptions();
}
void ProjectCompilerWidget::init()
{
ui->cbCompilerSet->clear();
2022-04-25 12:43:23 +08:00
for (size_t i=0;i<pSettings->compilerSets().size();i++) {
2022-03-11 20:51:33 +08:00
ui->cbCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name());
}
SettingsWidget::init();
}
void ProjectCompilerWidget::on_cbCompilerSet_currentIndexChanged(int)
{
refreshOptions();
}