work save: project file option dialog

This commit is contained in:
royqh1979@gmail.com 2021-09-14 17:33:47 +08:00
parent 4e1cb482f9
commit bf71340233
13 changed files with 244 additions and 23 deletions

View File

@ -43,6 +43,7 @@ SOURCES += \
settingsdialog/editorcodecompletionwidget.cpp \
settingsdialog/editormiscwidget.cpp \
settingsdialog/formattergeneralwidget.cpp \
settingsdialog/projectfileswidget.cpp \
settingsdialog/projectgeneralwidget.cpp \
widgets/classbrowser.cpp \
widgets/codecompletionlistview.cpp \
@ -126,6 +127,7 @@ HEADERS += \
settingsdialog/editorcodecompletionwidget.h \
settingsdialog/editormiscwidget.h \
settingsdialog/formattergeneralwidget.h \
settingsdialog/projectfileswidget.h \
settingsdialog/projectgeneralwidget.h \
widgets/classbrowser.h \
widgets/codecompletionlistview.h \
@ -185,6 +187,7 @@ FORMS += \
settingsdialog/editorcodecompletionwidget.ui \
settingsdialog/editormiscwidget.ui \
settingsdialog/formattergeneralwidget.ui \
settingsdialog/projectfileswidget.ui \
settingsdialog/projectgeneralwidget.ui \
widgets/cpudialog.ui \
mainwindow.ui \

View File

@ -2878,3 +2878,13 @@ void MainWindow::on_actionClose_Project_triggered()
mClosing = false;
}
void MainWindow::on_actionProject_options_triggered()
{
if (!mProject)
return;
QString oldName = mProject->name();
PSettingsDialog dialog = SettingsDialog::projectOptionDialog();
dialog->exec();
}

View File

@ -307,6 +307,8 @@ private slots:
void on_actionClose_Project_triggered();
void on_actionProject_options_triggered();
private:
Ui::MainWindow *ui;
EditorList *mEditorList;

View File

@ -276,7 +276,7 @@
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>4</number>
<number>1</number>
</property>
<widget class="QWidget" name="tabIssues">
<attribute name="icon">
@ -330,16 +330,6 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabResource">
<attribute name="icon">
<iconset>
<normalon>:/icons/images/newlook24/068-resrc.png</normalon>
</iconset>
</attribute>
<attribute name="title">
<string>Resource</string>
</attribute>
</widget>
<widget class="QWidget" name="tabCompilerOutput">
<attribute name="icon">
<iconset>
@ -890,10 +880,17 @@
<addaction name="actionNext_Editor"/>
<addaction name="actionPrevious_Editor"/>
</widget>
<widget class="QMenu" name="menuProject">
<property name="title">
<string>Project</string>
</property>
<addaction name="actionProject_options"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuSearch"/>
<addaction name="menuCode"/>
<addaction name="menuProject"/>
<addaction name="menuExecute"/>
<addaction name="menuTools"/>
<addaction name="menuWindow"/>
@ -1624,6 +1621,16 @@
<string>Close Project</string>
</property>
</action>
<action name="actionProject_options">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/060-projopt.png</normalon>
</iconset>
</property>
<property name="text">
<string>Project options</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -1405,16 +1405,11 @@ const QList<PProjectUnit> &Project::units() const
return mUnits;
}
const ProjectOptions &Project::options() const
ProjectOptions &Project::options()
{
return mOptions;
}
void Project::setOptions(const ProjectOptions &newOptions)
{
mOptions = newOptions;
}
ProjectModel *Project::model()
{
return &mModel;
@ -1437,7 +1432,10 @@ const QString &Project::name() const
void Project::setName(const QString &newName)
{
if (newName != mName) {
mName = newName;
mNode->text = newName;
}
}
const QString &Project::filename() const

View File

@ -225,8 +225,7 @@ public:
const PFolderNode &node() const;
void setNode(const PFolderNode &newNode);
const ProjectOptions &options() const;
void setOptions(const ProjectOptions &newOptions);
ProjectOptions &options();
ProjectModel* model() ;

View File

@ -0,0 +1,14 @@
#include "projectfileswidget.h"
#include "ui_projectfileswidget.h"
ProjectFilesWidget::ProjectFilesWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ProjectFilesWidget)
{
ui->setupUi(this);
}
ProjectFilesWidget::~ProjectFilesWidget()
{
delete ui;
}

