* compiler settings dialog done
This commit is contained in:
parent
7153fc6f8b
commit
fbb86a78e6
|
@ -1033,6 +1033,9 @@ void Settings::CompilerSets::deleteSet(int index)
|
|||
for (int i=index;i<mList.size();i++) {
|
||||
saveSet(i);
|
||||
}
|
||||
if (mDefaultIndex>=mList.size()) {
|
||||
mDefaultIndex = mList.size()-1;
|
||||
}
|
||||
}
|
||||
|
||||
Settings::CompilerSetList &Settings::CompilerSets::list()
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "compilersetdirectorieswidget.h"
|
||||
#include "ui_compilersetdirectorieswidget.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QStringListModel>
|
||||
#include <QDebug>
|
||||
|
||||
CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
|
@ -11,6 +13,9 @@ CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) :
|
|||
|
||||
mModel = new CompilerSetDirectoriesWidget::ListModel();
|
||||
ui->listView->setModel(mModel);
|
||||
connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &CompilerSetDirectoriesWidget::selectionChanged);
|
||||
ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
}
|
||||
|
||||
CompilerSetDirectoriesWidget::~CompilerSetDirectoriesWidget()
|
||||
|
@ -21,6 +26,8 @@ CompilerSetDirectoriesWidget::~CompilerSetDirectoriesWidget()
|
|||
void CompilerSetDirectoriesWidget::setDirList(const QStringList &list)
|
||||
{
|
||||
mModel->setStringList(list);
|
||||
QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes();
|
||||
ui->btnDelete->setEnabled(lst.count()>0);
|
||||
}
|
||||
|
||||
QStringList CompilerSetDirectoriesWidget::dirList() const
|
||||
|
@ -30,7 +37,49 @@ QStringList CompilerSetDirectoriesWidget::dirList() const
|
|||
|
||||
Qt::ItemFlags CompilerSetDirectoriesWidget::ListModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags flags = Qt::NoItemFlags;
|
||||
if (index.isValid()) {
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable;
|
||||
flags = Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable ;
|
||||
} else if (index.row() ==-1) {
|
||||
// -1 means it's a drop target?
|
||||
flags = Qt::ItemIsDropEnabled;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
void CompilerSetDirectoriesWidget::on_btnAdd_pressed()
|
||||
{
|
||||
QString folder = QFileDialog::getExistingDirectory(this,tr("Choose Folder"));
|
||||
if (!folder.isEmpty()) {
|
||||
int row = mModel->rowCount();
|
||||
mModel->insertRow(row);
|
||||
QModelIndex index= mModel->index(row,0);
|
||||
mModel->setData(index,folder,Qt::DisplayRole);
|
||||
}
|
||||
}
|
||||
|
||||
void CompilerSetDirectoriesWidget::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||
{
|
||||
ui->btnDelete->setEnabled(!selected.isEmpty());
|
||||
}
|
||||
|
||||
void CompilerSetDirectoriesWidget::on_btnDelete_pressed()
|
||||
{
|
||||
QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes();
|
||||
if (lst.count()>0) {
|
||||
mModel->removeRow(lst[0].row());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CompilerSetDirectoriesWidget::on_btnRemoveInvalid_pressed()
|
||||
{
|
||||
QStringList lst;
|
||||
for (const QString& folder : dirList() ) {
|
||||
QFileInfo info(folder);
|
||||
if (info.exists() && info.isDir() ) {
|
||||
lst.append(folder);
|
||||
}
|
||||
}
|
||||
setDirList(lst);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace Ui {
|
|||
class CompilerSetDirectoriesWidget;
|
||||
}
|
||||
|
||||
class QItemSelection;
|
||||
|
||||
class CompilerSetDirectoriesWidget : public QWidget
|
||||
{
|
||||
|
@ -24,6 +25,15 @@ public:
|
|||
void setDirList(const QStringList& list);
|
||||
QStringList dirList() const;
|
||||
|
||||
private slots:
|
||||
void on_btnDelete_pressed();
|
||||
|
||||
void on_btnAdd_pressed();
|
||||
|
||||
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
|
||||
void on_btnRemoveInvalid_pressed();
|
||||
|
||||
private:
|
||||
Ui::CompilerSetDirectoriesWidget *ui;
|
||||
ListModel* mModel;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton">
|
||||
<widget class="QToolButton" name="btnAdd">
|
||||
<property name="toolTip">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
|
@ -37,12 +37,12 @@
|
|||
</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_2">
|
||||
<widget class="QToolButton" name="btnDelete">
|
||||
<property name="toolTip">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
|
@ -55,12 +55,12 @@
|
|||
</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_3">
|
||||
<widget class="QToolButton" name="btnRemoveInvalid">
|
||||
<property name="toolTip">
|
||||
<string>Remove Invalid</string>
|
||||
</property>
|
||||
|
@ -76,7 +76,7 @@
|
|||
<enum>Qt::ToolButtonIconOnly</enum>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -59,7 +59,7 @@ void resetOptionTabs(Settings::PCompilerSet pSet,QTabWidget* pTab)
|
|||
pTab->addTab(pWidget,pOption->section);
|
||||
pWidget->setLayout(new QGridLayout());
|
||||
}
|
||||
QGridLayout *pLayout = (QGridLayout*)pWidget->layout();
|
||||
QGridLayout *pLayout = static_cast<QGridLayout*>(pWidget->layout());
|
||||
int row = pLayout->rowCount();
|
||||
pLayout->addWidget(new QLabel(pOption->name),row,0);
|
||||
QComboBox* pCombo = new QComboBox();
|
||||
|
@ -82,7 +82,7 @@ void resetOptionTabs(Settings::PCompilerSet pSet,QTabWidget* pTab)
|
|||
}
|
||||
for (int i=0;i<pTab->count();i++) {
|
||||
QWidget* pWidget = pTab->widget(i);
|
||||
QGridLayout *pLayout = (QGridLayout*)pWidget->layout();
|
||||
QGridLayout *pLayout = static_cast<QGridLayout*>(pWidget->layout());
|
||||
int row = pLayout->rowCount();
|
||||
QSpacerItem* horizontalSpacer = new QSpacerItem(10, 100, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
pLayout->addItem(horizontalSpacer,row,0);
|
||||
|
@ -112,18 +112,33 @@ static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSet
|
|||
|
||||
void CompilerSetOptionWidget::doLoad()
|
||||
{
|
||||
disconnectInputs();
|
||||
ui->cbCompilerSet->clear();
|
||||
if (pSettings->compilerSets().list().size()<=0) {
|
||||
ui->btnRenameCompilerSet->setEnabled(false);
|
||||
ui->btnRemoveCompilerSet->setEnabled(false);
|
||||
return;
|
||||
} else {
|
||||
ui->btnRenameCompilerSet->setEnabled(true);
|
||||
ui->btnRemoveCompilerSet->setEnabled(true);
|
||||
}
|
||||
int index=pSettings->compilerSets().defaultIndex();
|
||||
for (int i=0;i<pSettings->compilerSets().list().size();i++) {
|
||||
ui->cbCompilerSet->addItem(pSettings->compilerSets().list()[i]->name());
|
||||
}
|
||||
if (index < 0 || index>=ui->cbCompilerSet->count()) {
|
||||
index = 0;
|
||||
}
|
||||
ui->cbCompilerSet->setCurrentIndex(index);
|
||||
|
||||
//reloadCurrentCompilerSet();
|
||||
reloadCurrentCompilerSet();
|
||||
connectInputs();
|
||||
}
|
||||
|
||||
void CompilerSetOptionWidget::doSave()
|
||||
{
|
||||
if (pSettings->compilerSets().list().size()>0) {
|
||||
saveCurrentCompilerSet();
|
||||
}
|
||||
pSettings->compilerSets().saveSets();
|
||||
}
|
||||
|
||||
|
@ -131,8 +146,11 @@ void CompilerSetOptionWidget::on_cbCompilerSet_currentIndexChanged(int index)
|
|||
{
|
||||
if (index<0)
|
||||
return;
|
||||
setSettingsChanged();
|
||||
pSettings->compilerSets().setDefaultIndex(index);
|
||||
disconnectInputs();
|
||||
reloadCurrentCompilerSet();
|
||||
connectInputs();
|
||||
}
|
||||
|
||||
void CompilerSetOptionWidget::reloadCurrentCompilerSet()
|
||||
|
@ -145,7 +163,50 @@ void CompilerSetOptionWidget::reloadCurrentCompilerSet()
|
|||
mCIncludeDirWidget->setDirList(pSet->CIncludeDirs());
|
||||
mCppIncludeDirWidget->setDirList(pSet->CppIncludeDirs());
|
||||
|
||||
connectInputs();
|
||||
}
|
||||
|
||||
void CompilerSetOptionWidget::saveCurrentCompilerSet()
|
||||
{
|
||||
Settings::PCompilerSet pSet = pSettings->compilerSets().defaultSet();
|
||||
|
||||
pSet->setUseCustomCompileParams(ui->chkUseCustomCompilerParams->isChecked());
|
||||
pSet->setCustomCompileParams(ui->txtCustomCompileParams->toPlainText());
|
||||
pSet->setUseCustomLinkParams(ui->chkUseCustomLinkParams->isChecked());
|
||||
pSet->setCustomLinkParams(ui->txtCustomLinkParams->toPlainText());
|
||||
pSet->setStaticLink(ui->chkStaticLink->isChecked());
|
||||
pSet->setAutoAddCharsetParams(ui->chkAutoAddCharset->isChecked());
|
||||
|
||||
pSet->setCCompiler(ui->txtCCompiler->text());
|
||||
pSet->setCppCompiler(ui->txtCppCompiler->text());
|
||||
pSet->setMake(ui->txtMake->text());
|
||||
pSet->setDebugger(ui->txtDebugger->text());
|
||||
pSet->setResourceCompiler(ui->txtResourceCompiler->text());
|
||||
pSet->setProfiler(ui->txtProfiler->text());
|
||||
|
||||
pSet->binDirs()=mBinDirWidget->dirList();
|
||||
|
||||
pSet->libDirs()=mLibDirWidget->dirList();
|
||||
pSet->CIncludeDirs()=mCIncludeDirWidget->dirList();
|
||||
pSet->CppIncludeDirs()=mCppIncludeDirWidget->dirList();
|
||||
|
||||
//read values in the options widget
|
||||
QTabWidget* pTab = ui->optionTabs;
|
||||
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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CompilerSetOptionWidget::on_btnFindCompilers_pressed()
|
||||
|
@ -180,8 +241,15 @@ void CompilerSetOptionWidget::on_btnAddCompilerSetByFolder_pressed()
|
|||
|
||||
void CompilerSetOptionWidget::on_btnRenameCompilerSet_pressed()
|
||||
{
|
||||
QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("New name"));
|
||||
QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("New name"),QLineEdit::Normal,
|
||||
pSettings->compilerSets().defaultSet()->name());
|
||||
if (!name.isEmpty())
|
||||
pSettings->compilerSets().defaultSet()->setName(name);
|
||||
doLoad();
|
||||
}
|
||||
|
||||
void CompilerSetOptionWidget::on_btnRemoveCompilerSet_pressed()
|
||||
{
|
||||
pSettings->compilerSets().deleteSet(ui->cbCompilerSet->currentIndex());
|
||||
doLoad();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ protected:
|
|||
void doSave() override;
|
||||
private:
|
||||
void reloadCurrentCompilerSet();
|
||||
void saveCurrentCompilerSet();
|
||||
|
||||
private slots:
|
||||
void on_cbCompilerSet_currentIndexChanged(int index);
|
||||
|
@ -38,6 +39,7 @@ private slots:
|
|||
void on_btnAddBlankCompilerSet_pressed();
|
||||
void on_btnAddCompilerSetByFolder_pressed();
|
||||
void on_btnRenameCompilerSet_pressed();
|
||||
void on_btnRemoveCompilerSet_pressed();
|
||||
};
|
||||
|
||||
#endif // COMPILERSETOPTIONWIDGET_H
|
||||
|
|
|
@ -90,7 +90,7 @@ void SettingsDialog::on_btnOk_pressed()
|
|||
|
||||
void SettingsDialog::saveCurrentPageSettings(bool confirm)
|
||||
{
|
||||
if (ui->scrollArea->widget()!=ui->scrollAreaWidgetContents)
|
||||
if (ui->scrollArea->widget()==ui->scrollAreaWidgetContents)
|
||||
return;
|
||||
SettingsWidget* pWidget = (SettingsWidget*) ui->scrollArea->widget();
|
||||
if (!pWidget->isSettingsChanged())
|
||||
|
@ -101,6 +101,6 @@ void SettingsDialog::saveCurrentPageSettings(bool confirm)
|
|||
QMessageBox::Yes, QMessageBox::No)!=QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
pWidget->save();
|
||||
ui->btnApply->setEnabled(false);
|
||||
}
|
||||
pWidget->save();
|
||||
}
|
||||
|
|
|
@ -24,13 +24,32 @@ void SettingsWidget::init()
|
|||
void SettingsWidget::load()
|
||||
{
|
||||
doLoad();
|
||||
mSettingsChanged = false;
|
||||
clearSettingsChanged();
|
||||
}
|
||||
|
||||
void SettingsWidget::save()
|
||||
{
|
||||
doSave();
|
||||
mSettingsChanged = false;
|
||||
clearSettingsChanged();
|
||||
}
|
||||
|
||||
void SettingsWidget::connectAbstractItemView(QAbstractItemView *pView)
|
||||
{
|
||||
connect(pView->model(),&QAbstractItemModel::rowsInserted,this,&SettingsWidget::setSettingsChanged);
|
||||
connect(pView->model(),&QAbstractItemModel::rowsMoved,this,&SettingsWidget::setSettingsChanged);
|
||||
connect(pView->model(),&QAbstractItemModel::rowsRemoved,this,&SettingsWidget::setSettingsChanged);
|
||||
connect(pView->model(),&QAbstractItemModel::dataChanged,this,&SettingsWidget::setSettingsChanged);
|
||||
connect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged);
|
||||
}
|
||||
|
||||
void SettingsWidget::disconnectAbstractItemView(QAbstractItemView *pView)
|
||||
{
|
||||
disconnect(pView->model(),&QAbstractItemModel::rowsInserted,this,&SettingsWidget::setSettingsChanged);
|
||||
disconnect(pView->model(),&QAbstractItemModel::rowsMoved,this,&SettingsWidget::setSettingsChanged);
|
||||
disconnect(pView->model(),&QAbstractItemModel::rowsRemoved,this,&SettingsWidget::setSettingsChanged);
|
||||
disconnect(pView->model(),&QAbstractItemModel::dataChanged,this,&SettingsWidget::setSettingsChanged);
|
||||
disconnect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged);
|
||||
|
||||
}
|
||||
|
||||
void SettingsWidget::connectInputs()
|
||||
|
@ -48,11 +67,30 @@ void SettingsWidget::connectInputs()
|
|||
connect(p, QOverload<int>::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged);
|
||||
}
|
||||
for (QAbstractItemView* p: findChildren<QAbstractItemView*>()) {
|
||||
connect(p, &QAbstractItemView::activated,this, &SettingsWidget::setSettingsChanged);
|
||||
connectAbstractItemView(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SettingsWidget::disconnectInputs()
|
||||
{
|
||||
for (QLineEdit* p:findChildren<QLineEdit*>()) {
|
||||
disconnect(p, &QLineEdit::textChanged, this, &SettingsWidget::setSettingsChanged);
|
||||
}
|
||||
for (QCheckBox* p:findChildren<QCheckBox*>()) {
|
||||
disconnect(p, &QCheckBox::stateChanged, this, &SettingsWidget::setSettingsChanged);
|
||||
}
|
||||
for (QPlainTextEdit* p:findChildren<QPlainTextEdit*>()) {
|
||||
disconnect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged);
|
||||
}
|
||||
for (QComboBox* p: findChildren<QComboBox*>()) {
|
||||
disconnect(p, QOverload<int>::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged);
|
||||
}
|
||||
for (QAbstractItemView* p: findChildren<QAbstractItemView*>()) {
|
||||
disconnectAbstractItemView(p);
|
||||
}
|
||||
}
|
||||
|
||||
const QString &SettingsWidget::group()
|
||||
{
|
||||
return mGroup;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
class QAbstractItemView;
|
||||
class SettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -17,16 +18,21 @@ signals:
|
|||
void settingsChanged(bool changed);
|
||||
|
||||
protected:
|
||||
void connectInputs();
|
||||
virtual void doLoad() = 0;
|
||||
virtual void doSave() = 0;
|
||||
void connectAbstractItemView(QAbstractItemView* pView);
|
||||
void disconnectAbstractItemView(QAbstractItemView* pView);
|
||||
public:
|
||||
const QString& group();
|
||||
const QString& name();
|
||||
bool isSettingsChanged();
|
||||
void connectInputs();
|
||||
void disconnectInputs();
|
||||
public slots:
|
||||
void setSettingsChanged();
|
||||
void clearSettingsChanged();
|
||||
private:
|
||||
|
||||
private:
|
||||
bool mSettingsChanged;
|
||||
QString mGroup;
|
||||
|
|
Loading…
Reference in New Issue