work save

- fix: copy icon file to project folder
 - fix: recopy units after they are sorted
This commit is contained in:
royqh1979 2021-09-15 07:53:35 +08:00
parent 6fc5f5995f
commit e1977f1237
5 changed files with 47 additions and 23 deletions

View File

@ -157,11 +157,11 @@ static void initCodePages(){
CodePages.insert(50937,std::make_shared<CodePageInfo>(50937,"","")); CodePages.insert(50937,std::make_shared<CodePageInfo>(50937,"",""));
CodePages.insert(50939,std::make_shared<CodePageInfo>(50939,"","")); CodePages.insert(50939,std::make_shared<CodePageInfo>(50939,"",""));
CodePages.insert(51932,std::make_shared<CodePageInfo>(51932,"euc-jp","")); CodePages.insert(51932,std::make_shared<CodePageInfo>(51932,"euc-jp",""));
CodePages.insert(51936,std::make_shared<CodePageInfo>(51936,"EUC-CN","")); CodePages.insert(51936,std::make_shared<CodePageInfo>(51936,"euc-cn",""));
CodePages.insert(51949,std::make_shared<CodePageInfo>(51949,"euc-kr","")); CodePages.insert(51949,std::make_shared<CodePageInfo>(51949,"euc-kr",""));
CodePages.insert(51950,std::make_shared<CodePageInfo>(51950,"","")); CodePages.insert(51950,std::make_shared<CodePageInfo>(51950,"",""));
CodePages.insert(52936,std::make_shared<CodePageInfo>(52936,"hz-gb-2312","")); CodePages.insert(52936,std::make_shared<CodePageInfo>(52936,"hz-gb-2312",""));
CodePages.insert(54936,std::make_shared<CodePageInfo>(54936,"GB18030","")); CodePages.insert(54936,std::make_shared<CodePageInfo>(54936,"gb18030",""));
CodePages.insert(57002,std::make_shared<CodePageInfo>(57002,"x-iscii-de","")); CodePages.insert(57002,std::make_shared<CodePageInfo>(57002,"x-iscii-de",""));
CodePages.insert(57003,std::make_shared<CodePageInfo>(57003,"x-iscii-be","")); CodePages.insert(57003,std::make_shared<CodePageInfo>(57003,"x-iscii-be",""));
CodePages.insert(57004,std::make_shared<CodePageInfo>(57004,"x-iscii-ta","")); CodePages.insert(57004,std::make_shared<CodePageInfo>(57004,"x-iscii-ta",""));

View File

@ -20,18 +20,7 @@ void ProjectFilesWidget::doLoad()
std::shared_ptr<Project> project = pMainWindow->project(); std::shared_ptr<Project> project = pMainWindow->project();
if (!project) if (!project)
return; return;
mUnits.clear(); copyUnits();
foreach (const PProjectUnit& unit, project->units()) {
PProjectUnit unitCopy = std::make_shared<ProjectUnit>(project.get());
unitCopy->setPriority(unit->priority());
unitCopy->setCompile(unit->compile());
unitCopy->setLink(unit->link());
unitCopy->setCompileCpp(unit->compileCpp());
unitCopy->setOverrideBuildCmd(unit->overrideBuildCmd());
unitCopy->setBuildCmd(unit->buildCmd());
unitCopy->setEncoding(unit->encoding());
mUnits.append(unitCopy);
}
ui->treeProject->setModel(project->model()); ui->treeProject->setModel(project->model());
ui->treeProject->expandAll(); ui->treeProject->expandAll();
ui->grpFileOptions->setEnabled(false); ui->grpFileOptions->setEnabled(false);
@ -55,6 +44,8 @@ void ProjectFilesWidget::doSave()
} }
pMainWindow->project()->sortUnitsByPriority(); pMainWindow->project()->sortUnitsByPriority();
pMainWindow->project()->saveUnits(); pMainWindow->project()->saveUnits();
copyUnits();
ui->treeProject->clicked(ui->treeProject->currentIndex());
} }
PProjectUnit ProjectFilesWidget::currentUnit() PProjectUnit ProjectFilesWidget::currentUnit()
@ -72,6 +63,25 @@ PProjectUnit ProjectFilesWidget::currentUnit()
return PProjectUnit(); return PProjectUnit();
} }
void ProjectFilesWidget::copyUnits()
{
std::shared_ptr<Project> project = pMainWindow->project();
if (!project)
return;
mUnits.clear();
foreach (const PProjectUnit& unit, project->units()) {
PProjectUnit unitCopy = std::make_shared<ProjectUnit>(project.get());
unitCopy->setPriority(unit->priority());
unitCopy->setCompile(unit->compile());
unitCopy->setLink(unit->link());
unitCopy->setCompileCpp(unit->compileCpp());
unitCopy->setOverrideBuildCmd(unit->overrideBuildCmd());
unitCopy->setBuildCmd(unit->buildCmd());
unitCopy->setEncoding(unit->encoding());
mUnits.append(unitCopy);
}
}
void ProjectFilesWidget::on_treeProject_doubleClicked(const QModelIndex &index) void ProjectFilesWidget::on_treeProject_doubleClicked(const QModelIndex &index)
{ {
if (!index.isValid()) if (!index.isValid())

View File

@ -28,6 +28,7 @@ protected:
void doSave() override; void doSave() override;
private: private:
PProjectUnit currentUnit(); PProjectUnit currentUnit();
void copyUnits();
private slots: private slots:
void on_treeProject_doubleClicked(const QModelIndex &index); void on_treeProject_doubleClicked(const QModelIndex &index);
void on_spinPriority_valueChanged(int arg1); void on_spinPriority_valueChanged(int arg1);

View File

@ -21,6 +21,12 @@ ProjectGeneralWidget::~ProjectGeneralWidget()
delete ui; delete ui;
} }
void ProjectGeneralWidget::refreshIcon()
{
QPixmap icon(mIconPath);
ui->lblICon->setPixmap(icon);
}
void ProjectGeneralWidget::doLoad() void ProjectGeneralWidget::doLoad()
{ {
std::shared_ptr<Project> project = pMainWindow->project(); std::shared_ptr<Project> project = pMainWindow->project();
@ -61,11 +67,8 @@ void ProjectGeneralWidget::doLoad()
ui->cbDefaultCpp->setChecked(project->options().useGPP); ui->cbDefaultCpp->setChecked(project->options().useGPP);
ui->cbSupportXPTheme->setChecked(project->options().supportXPThemes); ui->cbSupportXPTheme->setChecked(project->options().supportXPThemes);
mIconPath = project->options().icon; mIconPath = project->options().icon;
if (!mIconPath.isEmpty()) { QPixmap icon(mIconPath);
QPixmap icon(mIconPath); refreshIcon();
ui->lblICon->setPixmap(icon);
}
ui->btnRemove->setEnabled(!mIconPath.isEmpty());
} }
void ProjectGeneralWidget::doSave() void ProjectGeneralWidget::doSave()
@ -82,7 +85,17 @@ void ProjectGeneralWidget::doSave()
project->options().useGPP = ui->cbDefaultCpp->isChecked(); project->options().useGPP = ui->cbDefaultCpp->isChecked();
project->options().supportXPThemes = ui->cbSupportXPTheme->isChecked(); project->options().supportXPThemes = ui->cbSupportXPTheme->isChecked();
project->options().icon = mIconPath; if (mIconPath.isEmpty()
|| ui->lblICon->pixmap(Qt::ReturnByValue).isNull()) {
project->options().icon = "";
} else {
QString iconPath = changeFileExt(project->filename(),"ico");
QFile::copy(mIconPath, iconPath);
project->options().icon = iconPath;
mIconPath = iconPath;
refreshIcon();
}
project->saveOptions(); project->saveOptions();
} }
@ -95,8 +108,7 @@ void ProjectGeneralWidget::on_btnBrowse_clicked()
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
mIconPath = fileName; mIconPath = fileName;
QPixmap icon(mIconPath); QPixmap icon(mIconPath);
ui->lblICon->setPixmap(icon); refreshIcon();
setSettingsChanged();
} }
ui->btnRemove->setEnabled(!mIconPath.isEmpty()); ui->btnRemove->setEnabled(!mIconPath.isEmpty());
} }

View File

@ -19,7 +19,8 @@ public:
private: private:
Ui::ProjectGeneralWidget *ui; Ui::ProjectGeneralWidget *ui;
QString mIconPath; QString mIconPath;
private:
void refreshIcon();
// SettingsWidget interface // SettingsWidget interface
protected: protected:
void doLoad() override; void doLoad() override;