RedPanda-CPP/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp

147 lines
5.4 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"
#include <qt_utils/charsetinfo.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->panelAddCharset->setVisible(pSet->compilerType()!=CompilerType::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());
ui->chkAddCharset->setChecked(pSet->autoAddCharsetParams());
QByteArray execEncoding = pMainWindow->project()->options().execEncoding;
if (execEncoding == ENCODING_AUTO_DETECT
|| execEncoding == ENCODING_SYSTEM_DEFAULT
|| execEncoding == ENCODING_UTF8) {
int index =ui->cbEncoding->findData(execEncoding);
ui->cbEncoding->setCurrentIndex(index);
ui->cbEncodingDetails->clear();
ui->cbEncodingDetails->setVisible(false);
} else {
QString encoding = execEncoding;
QString language = pCharsetInfoManager->findLanguageByCharsetName(encoding);
ui->cbEncoding->setCurrentText(language);
ui->cbEncodingDetails->setVisible(true);
ui->cbEncodingDetails->clear();
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(language);
foreach (const PCharsetInfo& info, infos) {
ui->cbEncodingDetails->addItem(info->name);
}
ui->cbEncodingDetails->setCurrentText(encoding);
}
}
void ProjectCompilerWidget::doLoad()
{
mOptions = pMainWindow->project()->options().compilerOptions;
ui->cbCompilerSet->setCurrentIndex(pMainWindow->project()->options().compilerSet);
ui->chkAddCharset->setChecked(pMainWindow->project()->options().addCharset);
ui->chkStaticLink->setChecked(pMainWindow->project()->options().staticLink);
}
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()!=CompilerType::Clang)
pMainWindow->project()->options().addCharset = ui->chkAddCharset->isChecked();
pMainWindow->project()->options().staticLink = ui->chkStaticLink->isChecked();
if (ui->cbEncodingDetails->isVisible()) {
pMainWindow->project()->options().execEncoding = ui->cbEncodingDetails->currentText().toLocal8Bit();
} else {
pMainWindow->project()->options().execEncoding = ui->cbEncoding->currentData().toString().toLocal8Bit();
}
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());
}
ui->cbEncodingDetails->setVisible(false);
ui->cbEncoding->clear();
ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT);
ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8);
foreach (const QString& langName, pCharsetInfoManager->languageNames()) {
ui->cbEncoding->addItem(langName,langName);
}
SettingsWidget::init();
}
void ProjectCompilerWidget::on_cbCompilerSet_currentIndexChanged(int)
{
refreshOptions();
}
2022-07-04 11:39:06 +08:00
void ProjectCompilerWidget::on_cbEncoding_currentTextChanged(const QString &/*arg1*/)
{
QString userData = ui->cbEncoding->currentData().toString();
if (userData == ENCODING_AUTO_DETECT
|| userData == ENCODING_SYSTEM_DEFAULT
|| userData == ENCODING_UTF8) {
ui->cbEncodingDetails->setVisible(false);
ui->cbEncodingDetails->clear();
} else {
ui->cbEncodingDetails->setVisible(true);
ui->cbEncodingDetails->clear();
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(userData);
foreach (const PCharsetInfo& info, infos) {
ui->cbEncodingDetails->addItem(info->name);
}
}
}
2022-07-04 11:39:06 +08:00
void ProjectCompilerWidget::on_cbEncodingDetails_currentTextChanged(const QString &/*arg1*/)
{
}