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"
|
2021-09-15 11:23:42 +08:00
|
|
|
#include "../settings.h"
|
|
|
|
#include "../project.h"
|
|
|
|
#include "../mainwindow.h"
|
2022-09-26 14:54:28 +08:00
|
|
|
#include <qt_utils/charsetinfo.h>
|
2023-04-03 09:39:45 +08:00
|
|
|
#include <QMessageBox>
|
2021-09-15 08:02:08 +08:00
|
|
|
|
2021-09-15 11:23:42 +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)
|
|
|
|
{
|
2023-04-03 09:39:45 +08:00
|
|
|
mInitialized=false;
|
2021-09-15 08:02:08 +08:00
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectCompilerWidget::~ProjectCompilerWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2021-09-15 11:23:42 +08:00
|
|
|
|
|
|
|
void ProjectCompilerWidget::refreshOptions()
|
|
|
|
{
|
2021-10-25 21:36:23 +08:00
|
|
|
Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(ui->cbCompilerSet->currentIndex());
|
2021-09-15 11:23:42 +08:00
|
|
|
if (!pSet)
|
|
|
|
return;
|
2022-10-30 11:58:42 +08:00
|
|
|
ui->panelAddCharset->setVisible(pSet->compilerType()!=CompilerType::Clang);
|
2022-06-22 17:08:35 +08:00
|
|
|
//ui->chkAddCharset->setEnabled(pSet->compilerType()!=COMPILER_CLANG);
|
2022-05-14 11:21:59 +08:00
|
|
|
mOptions = pMainWindow->project()->options().compilerOptions;
|
2022-05-12 22:42:19 +08:00
|
|
|
if (mOptions.isEmpty())
|
|
|
|
mOptions = pSet->compileOptions();
|
2021-09-15 11:23:42 +08:00
|
|
|
|
2022-05-14 11:21:59 +08:00
|
|
|
ui->tabOptions->resetUI(pSet,mOptions);
|
2021-10-25 21:36:23 +08:00
|
|
|
|
|
|
|
ui->chkStaticLink->setChecked(pSet->staticLink());
|
2022-12-18 12:31:19 +08:00
|
|
|
ui->chkAddCharset->setChecked(pSet->autoAddCharsetParams());
|
2022-06-22 17:08:35 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2021-09-15 11:23:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectCompilerWidget::doLoad()
|
|
|
|
{
|
|
|
|
mOptions = pMainWindow->project()->options().compilerOptions;
|
|
|
|
ui->cbCompilerSet->setCurrentIndex(pMainWindow->project()->options().compilerSet);
|
2022-12-18 12:31:19 +08:00
|
|
|
ui->chkAddCharset->setChecked(pMainWindow->project()->options().addCharset);
|
|
|
|
ui->chkStaticLink->setChecked(pMainWindow->project()->options().staticLink);
|
2023-04-03 09:39:45 +08:00
|
|
|
mInitialized=true;
|
2021-09-15 11:23:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectCompilerWidget::doSave()
|
|
|
|
{
|
2022-05-02 21:47:01 +08:00
|
|
|
Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(ui->cbCompilerSet->currentIndex());
|
2021-09-15 11:23:42 +08:00
|
|
|
if (!pSet)
|
|
|
|
return;
|
2022-05-14 11:21:59 +08:00
|
|
|
|
2021-10-25 21:36:23 +08:00
|
|
|
pMainWindow->project()->setCompilerSet(ui->cbCompilerSet->currentIndex());
|
2022-05-14 11:21:59 +08:00
|
|
|
pMainWindow->project()->options().compilerOptions = ui->tabOptions->arguments(true);
|
2022-10-30 11:58:42 +08:00
|
|
|
if (pSet->compilerType()!=CompilerType::Clang)
|
2022-05-02 21:47:01 +08:00
|
|
|
pMainWindow->project()->options().addCharset = ui->chkAddCharset->isChecked();
|
2021-10-25 21:36:23 +08:00
|
|
|
pMainWindow->project()->options().staticLink = ui->chkStaticLink->isChecked();
|
2022-06-22 17:08:35 +08:00
|
|
|
|
|
|
|
if (ui->cbEncodingDetails->isVisible()) {
|
|
|
|
pMainWindow->project()->options().execEncoding = ui->cbEncodingDetails->currentText().toLocal8Bit();
|
|
|
|
} else {
|
|
|
|
pMainWindow->project()->options().execEncoding = ui->cbEncoding->currentData().toString().toLocal8Bit();
|
|
|
|
}
|
2021-09-15 12:19:09 +08:00
|
|
|
pMainWindow->project()->saveOptions();
|
2021-09-15 11:23:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2021-09-15 11:23:42 +08:00
|
|
|
}
|
2022-06-22 17:08:35 +08:00
|
|
|
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);
|
|
|
|
}
|
2021-09-15 12:19:09 +08:00
|
|
|
SettingsWidget::init();
|
|
|
|
}
|
|
|
|
|
2023-04-03 09:39:45 +08:00
|
|
|
void ProjectCompilerWidget::on_cbCompilerSet_currentIndexChanged(int index)
|
2021-09-15 12:19:09 +08:00
|
|
|
{
|
2023-04-03 09:39:45 +08:00
|
|
|
std::shared_ptr<Project> project = pMainWindow->project();
|
|
|
|
auto action = finally([this]{
|
|
|
|
this->refreshOptions();
|
|
|
|
});
|
|
|
|
if (!mInitialized || index==project->options().compilerSet) {
|
|
|
|
return;
|
|
|
|
}
|
2023-08-17 19:24:49 +08:00
|
|
|
Settings::PCompilerSet pSet=pSettings->compilerSets().getSet(index);
|
2023-12-17 13:53:22 +08:00
|
|
|
#ifdef ENABLE_SDCC
|
2023-08-17 19:24:49 +08:00
|
|
|
if (pSet) {
|
|
|
|
if (project->options().type==ProjectType::MicroController) {
|
|
|
|
if (pSet->compilerType()!=CompilerType::SDCC) {
|
|
|
|
QMessageBox::information(this,
|
|
|
|
tr("Wrong Compiler Type"),
|
|
|
|
tr("Compiler %1 can't compile a microcontroller project.").arg(pSet->name())
|
|
|
|
);
|
|
|
|
ui->cbCompilerSet->setCurrentIndex(project->options().compilerSet);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pSet->compilerType()==CompilerType::SDCC) {
|
|
|
|
QMessageBox::information(this,
|
|
|
|
tr("Wrong Compiler Type"),
|
|
|
|
tr("Compiler %1 can only compile microcontroller project.").arg(pSet->name())
|
|
|
|
);
|
|
|
|
ui->cbCompilerSet->setCurrentIndex(project->options().compilerSet);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-17 13:53:22 +08:00
|
|
|
#endif
|
2023-04-03 09:39:45 +08:00
|
|
|
if (QMessageBox::warning(
|
|
|
|
this,
|
2023-08-17 19:24:49 +08:00
|
|
|
tr("Change Project Compiler Set"),
|
|
|
|
tr("Change the project's compiler set will lose all custom compiler set options.")
|
2023-04-03 09:39:45 +08:00
|
|
|
+"<br />"
|
2023-08-17 19:24:49 +08:00
|
|
|
+ tr("Do you really want to do that?"),
|
2023-04-03 09:39:45 +08:00
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
|
QMessageBox::No) != QMessageBox::Yes) {
|
|
|
|
ui->cbCompilerSet->setCurrentIndex(project->options().compilerSet);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
project->setCompilerSet(index);
|
|
|
|
project->saveOptions();
|
2021-09-15 11:23:42 +08:00
|
|
|
}
|
2021-09-15 12:19:09 +08:00
|
|
|
|
2022-07-04 11:39:06 +08:00
|
|
|
void ProjectCompilerWidget::on_cbEncoding_currentTextChanged(const QString &/*arg1*/)
|
2022-06-22 17:08:35 +08:00
|
|
|
{
|
|
|
|
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*/)
|
2022-06-22 17:08:35 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|