work save

This commit is contained in:
Roy Qu 2022-05-13 20:22:16 +08:00
parent 2f5f1346fd
commit 58b7c55cd6
13 changed files with 665 additions and 300 deletions

View File

@ -46,6 +46,7 @@ SOURCES += \
codeformatter.cpp \
codesnippetsmanager.cpp \
colorscheme.cpp \
compiler/compilerinfo.cpp \
compiler/ojproblemcasesrunner.cpp \
compiler/projectcompiler.cpp \
compiler/runner.cpp \
@ -157,6 +158,7 @@ SOURCES += \
systemconsts.cpp \
utils.cpp \
widgets/coloredit.cpp \
widgets/compileargumentswidget.cpp \
widgets/consolewidget.cpp \
widgets/customdisablediconengine.cpp \
widgets/customfilesystemmodel.cpp \
@ -194,6 +196,7 @@ HEADERS += \
codesnippetsmanager.h \
colorscheme.h \
compiler/compiler.h \
compiler/compilerinfo.h \
compiler/compilermanager.h \
compiler/executablerunner.h \
compiler/filecompiler.h \
@ -304,6 +307,7 @@ HEADERS += \
utils.h \
common.h \
widgets/coloredit.h \
widgets/compileargumentswidget.h \
widgets/consolewidget.h \
widgets/customdisablediconengine.h \
widgets/customfilesystemmodel.h \
@ -381,6 +385,7 @@ FORMS += \
settingsdialog/executorgeneralwidget.ui \
settingsdialog/settingsdialog.ui \
widgets/custommakefileinfodialog.ui \
widgets/compileargumentswidget.ui \
widgets/filepropertiesdialog.ui \
widgets/infomessagebox.ui \
widgets/newclassdialog.ui \
@ -451,40 +456,40 @@ RESOURCES += \
RC_ICONS = images/devcpp.ico images/associations/c.ico images/associations/cpp.ico images/associations/dev.ico images/associations/c.ico images/associations/cpp.ico images/associations/h.ico images/associations/hpp.ico
# fixed lrelease.prf
qtPrepareTool(QMAKE_LRELEASE, lrelease)
#qtPrepareTool(QMAKE_LRELEASE, lrelease)
isEmpty(LRELEASE_DIR): LRELEASE_DIR = .qm
isEmpty(QM_FILES_RESOURCE_PREFIX): QM_FILES_RESOURCE_PREFIX = i18n
#isEmpty(LRELEASE_DIR): LRELEASE_DIR = .qm
#isEmpty(QM_FILES_RESOURCE_PREFIX): QM_FILES_RESOURCE_PREFIX = i18n
lrelease.name = lrelease
lrelease.input = TRANSLATIONS EXTRA_TRANSLATIONS
lrelease.output = $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm
lrelease.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} $$QMAKE_LRELEASE_FLAGS -qm ${QMAKE_FILE_OUT}
silent: lrelease.commands = @echo lrelease ${QMAKE_FILE_IN} && $$lrelease.commands
lrelease.CONFIG = no_link target_predeps
QMAKE_EXTRA_COMPILERS += lrelease
#lrelease.name = lrelease
#lrelease.input = TRANSLATIONS EXTRA_TRANSLATIONS
#lrelease.output = $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm
#lrelease.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} $$QMAKE_LRELEASE_FLAGS -qm ${QMAKE_FILE_OUT}
#silent: lrelease.commands = @echo lrelease ${QMAKE_FILE_IN} && $$lrelease.commands
#lrelease.CONFIG = no_link target_predeps
#QMAKE_EXTRA_COMPILERS += lrelease
all_translations = $$TRANSLATIONS $$EXTRA_TRANSLATIONS
for (translation, all_translations) {
# mirrors $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm above
translation = $$basename(translation)
QM_FILES += $$OUT_PWD/$$LRELEASE_DIR/$$replace(translation, \\..*$, .qm)
}
#all_translations = $$TRANSLATIONS $$EXTRA_TRANSLATIONS
#for (translation, all_translations) {
# # mirrors $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm above
# translation = $$basename(translation)
# QM_FILES += $$OUT_PWD/$$LRELEASE_DIR/$$replace(translation, \\..*$, .qm)
#}
qmake_qm_files.files = $$QM_FILES
qmake_qm_files.base = $$OUT_PWD/$$LRELEASE_DIR
qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX
#qmake_qm_files.files = $$QM_FILES
#qmake_qm_files.base = $$OUT_PWD/$$LRELEASE_DIR
#qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX
iconsets_files.files += $$files(resources/iconsets/*.svg, true)
iconsets_files.files += $$files(resources/iconsets/*.json, true)
#iconsets_files.files += $$files(resources/iconsets/*.svg, true)
#iconsets_files.files += $$files(resources/iconsets/*.json, true)
theme_files.files += $$files(themes/*.json, false)
theme_files.files += $$files(themes/*.png, false)
#theme_files.files += $$files(themes/*.json, false)
#theme_files.files += $$files(themes/*.png, false)
colorscheme_files.files += $$files(colorschemes/*.scheme, false)
colorscheme_files.prefix = /colorschemes
#colorscheme_files.files += $$files(colorschemes/*.scheme, false)
#colorscheme_files.prefix = /colorschemes
RESOURCES += qmake_qm_files
RESOURCES += iconsets_files
RESOURCES += theme_files
RESOURCES += colorscheme_files
#RESOURCES += qmake_qm_files
#RESOURCES += iconsets_files
#RESOURCES += theme_files
#RESOURCES += colorscheme_files

View File

@ -347,7 +347,7 @@ QString Compiler::getCCompileArguments(bool checkSyntax)
compileOptions = compilerSet()->compileOptions();
}
foreach (const QString& key, compilerSet()->compileOptions()) {
PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key);
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerSet()->CCompiler(), key);
if (pOption && pOption->isC && !pOption->isLinker) {
result += " " + pOption->setting + compilerSet()->getCompileOptionValue(key);
}
@ -380,7 +380,7 @@ QString Compiler::getCppCompileArguments(bool checkSyntax)
compileOptions = compilerSet()->compileOptions();
}
foreach (const QString& key, compilerSet()->compileOptions()) {
PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key);
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerSet()->CCompiler(), key);
if (pOption && pOption->isCpp && !pOption->isLinker) {
result += " " + pOption->setting + compilerSet()->getCompileOptionValue(key);
}
@ -484,7 +484,7 @@ QString Compiler::getLibraryArguments(FileType fileType)
compileOptions = compilerSet()->compileOptions();
}
foreach (const QString& key, compilerSet()->compileOptions()) {
PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key);
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerSet()->CCompiler(), key);
if (pOption->isLinker) {
result += " " + pOption->setting + compilerSet()->getCompileOptionValue(key);
}

View File

@ -0,0 +1,234 @@
#include "compilerinfo.h"
#include <QObject>
CompilerInfo::CompilerInfo(const QString &name):
mName(name)
{
prepareCompilerOptions();
}
const CompilerOptionMap &CompilerInfo::compilerOptions() const
{
return mCompilerOptions;
}
const QString &CompilerInfo::name() const
{
return mName;
}
PCompilerOption CompilerInfo::getCompilerOption(const QString &key) const
{
return mCompilerOptions.value(key,PCompilerOption());
}
void CompilerInfo::addOption(const QString &key, const QString &name, const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting, const CompileOptionChoiceList &choices)
{
PCompilerOption pOption = std::make_shared<CompilerOption>();
pOption->key = key;
pOption->name = name;
pOption->section = section;
pOption->isC = isC;
pOption->isCpp = isCpp;
pOption->isLinker = isLinker;
pOption->setting= setting;
pOption->choices = choices;
mCompilerOptions.insert(key,pOption);
}
void CompilerInfo::prepareCompilerOptions()
{
// C options
QString groupName = QObject::tr("C options");
addOption(CC_CMD_OPT_ANSI, QObject::tr("Support all ANSI standard C programs (-ansi)"), groupName, true, true, false, "-ansi");
addOption(CC_CMD_OPT_NO_ASM, QObject::tr("Do not recognize asm,inline or typeof as a keyword (-fno-asm)"), groupName, true, true, false, "-fno-asm");
addOption(CC_CMD_OPT_TRADITIONAL_CPP, QObject::tr("Imitate traditional C preprocessors (-traditional-cpp)"), groupName, true, true, false, "-traditional-cpp");
// Optimization for cpu type
groupName = QObject::tr("Code Generation");
QList<QPair<QString,QString>> sl;
sl.append(QPair<QString,QString>(QObject::tr("This CPU"),"native"));
sl.append(QPair<QString,QString>("i386","i386"));
sl.append(QPair<QString,QString>("i486","i486"));
sl.append(QPair<QString,QString>("i586","i586"));
sl.append(QPair<QString,QString>("i686","i686"));
sl.append(QPair<QString,QString>("Pentium","pentium"));
sl.append(QPair<QString,QString>("Pentium MMX","pentium-mmx"));
sl.append(QPair<QString,QString>("Pentium Pro","pentiumpro"));
sl.append(QPair<QString,QString>("Pentium 2","pentium2"));
sl.append(QPair<QString,QString>("Pentium 3","pentium3"));
sl.append(QPair<QString,QString>("Pentium 4","pentium4"));
sl.append(QPair<QString,QString>("Conroe","core2"));
sl.append(QPair<QString,QString>("Nehalem","corei7"));
sl.append(QPair<QString,QString>("Sandy","corei7-avx"));
sl.append(QPair<QString,QString>("K6","k6"));
sl.append(QPair<QString,QString>("K6-2","k6-2"));
sl.append(QPair<QString,QString>("K6-3","k6-3"));
sl.append(QPair<QString,QString>("Athlon","athlon"));
sl.append(QPair<QString,QString>("Athlon Tbird","athlon-tbird"));
sl.append(QPair<QString,QString>("Athlon 4","athlon-4"));
sl.append(QPair<QString,QString>("Athlon XP","athlon-xp"));
sl.append(QPair<QString,QString>("Athlon MP","athlon-mp"));
sl.append(QPair<QString,QString>("K8","k8"));
sl.append(QPair<QString,QString>("K8 Rev.E","k8-sse3"));
sl.append(QPair<QString,QString>("K10","barcelona"));
sl.append(QPair<QString,QString>("Bulldozer","bdver1"));
addOption("gcc_cmd_opt_arch", QObject::tr("Optimize for the following machine (-march)"), groupName, true, true, false, "-march=", sl);
addOption("gcc_cmd_opt_tune", QObject::tr("Optimize less, while maintaining full compatibility (-tune)"), groupName, true, true, false, "-mtune=", sl);
// Enable use of the specific instructions
sl.clear();
sl.append(QPair<QString,QString>("MMX","mmx"));
sl.append(QPair<QString,QString>("3D Now","3dnow"));
sl.append(QPair<QString,QString>("SSE","sse"));
sl.append(QPair<QString,QString>("SSE2","sse2"));
sl.append(QPair<QString,QString>("SSE3","sse3"));
sl.append(QPair<QString,QString>("SSSE3","ssse3"));
sl.append(QPair<QString,QString>("SSE4","sse4"));
sl.append(QPair<QString,QString>("SSE4A","sse4a"));
sl.append(QPair<QString,QString>("SSE4.1","sse4.1"));
sl.append(QPair<QString,QString>("SSE4.2","sse4.2"));
sl.append(QPair<QString,QString>("AVX","avx"));
sl.append(QPair<QString,QString>("AVX2","avx2"));
sl.append(QPair<QString,QString>("FMA4","fma4"));
sl.append(QPair<QString,QString>("XOP","xop"));
sl.append(QPair<QString,QString>("AES","aes"));
addOption("gcc_cmd_opt_instruction",QObject::tr("Enable use of specific instructions (-mx)"), groupName, true, true, false, "-m", sl);
// Optimization
sl.clear();
sl.append(QPair<QString,QString>("Low","1"));
sl.append(QPair<QString,QString>("Med","2"));
sl.append(QPair<QString,QString>("High","3"));
sl.append(QPair<QString,QString>("Highest (fast)","fast"));
sl.append(QPair<QString,QString>("Size (s)","s"));
sl.append(QPair<QString,QString>("Debug (g)","g"));
addOption("gcc_cmd_opt_optimize", QObject::tr("Optimization level (-Ox)"), groupName, true, true, false, "-O", sl);
// 32bit/64bit
sl.clear();
sl.append(QPair<QString,QString>("32bit","32"));
sl.append(QPair<QString,QString>("64bit","64"));
addOption("gcc_cmd_opt_pointer_size", QObject::tr("Compile with the following pointer size (-mx)"), groupName, true, true, true, "-m", sl);
// Language Standards
sl.clear();
sl.append(QPair<QString,QString>("ISO C90","c90"));
sl.append(QPair<QString,QString>("ISO C99","c99"));
sl.append(QPair<QString,QString>("ISO C11","c11"));
sl.append(QPair<QString,QString>("ISO C17","c17"));
sl.append(QPair<QString,QString>("ISO C++","c++98"));
sl.append(QPair<QString,QString>("ISO C++11","c++11"));
sl.append(QPair<QString,QString>("ISO C++14","c++14"));
sl.append(QPair<QString,QString>("ISO C++17","c++17"));
sl.append(QPair<QString,QString>("ISO C++20","c++2a"));
sl.append(QPair<QString,QString>("GNU C90","gnu90"));
sl.append(QPair<QString,QString>("GNU C99","gnu99"));
sl.append(QPair<QString,QString>("GNU C11","gnu11"));
sl.append(QPair<QString,QString>("GNU C17","gnu17"));
sl.append(QPair<QString,QString>("GNU C++","gnu++98"));
sl.append(QPair<QString,QString>("GNU C++11","gnu++11"));
sl.append(QPair<QString,QString>("GNU C++14","gnu++14"));
sl.append(QPair<QString,QString>("GNU C++17","gnu++17"));
sl.append(QPair<QString,QString>("GNU C++20","gnu++2a"));
addOption("gcc_cmd_opt_std", QObject::tr("Language standard (-std)"), groupName, true, true, false, "-std=", sl);
// Warnings
groupName = QObject::tr("Warnings");
addOption("gcc_cmd_opt_inhibit_all_warning", QObject::tr("Inhibit all warning messages (-w)"), groupName, true, true, false, "-w");
addOption("gcc_cmd_opt_warning_all",QObject::tr("Show most warnings (-Wall)"), groupName, true, true, false, "-Wall");
addOption("gcc_cmd_opt_warning_extra",QObject::tr("Show some more warnings (-Wextra)"), groupName, true, true, false, "-Wextra");
addOption("gcc_cmd_opt_check_iso_conformance", QObject::tr("Check ISO C/C++/C++0x conformance (-pedantic)"), groupName, true, true, false, "-pedantic");
addOption("gcc_cmd_opt_syntax_only", QObject::tr("Only check the code for syntax errors (-fsyntax-only)"), groupName, true, true, false, "-fsyntax-only");
addOption("gcc_cmd_opt_warning_as_error", QObject::tr("Make all warnings into errors (-Werror)"), groupName, true, true, false, "-Werror");
addOption("gcc_cmd_opt_abort_on_error", QObject::tr("Abort compilation on first error (-Wfatal-errors)"), groupName, true, true, false, "-Wfatal-errors");
// Profile
groupName = QObject::tr("Profile");
addOption("gcc_cmd_opt_profile_info",QObject::tr("Generate profiling info for analysis (-pg)"), groupName, true, true, true, "-pg");
// Linker
groupName = QObject::tr("Linker");
addOption("linker_cmd_opt_link_objc", QObject::tr("Link an Objective C program (-lobjc)"), groupName, false, false, true, "-lobjc");
addOption("linker_cmd_opt_no_link_stdlib",QObject::tr("Do not use standard system libraries (-nostdlib)"), groupName, false, false, true, "-nostdlib");
addOption("linker_cmd_opt_no_console", QObject::tr("Do not create a console window (-mwindows)"), groupName,false, false, true, "-mwindows");
addOption("linker_cmd_opt_strip_exe", QObject::tr("Strip executable (-s)"), groupName, false, false, true, "-s");
addOption("cc_cmd_opt_debug_info", QObject::tr("Generate debugging information (-g3)"), groupName, true, true, false, "-g3");
// Output
groupName = QObject::tr("Output");
addOption("cc_cmd_opt_verbose_asm", QObject::tr("Put comments in generated assembly code (-fverbose-asm)"), groupName, true, true, false, "-fverbose-asm");
addOption("cc_cmd_opt_only_gen_asm_code", QObject::tr("Do not assemble, compile and generate the assemble code (-S)"), groupName, true, true, false, "-S");
addOption("cc_cmd_opt_use_pipe", QObject::tr("Use pipes instead of temporary files during compilation (-pipe)"), groupName, true, true, false, "-pipe");
}
PCompilerInfo CompilerInfoManager::getInfo(const QString &compilerType)
{
return getInstance()->mInfos.value(compilerType,PCompilerInfo());
}
bool CompilerInfoManager::hasCompilerOption(const QString &compilerType, const QString &optKey)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return false;
return pInfo->compilerOptions().contains(optKey);
}
PCompilerOption CompilerInfoManager::getCompilerOption(const QString &compilerType, const QString &optKey)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return PCompilerOption();
return pInfo->compilerOptions().value(optKey,PCompilerOption());
}
CompilerOptionMap CompilerInfoManager::getCompilerOptions(const QString &compilerType)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return CompilerOptionMap();
return pInfo->compilerOptions();
}
bool CompilerInfoManager::supportCovertingCharset(const QString &compilerType)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return false;
return pInfo->supportConvertingCharset();
}
PCompilerInfoManager CompilerInfoManager::getInstance()
{
if (!instance) {
instance = std::make_shared<CompilerInfoManager>();
}
return instance;
}
void CompilerInfoManager::addInfo(const QString &name, PCompilerInfo info)
{
getInstance()->mInfos.insert(name,info);
}
ClangCompilerInfo::ClangCompilerInfo():CompilerInfo(COMPILER_CLANG)
{
}
bool ClangCompilerInfo::supportConvertingCharset()
{
return false;
}
GCCCompilerInfo::GCCCompilerInfo():CompilerInfo(COMPILER_GCC)
{
}
bool GCCCompilerInfo::supportConvertingCharset()
{
return true;
}

View File

@ -0,0 +1,130 @@
#ifndef COMPILERINFO_H
#define COMPILERINFO_H
#include <QString>
#include <QMap>
#include <memory>
#include <QMutex>
#define COMPILER_CLANG "Clang"
#define COMPILER_GCC "GCC"
#define CC_CMD_OPT_ANSI "cc_cmd_opt_ansi"
#define CC_CMD_OPT_NO_ASM "cc_cmd_opt_no_asm"
#define CC_CMD_OPT_TRADITIONAL_CPP "cc_cmd_opt_traditional_cpp"
#define CC_CMD_OPT_ARCH "cc_cmd_opt_arch"
#define CC_CMD_OPT_TUNE "cc_cmd_opt_tune"
#define CC_CMD_OPT_INSTRUCTION "cc_cmd_opt_instruction"
#define CC_CMD_OPT_OPTIMIZE "cc_cmd_opt_optimize"
#define CC_CMD_OPT_POINTER_SIZE "cc_cmd_opt_pointer_size"
#define CC_CMD_OPT_STD "cc_cmd_opt_std"
#define CC_CMD_OPT_INHIBIT_ALL_WARNING "cc_cmd_opt_inhibit_all_warning"
#define CC_CMD_OPT_WARNING_ALL "cc_cmd_opt_warning_all"
#define CC_CMD_OPT_WARNING_EXTRA "cc_cmd_opt_warning_extra"
#define CC_CMD_OPT_CHECK_ISO_CONFORMANCE "cc_cmd_opt_check_iso_conformance"
#define CC_CMD_OPT_SYNTAX_ONLY "cc_cmd_opt_syntax_only"
#define CC_CMD_OPT_WARNING_AS_ERROR "cc_cmd_opt_warning_as_error"
#define CC_CMD_OPT_ABORT_ON_ERROR "cc_cmd_opt_abort_on_error"
#define CC_CMD_OPT_PROFILE_INFO "cc_cmd_opt_profile_info"
#define LINK_CMD_OPT_LINK_OBJC "link_cmd_opt_link_objc"
#define LINK_CMD_OPT_NO_LINK_STDLIB "link_cmd_opt_no_link_stdlib"
#define LINK_CMD_OPT_NO_CONSOLE "link_cmd_opt_no_console"
#define LINK_CMD_OPT_STRIP_EXE "link_cmd_opt_strip_exe"
#define CC_CMD_OPT_DEBUG_INFO "cc_cmd_opt_debug_info"
#define CC_CMD_OPT_VERBOSE_ASM "cc_cmd_opt_verbose_asm"
#define CC_CMD_OPT_ONLY_GEN_ASM_CODE "cc_cmd_opt_only_gen_asm_code"
#define CC_CMD_OPT_USE_PIPE "cc_cmd_opt_use_pipe"
#define COMPILER_OPTION_ON "on"
using CompileOptionChoiceList = QList<QPair<QString,QString>>;
typedef struct {
QString key;
QString name; // "Generate debugging info"
QString section; // "C options"
bool isC;
bool isCpp; // True (C++ option?) - can be both C and C++ option...
bool isLinker; // Is it a linker param
QString setting; // "-g3"
CompileOptionChoiceList choices; // replaces "Yes/No" standard choices (max 30 different choices)
} CompilerOption;
using PCompilerOption = std::shared_ptr<CompilerOption>;
using CompilerOptionMap=QMap<QString,std::shared_ptr<CompilerOption>>;
class CompilerInfo
{
public:
CompilerInfo(const QString& name);
const CompilerOptionMap &compilerOptions() const;
const QString &name() const;
PCompilerOption getCompilerOption(const QString& key) const;
virtual bool supportConvertingCharset()=0;
protected:
void addOption(const QString& key,
const QString& name,
const QString section,
bool isC,
bool isCpp,
bool isLinker,
const QString& setting,
const CompileOptionChoiceList& choices = CompileOptionChoiceList());
virtual void prepareCompilerOptions();
protected:
CompilerOptionMap mCompilerOptions;
QString mName;
};
using PCompilerInfo = std::shared_ptr<CompilerInfo>;
class CompilerInfoManager;
using PCompilerInfoManager = std::shared_ptr<CompilerInfoManager>;
class CompilerInfoManager {
public:
static PCompilerInfo getInfo(const QString& compilerType);
static bool hasCompilerOption(const QString& compilerType, const QString& optKey);
static PCompilerOption getCompilerOption(const QString& compilerType, const QString& optKey);
static CompilerOptionMap getCompilerOptions(const QString& compilerType);
static bool supportCovertingCharset(const QString& compilerType);
static PCompilerInfoManager getInstance();
static void addInfo(const QString& name, PCompilerInfo info);
private:
CompilerInfoManager();
static PCompilerInfoManager instance;
QMap<QString,PCompilerInfo> mInfos;
};
extern PCompilerInfoManager pCompilerInfoManager;
class ClangCompilerInfo: public CompilerInfo{
public:
ClangCompilerInfo();
// CompilerInfo interface
protected:
void prepareCompilerOptions() Q_DECL_OVERRIDE;
bool supportConvertingCharset() Q_DECL_OVERRIDE;
};
class GCCCompilerInfo: public CompilerInfo{
public:
GCCCompilerInfo();
// CompilerInfo interface
protected:
void prepareCompilerOptions() Q_DECL_OVERRIDE;
bool supportConvertingCharset() Q_DECL_OVERRIDE;
};
#endif // COMPILERINFO_H

View File

@ -689,19 +689,37 @@ void Project::associateEditorToUnit(Editor *editor, PProjectUnit unit)
}
}
bool Project::setCompileOption(const QString &key, int valIndex)
{
PCompilerOption op = pSettings->compilerSets().getCompilerOption(key);
if (op && valIndex>=0 && valIndex < op->choices.length()) {
mOptions.compilerOptions.insert(key,op->choices[valIndex].second);
return true;
}
return false;
}
//bool Project::setCompileOption(const QString &key, int valIndex)
//{
// Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(mOptions.compilerSet);
// if (!pSet)
// return false;
// PCompilerOption op = CompilerInfoManager::getCompilerOption(
// pSet->compilerType(), key);
// if (!op)
// return false;
// if (op->choices.isEmpty()) {
// if (valIndex>0)
// mOptions.compilerOptions.insert(key,COMPILER_OPTION_ON);
// else
// mOptions.compilerOptions.insert(key,"");
// } else {
// if (valIndex>0 && valIndex <= op->choices.length()) {
// mOptions.compilerOptions.insert(key,op->choices[valIndex-1].second);
// } else {
// mOptions.compilerOptions.insert(key,"");
// }
// }
// return true;
//}
bool Project::setCompileOption(const QString &key, const QString &value)
{
PCompilerOption op = pSettings->compilerSets().getCompilerOption(key);
Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(mOptions.compilerSet);
if (!pSet)
return false;
PCompilerOption op = CompilerInfoManager::getCompilerOption(
pSet->compilerType(), key);
if (!op)
return false;
mOptions.compilerOptions.insert(key,value);
@ -1533,8 +1551,8 @@ void Project::loadOptions(SimpleIni& ini)
}
mOptions.version = ini.GetLongValue("Project", "Ver", 0);
if (mOptions.version > 0) { // ver > 0 is at least a v5 project
if (mOptions.version < 2) {
mOptions.version = 2;
if (mOptions.version < 3) {
mOptions.version = 3;
QMessageBox::information(nullptr,
tr("Settings need update"),
tr("The compiler settings format of Red Panda C++ has changed.")
@ -1585,29 +1603,36 @@ void Project::loadOptions(SimpleIni& ini)
setCompilerSet(pSettings->compilerSets().defaultIndex());
}
Settings::PCompilerSet pSet = pSettings->compilerSets().getSet(mOptions.compilerSet);
if (pSet) {
QByteArray oldCompilerOptions = ini.GetValue("Project", "CompilerSettings", "");
if (!oldCompilerOptions.isEmpty()) {
//version 2 compatibility
for (int i=0;i<oldCompilerOptions.length();i++) {
QString key = pSettings->compilerSets().getKeyFromCompilerCompatibleIndex(i);
PCompilerOption pOption = pSettings->compilerSets().getCompilerOption(key);
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(
pSet->compilerType(), key);
if (pOption) {
int val = Settings::CompilerSet::charToValue(oldCompilerOptions[i]);
if (pOption->choices.isEmpty()) {
if (val>0)
mOptions.compilerOptions.insert(key,COMPILER_OPTION_ON);
else
mOptions.compilerOptions.insert(key,"");
} else {
if (val>0 && val <= pOption->choices.length())
mOptions.compilerOptions.insert(key,pOption->choices[val-1].second);
else
mOptions.compilerOptions.insert(key,"");
}
}
}
} else {
//version 3
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, ""));
@ -1649,7 +1674,7 @@ void Project::loadOptions(SimpleIni& ini)
mOptions.versionInfo.syncProduct = ini.GetBoolValue("VersionInfo", "SyncProduct", false);
} else { // dev-c < 4
mOptions.version = 2;
mOptions.version = 3;
if (!ini.GetBoolValue("VersionInfo", "NoConsole", true))
mOptions.type = ProjectType::Console;
else if (ini.GetBoolValue("VersionInfo", "IsDLL", false))

View File

@ -210,8 +210,7 @@ public:
PProjectUnit findUnitByFilename(const QString& filename);
void associateEditor(Editor* editor);
void associateEditorToUnit(Editor* editor, PProjectUnit unit);
void setCompilerOption(const QString& optionString, char value);
bool setCompileOption(const QString &key, int valIndex);
// bool setCompileOption(const QString &key, int valIndex);
bool setCompileOption(const QString &key, const QString &value);
void updateFolders();

View File

@ -40,7 +40,7 @@ ProjectVersionInfo::ProjectVersionInfo()
ProjectOptions::ProjectOptions()
{
type = ProjectType::GUI;
version = 2;
version = 3;
isCpp = false;
logOutputEnabled = false;
useCustomMakefile = false;

View File

@ -1494,15 +1494,20 @@ Settings::CompilerSet::CompilerSet(const Settings::CompilerSet &set):
bool Settings::CompilerSet::setCompileOption(const QString &key, int valIndex)
{
PCompilerOption op = pSettings->compilerSets().getCompilerOption(key);
PCompilerOption op = CompilerInfoManager::getCompilerOption(mCompilerType, key);
if (!op)
return false;
if (op->choices.isEmpty()) {
if (valIndex==1)
mCompileOptions.insert(key,"");
mCompileOptions.insert(key,COMPILER_OPTION_ON);
else
mCompileOptions.remove(key);
return true;
} else if (valIndex>0 && valIndex <= op->choices.length()) {
mCompileOptions.insert(key,op->choices[valIndex].second);
mCompileOptions.insert(key,op->choices[valIndex-1].second);
return true;
} else {
mCompileOptions.remove(key);
return true;
}
return false;
@ -1510,7 +1515,7 @@ bool Settings::CompilerSet::setCompileOption(const QString &key, int valIndex)
bool Settings::CompilerSet::setCompileOption(const QString &key, const QString &value)
{
PCompilerOption op = pSettings->compilerSets().getCompilerOption(key);
PCompilerOption op = CompilerInfoManager::getCompilerOption(mCompilerType,key);
if (!op)
return false;
mCompileOptions.insert(key,value);
@ -2306,7 +2311,7 @@ Settings::CompilerSets::CompilerSets(Settings *settings):
mDefaultIndex(-1),
mSettings(settings)
{
initOptions();
prepareCompatibleIndex();
}
Settings::PCompilerSet Settings::CompilerSets::addSet(const Settings::CompilerSet& set)
@ -2329,16 +2334,16 @@ static void set64_32Options(Settings::PCompilerSet pSet) {
static void setReleaseOptions(Settings::PCompilerSet pSet) {
pSet->setCompileOption(CC_CMD_OPT_OPTIMIZE,"2");
pSet->setCompileOption(LINK_CMD_OPT_STRIP_EXE,"");
pSet->setCompileOption(CC_CMD_OPT_USE_PIPE, "");
pSet->setCompileOption(LINK_CMD_OPT_STRIP_EXE, COMPILER_OPTION_ON);
pSet->setCompileOption(CC_CMD_OPT_USE_PIPE, COMPILER_OPTION_ON);
pSet->setStaticLink(true);
}
static void setDebugOptions(Settings::PCompilerSet pSet) {
pSet->setCompileOption(CC_CMD_OPT_DEBUG_INFO,"");
pSet->setCompileOption(CC_CMD_OPT_WARNING_ALL,"");
pSet->setCompileOption(CC_CMD_OPT_WARNING_EXTRA,"");
pSet->setCompileOption(CC_CMD_OPT_USE_PIPE,"");
pSet->setCompileOption(CC_CMD_OPT_DEBUG_INFO, COMPILER_OPTION_ON);
pSet->setCompileOption(CC_CMD_OPT_WARNING_ALL, COMPILER_OPTION_ON);
pSet->setCompileOption(CC_CMD_OPT_WARNING_EXTRA, COMPILER_OPTION_ON);
pSet->setCompileOption(CC_CMD_OPT_USE_PIPE, COMPILER_OPTION_ON);
#ifdef Q_OS_LINUX
pSet->setCustomCompileParams("-fsanitize=address");
@ -2722,7 +2727,7 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index)
pSet->setIniOptions(iniOptions);
else {
foreach (const QString &optionKey, mSettings->mSettings.allKeys()) {
if (mCompilerOptions.contains(optionKey)) {
if (CompilerInfoManager::hasCompilerOption(pSet->compilerType(),optionKey)) {
pSet->setCompileOption(optionKey, mSettings->mSettings.value(optionKey).toString());
}
}
@ -2764,131 +2769,8 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index)
return pSet;
}
void Settings::CompilerSets::initOptions()
void Settings::CompilerSets::prepareCompatibleIndex()
{
// C options
QString groupName = QObject::tr("C options");
addOption(CC_CMD_OPT_ANSI, QObject::tr("Support all ANSI standard C programs (-ansi)"), groupName, true, true, false, "-ansi");
addOption(CC_CMD_OPT_NO_ASM, QObject::tr("Do not recognize asm,inline or typeof as a keyword (-fno-asm)"), groupName, true, true, false, "-fno-asm");
addOption(CC_CMD_OPT_TRADITIONAL_CPP, QObject::tr("Imitate traditional C preprocessors (-traditional-cpp)"), groupName, true, true, false, "-traditional-cpp");
// Optimization for cpu type
groupName = QObject::tr("Code Generation");
QList<QPair<QString,QString>> sl;
sl.append(QPair<QString,QString>(QObject::tr("This CPU"),"native"));
sl.append(QPair<QString,QString>("i386","i386"));
sl.append(QPair<QString,QString>("i486","i486"));
sl.append(QPair<QString,QString>("i586","i586"));
sl.append(QPair<QString,QString>("i686","i686"));
sl.append(QPair<QString,QString>("Pentium","pentium"));
sl.append(QPair<QString,QString>("Pentium MMX","pentium-mmx"));
sl.append(QPair<QString,QString>("Pentium Pro","pentiumpro"));
sl.append(QPair<QString,QString>("Pentium 2","pentium2"));
sl.append(QPair<QString,QString>("Pentium 3","pentium3"));
sl.append(QPair<QString,QString>("Pentium 4","pentium4"));
sl.append(QPair<QString,QString>("Conroe","core2"));
sl.append(QPair<QString,QString>("Nehalem","corei7"));
sl.append(QPair<QString,QString>("Sandy","corei7-avx"));
sl.append(QPair<QString,QString>("K6","k6"));
sl.append(QPair<QString,QString>("K6-2","k6-2"));
sl.append(QPair<QString,QString>("K6-3","k6-3"));
sl.append(QPair<QString,QString>("Athlon","athlon"));
sl.append(QPair<QString,QString>("Athlon Tbird","athlon-tbird"));
sl.append(QPair<QString,QString>("Athlon 4","athlon-4"));
sl.append(QPair<QString,QString>("Athlon XP","athlon-xp"));
sl.append(QPair<QString,QString>("Athlon MP","athlon-mp"));
sl.append(QPair<QString,QString>("K8","k8"));
sl.append(QPair<QString,QString>("K8 Rev.E","k8-sse3"));
sl.append(QPair<QString,QString>("K10","barcelona"));
sl.append(QPair<QString,QString>("Bulldozer","bdver1"));
addOption("gcc_cmd_opt_arch", QObject::tr("Optimize for the following machine (-march)"), groupName, true, true, false, "-march=", sl);
addOption("gcc_cmd_opt_tune", QObject::tr("Optimize less, while maintaining full compatibility (-tune)"), groupName, true, true, false, "-mtune=", sl);
// Enable use of the specific instructions
sl.clear();
sl.append(QPair<QString,QString>("MMX","mmx"));
sl.append(QPair<QString,QString>("3D Now","3dnow"));
sl.append(QPair<QString,QString>("SSE","sse"));
sl.append(QPair<QString,QString>("SSE2","sse2"));
sl.append(QPair<QString,QString>("SSE3","sse3"));
sl.append(QPair<QString,QString>("SSSE3","ssse3"));
sl.append(QPair<QString,QString>("SSE4","sse4"));
sl.append(QPair<QString,QString>("SSE4A","sse4a"));
sl.append(QPair<QString,QString>("SSE4.1","sse4.1"));
sl.append(QPair<QString,QString>("SSE4.2","sse4.2"));
sl.append(QPair<QString,QString>("AVX","avx"));
sl.append(QPair<QString,QString>("AVX2","avx2"));
sl.append(QPair<QString,QString>("FMA4","fma4"));
sl.append(QPair<QString,QString>("XOP","xop"));
sl.append(QPair<QString,QString>("AES","aes"));
addOption("gcc_cmd_opt_instruction",QObject::tr("Enable use of specific instructions (-mx)"), groupName, true, true, false, "-m", sl);
// Optimization
sl.clear();
sl.append(QPair<QString,QString>("Low","1"));
sl.append(QPair<QString,QString>("Med","2"));
sl.append(QPair<QString,QString>("High","3"));
sl.append(QPair<QString,QString>("Highest (fast)","fast"));
sl.append(QPair<QString,QString>("Size (s)","s"));
sl.append(QPair<QString,QString>("Debug (g)","g"));
addOption("gcc_cmd_opt_optimize", QObject::tr("Optimization level (-Ox)"), groupName, true, true, false, "-O", sl);
// 32bit/64bit
sl.clear();
sl.append(QPair<QString,QString>("32bit","32"));
sl.append(QPair<QString,QString>("64bit","64"));
addOption("gcc_cmd_opt_pointer_size", QObject::tr("Compile with the following pointer size (-mx)"), groupName, true, true, true, "-m", sl);
// Language Standards
sl.clear();
sl.append(QPair<QString,QString>("ISO C90","c90"));
sl.append(QPair<QString,QString>("ISO C99","c99"));
sl.append(QPair<QString,QString>("ISO C11","c11"));
sl.append(QPair<QString,QString>("ISO C17","c17"));
sl.append(QPair<QString,QString>("ISO C++","c++98"));
sl.append(QPair<QString,QString>("ISO C++11","c++11"));
sl.append(QPair<QString,QString>("ISO C++14","c++14"));
sl.append(QPair<QString,QString>("ISO C++17","c++17"));
sl.append(QPair<QString,QString>("ISO C++20","c++2a"));
sl.append(QPair<QString,QString>("GNU C90","gnu90"));
sl.append(QPair<QString,QString>("GNU C99","gnu99"));
sl.append(QPair<QString,QString>("GNU C11","gnu11"));
sl.append(QPair<QString,QString>("GNU C17","gnu17"));
sl.append(QPair<QString,QString>("GNU C++","gnu++98"));
sl.append(QPair<QString,QString>("GNU C++11","gnu++11"));
sl.append(QPair<QString,QString>("GNU C++14","gnu++14"));
sl.append(QPair<QString,QString>("GNU C++17","gnu++17"));
sl.append(QPair<QString,QString>("GNU C++20","gnu++2a"));
addOption("gcc_cmd_opt_std", QObject::tr("Language standard (-std)"), groupName, true, true, false, "-std=", sl);
// Warnings
groupName = QObject::tr("Warnings");
addOption("gcc_cmd_opt_inhibit_all_warning", QObject::tr("Inhibit all warning messages (-w)"), groupName, true, true, false, "-w");
addOption("gcc_cmd_opt_warning_all",QObject::tr("Show most warnings (-Wall)"), groupName, true, true, false, "-Wall");
addOption("gcc_cmd_opt_warning_extra",QObject::tr("Show some more warnings (-Wextra)"), groupName, true, true, false, "-Wextra");
addOption("gcc_cmd_opt_check_iso_conformance", QObject::tr("Check ISO C/C++/C++0x conformance (-pedantic)"), groupName, true, true, false, "-pedantic");
addOption("gcc_cmd_opt_syntax_only", QObject::tr("Only check the code for syntax errors (-fsyntax-only)"), groupName, true, true, false, "-fsyntax-only");
addOption("gcc_cmd_opt_warning_as_error", QObject::tr("Make all warnings into errors (-Werror)"), groupName, true, true, false, "-Werror");
addOption("gcc_cmd_opt_abort_on_error", QObject::tr("Abort compilation on first error (-Wfatal-errors)"), groupName, true, true, false, "-Wfatal-errors");
// Profile
groupName = QObject::tr("Profile");
addOption("gcc_cmd_opt_profile_info",QObject::tr("Generate profiling info for analysis (-pg)"), groupName, true, true, true, "-pg");
// Linker
groupName = QObject::tr("Linker");
addOption("linker_cmd_opt_link_objc", QObject::tr("Link an Objective C program (-lobjc)"), groupName, false, false, true, "-lobjc");
addOption("linker_cmd_opt_no_link_stdlib",QObject::tr("Do not use standard system libraries (-nostdlib)"), groupName, false, false, true, "-nostdlib");
addOption("linker_cmd_opt_no_console", QObject::tr("Do not create a console window (-mwindows)"), groupName,false, false, true, "-mwindows");
addOption("linker_cmd_opt_strip_exe", QObject::tr("Strip executable (-s)"), groupName, false, false, true, "-s");
addOption("cc_cmd_opt_debug_info", QObject::tr("Generate debugging information (-g3)"), groupName, true, true, false, "-g3");
// Output
groupName = QObject::tr("Output");
addOption("cc_cmd_opt_verbose_asm", QObject::tr("Put comments in generated assembly code (-fverbose-asm)"), groupName, true, true, false, "-fverbose-asm");
addOption("cc_cmd_opt_only_gen_asm_code", QObject::tr("Do not assemble, compile and generate the assemble code (-S)"), groupName, true, true, false, "-S");
addOption("cc_cmd_opt_use_pipe", QObject::tr("Use pipes instead of temporary files during compilation (-pipe)"), groupName, true, true, false, "-pipe");
//old settings compatibility, don't reorder, add or remove items
mCompilerCompatibleIndex.append("gcc_cmd_opt_ansi");
@ -2924,25 +2806,6 @@ void Settings::CompilerSets::initOptions()
}
void Settings::CompilerSets::addOption(const QString &key, const QString &name, const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting, const CompileOptionChoiceList &choices)
{
PCompilerOption pOption = std::make_shared<CompilerOption>();
pOption->key = key;
pOption->name = name;
pOption->section = section;
pOption->isC = isC;
pOption->isCpp = isCpp;
pOption->isLinker = isLinker;
pOption->setting= setting;
pOption->choices = choices;
mCompilerOptions.insert(key,pOption);
}
const CompilerOptionMap &Settings::CompilerSets::compilerOptions() const
{
return mCompilerOptions;
}
QString Settings::CompilerSets::getKeyFromCompilerCompatibleIndex(int idx) const
{
if (idx<0 || idx >= mCompilerCompatibleIndex.length())
@ -2950,11 +2813,6 @@ QString Settings::CompilerSets::getKeyFromCompilerCompatibleIndex(int idx) const
return mCompilerCompatibleIndex[idx];
}
PCompilerOption Settings::CompilerSets::getCompilerOption(const QString &key) const
{
return mCompilerOptions.value(key,PCompilerOption());
}
Settings::Environment::Environment(Settings *settings):_Base(settings, SETTING_ENVIRONMENT)
{

View File

@ -24,6 +24,7 @@
#include <QString>
#include <QPair>
#include "qsynedit/SynEdit.h"
#include "compiler/compilerinfo.h"
/**
* use the following command to get gcc's default bin/library folders:
@ -47,42 +48,6 @@
#define SETTING_EDITOR_DEFAULT_ENCODING "default_encoding"
#define SETTING_EDITOR_AUTO_INDENT "default_auto_indent"
#define COMPILER_CLANG "Clang"
#define COMPILER_GCC "GCC"
#define CC_CMD_OPT_ANSI "cc_cmd_opt_ansi"
#define CC_CMD_OPT_NO_ASM "cc_cmd_opt_no_asm"
#define CC_CMD_OPT_TRADITIONAL_CPP "cc_cmd_opt_traditional_cpp"
#define CC_CMD_OPT_ARCH "cc_cmd_opt_arch"
#define CC_CMD_OPT_TUNE "cc_cmd_opt_tune"
#define CC_CMD_OPT_INSTRUCTION "cc_cmd_opt_instruction"
#define CC_CMD_OPT_OPTIMIZE "cc_cmd_opt_optimize"
#define CC_CMD_OPT_POINTER_SIZE "cc_cmd_opt_pointer_size"
#define CC_CMD_OPT_STD "cc_cmd_opt_std"
#define CC_CMD_OPT_INHIBIT_ALL_WARNING "cc_cmd_opt_inhibit_all_warning"
#define CC_CMD_OPT_WARNING_ALL "cc_cmd_opt_warning_all"
#define CC_CMD_OPT_WARNING_EXTRA "cc_cmd_opt_warning_extra"
#define CC_CMD_OPT_CHECK_ISO_CONFORMANCE "cc_cmd_opt_check_iso_conformance"
#define CC_CMD_OPT_SYNTAX_ONLY "cc_cmd_opt_syntax_only"
#define CC_CMD_OPT_WARNING_AS_ERROR "cc_cmd_opt_warning_as_error"
#define CC_CMD_OPT_ABORT_ON_ERROR "cc_cmd_opt_abort_on_error"
#define CC_CMD_OPT_PROFILE_INFO "cc_cmd_opt_profile_info"
#define LINK_CMD_OPT_LINK_OBJC "link_cmd_opt_link_objc"
#define LINK_CMD_OPT_NO_LINK_STDLIB "link_cmd_opt_no_link_stdlib"
#define LINK_CMD_OPT_NO_CONSOLE "link_cmd_opt_no_console"
#define LINK_CMD_OPT_STRIP_EXE "link_cmd_opt_strip_exe"
#define CC_CMD_OPT_DEBUG_INFO "cc_cmd_opt_debug_info"
#define CC_CMD_OPT_VERBOSE_ASM "cc_cmd_opt_verbose_asm"
#define CC_CMD_OPT_ONLY_GEN_ASM_CODE "cc_cmd_opt_only_gen_asm_code"
#define CC_CMD_OPT_USE_PIPE "cc_cmd_opt_use_pipe"
extern const char ValueToChar[28];
class Settings;
@ -93,23 +58,6 @@ enum CompilerSetType {
CST_PROFILING
};
using CompileOptionChoiceList = QList<QPair<QString,QString>>;
typedef struct {
QString key;
QString name; // "Generate debugging info"
QString section; // "C options"
bool isC;
bool isCpp; // True (C++ option?) - can be both C and C++ option...
bool isLinker; // Is it a linker param
QString setting; // "-g3"
CompileOptionChoiceList choices; // replaces "Yes/No" standard choices (max 30 different choices)
} CompilerOption;
using PCompilerOption = std::shared_ptr<CompilerOption>;
using CompilerOptionMap=QMap<QString,std::shared_ptr<CompilerOption>>;
class Settings
{
private:
@ -1371,10 +1319,8 @@ public:
void setDefaultIndex(int value);
PCompilerSet defaultSet();
PCompilerSet getSet(int index);
const CompilerOptionMap &compilerOptions() const;
QString getKeyFromCompilerCompatibleIndex(int idx) const;
PCompilerOption getCompilerOption(const QString& key) const;
private:
void savePath(const QString& name, const QString& path);
@ -1383,20 +1329,11 @@ public:
QString loadPath(const QString& name);
void loadPathList(const QString& name, QStringList& list);
PCompilerSet loadSet(int index);
void initOptions();
void addOption(const QString& key,
const QString& name,
const QString section,
bool isC,
bool isCpp,
bool isLinker,
const QString& setting,
const CompileOptionChoiceList& choices = QStringList());
void prepareCompatibleIndex();
private:
CompilerSetList mList;
int mDefaultIndex;
Settings* mSettings;
CompilerOptionMap mCompilerOptions;
QStringList mCompilerCompatibleIndex; // index for old settings compatibility
};

View File

@ -110,7 +110,7 @@
<item>
<widget class="QTabWidget" name="settingTabs">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<property name="movable">
<bool>false</bool>

View File

@ -0,0 +1,113 @@
#include "compileargumentswidget.h"
#include "ui_compileargumentswidget.h"
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
CompileArgumentsWidget::CompileArgumentsWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CompileArgumentsWidget)
{
ui->setupUi(this);
}
CompileArgumentsWidget::~CompileArgumentsWidget()
{
delete ui;
}
QMap<QString, QString> CompileArgumentsWidget::options() const
{
QMap
QTabWidget* pTab = ui->tabArguments;
for (int i=0;i<pTab->count();i++) {
QString section = pTab->tabText(i);
QWidget* pWidget = pTab->widget(i);
QGridLayout* pLayout = static_cast<QGridLayout*>(pWidget->layout());
if (pLayout != nullptr) {
for (int j=1;j<pLayout->rowCount()-1;j++) {
QString key = static_cast<QLabel *>(pLayout->itemAtPosition(j,0)->widget())->text();
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(mCompilerType,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);
}
}
}
}
}
}
void CompileArgumentsWidget::resetUI(Settings::PCompilerSet pSet, const QMap<QString,QString>& options)
{
QTabWidget* pTab = ui->tabArguments;
while (pTab->count()>0) {
QWidget* p=pTab->widget(0);
if (p!=nullptr) {
pTab->removeTab(0);
p->setParent(nullptr);
delete p;
}
}
if (!pSet)
return;
mCompilerType = pSet->compilerType();
foreach (PCompilerOption pOption, CompilerInfoManager::getCompilerOptions(mCompilerType).values()) {
QWidget* pWidget = nullptr;
for (int i=0;i<pTab->count();i++) {
if (pOption->section == pTab->tabText(i)) {
pWidget = pTab->widget(i);
break;
}
}
if (pWidget == nullptr) {
pWidget = new QWidget();
pTab->addTab(pWidget,pOption->section);
pWidget->setLayout(new QGridLayout());
}
QGridLayout *pLayout = static_cast<QGridLayout*>(pWidget->layout());
int row = pLayout->rowCount();
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(options.value(pOption->key,"")==COMPILER_OPTION_ON);
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 (options.value(pOption->key,"") == choice.second)
pCombo->setCurrentIndex(i);
}
pLayout->addWidget(pCombo,row,2);
}
}
for (int i=0;i<pTab->count();i++) {
QWidget* pWidget = pTab->widget(i);
QGridLayout *pLayout = static_cast<QGridLayout*>(pWidget->layout());
int row = pLayout->rowCount();
QSpacerItem* verticalSpacer = new QSpacerItem(10, 100, QSizePolicy::Minimum, QSizePolicy::Expanding);
pLayout->addItem(verticalSpacer,row,0);
}
}

View File

@ -0,0 +1,29 @@
#ifndef COMPILEARGUMENTSWIDGET_H
#define COMPILEARGUMENTSWIDGET_H
#include <QMap>
#include <QWidget>
#include "../settings.h"
namespace Ui {
class CompileArgumentsWidget;
}
class CompileArgumentsWidget : public QWidget
{
Q_OBJECT
public:
explicit CompileArgumentsWidget(QWidget *parent = nullptr);
~CompileArgumentsWidget();
QMap<QString, QString> options() const;
void resetUI(Settings::PCompilerSet pSet, const QMap<QString,QString>& options);
private:
Ui::CompileArgumentsWidget *ui;
QString mCompilerType;
};
#endif // COMPILEARGUMENTSWIDGET_H

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CompileArgumentsWidget</class>
<widget class="QWidget" name="CompileArgumentsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTabWidget" name="tabArguments">
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tab 2</string>
</attribute>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>