View File

@ -0,0 +1,23 @@
#ifndef PROJECTFILESWIDGET_H
#define PROJECTFILESWIDGET_H
#include <QWidget>
#include "settings.h"
namespace Ui {
class ProjectFilesWidget;
}
class ProjectFilesWidget : public Settings
{
Q_OBJECT
public:
explicit ProjectFilesWidget(QWidget *parent = nullptr);
~ProjectFilesWidget();
private:
Ui::ProjectFilesWidget *ui;
};
#endif // PROJECTFILESWIDGET_H

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProjectFilesWidget</class>
<widget class="QWidget" name="ProjectFilesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>753</width>
<height>503</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QTreeView" name="treeProject">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>File Options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="chkLink">
<property name="text">
<string>Include in linking</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Build Priority:</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="chkCompile">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Include in compilation</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="chkCompileAsCPP">
<property name="text">
<string>Compile files as C++</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Encoding</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinPriority"/>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="cbEncoding"/>
</item>
<item row="6" column="0" colspan="3">
<widget class="QPlainTextEdit" name="txtBuildCommand"/>
</item>
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="chkOverrideBuildCommand">
<property name="text">
<string>Override build command:</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -53,11 +53,27 @@ void ProjectGeneralWidget::doLoad()
ui->cbDefaultEncoding->addItem(ENCODING_AUTO_DETECT);
ui->cbDefaultEncoding->addItem(ENCODING_SYSTEM_DEFAULT);
ui->cbDefaultEncoding->addItem(ENCODING_UTF8);
QList<QByteArray> codecNames;
QSet<QByteArray> codecAlias;
codecAlias.insert("system");
codecAlias.insert("utf-8");
foreach (const QByteArray& name, QTextCodec::availableCodecs()){
if (name == "system")
QByteArray lname = name.toLower();
if (lname.startsWith("cp"))
continue;
if (name == "utf-8")
if (codecAlias.contains(lname))
continue;
codecNames.append(lname);
QTextCodec* codec = QTextCodec::codecForName(name);
if (codec) {
foreach (const QByteArray& alias, codec->aliases()) {
codecAlias.insert(alias.toLower());
}
}
}
std::sort(codecNames.begin(),codecNames.end());
foreach (const QByteArray& name,codecNames) {
ui->cbDefaultEncoding->addItem(name);
}
ui->cbDefaultEncoding->setCurrentText(project->options().encoding);
@ -72,3 +88,21 @@ void ProjectGeneralWidget::doLoad()
ui->lblICon->setPixmap(icon);
}
}
void ProjectGeneralWidget::doSave()
{
std::shared_ptr<Project> project = pMainWindow->project();
if (!project)
return;
project->setName(ui->txtName->text().trimmed());
project->options().encoding = ui->cbDefaultEncoding->currentText();
int row = std::max(0,ui->lstType->currentRow());
project->options().type = static_cast<ProjectType>(row);
project->options().useGPP = ui->cbDefaultCpp->isChecked();
project->options().supportXPThemes = ui->cbSupportXPTheme->isChecked();
project->options().icon = mIconPath;
project->saveOptions();
}

View File

@ -145,7 +145,7 @@
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::Panel</enum>
</property>
<property name="text">
<string/>

View File

@ -16,6 +16,7 @@
#include "executorgeneralwidget.h"
#include "debuggeneralwidget.h"
#include "formattergeneralwidget.h"
#include "projectgeneralwidget.h"
#include <QDebug>
#include <QMessageBox>
#include <QModelIndex>
@ -144,6 +145,19 @@ PSettingsDialog SettingsDialog::optionDialog()
return dialog;
}
PSettingsDialog SettingsDialog::projectOptionDialog()
{
PSettingsDialog dialog = std::make_shared<SettingsDialog>();
SettingsWidget* widget = new ProjectGeneralWidget(tr("General"),tr("Project"));
widget->init();
dialog->addWidget(widget);
dialog->selectFirstWidget();
return dialog;
}
void SettingsDialog::on_widgetsView_clicked(const QModelIndex &index)
{

View File

@ -28,6 +28,7 @@ public:
void selectFirstWidget();
static PSettingsDialog optionDialog();
static PSettingsDialog projectOptionDialog();
private slots:
void widget_settings_changed(bool value);