From 3368aa4012040780461613436243f9d955e4c7ed Mon Sep 17 00:00:00 2001 From: Shengjie Xu Date: Fri, 26 Jul 2024 20:43:32 -0400 Subject: [PATCH] Improved caching of ImagePack tool dialog data --- tooldialog/imagepacktooldialog.cpp | 23 +++++++++++++++++++++++ tooldialog/imagepacktooldialog.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/tooldialog/imagepacktooldialog.cpp b/tooldialog/imagepacktooldialog.cpp index 399cac1..04f7318 100644 --- a/tooldialog/imagepacktooldialog.cpp +++ b/tooldialog/imagepacktooldialog.cpp @@ -32,6 +32,10 @@ bool ImagePackToolDialog::STATE_lastForkOptionEnable = true; bool ImagePackToolDialog::STATE_lastExportOptionEnable = true; bool ImagePackToolDialog::STATE_lastExportOverviewOptionEnable = true; +QString ImagePackToolDialog::STATE_presetQueryData; +QString ImagePackToolDialog::STATE_presetFromExecutablePath; +QString ImagePackToolDialog::STATE_lastSelectedPresetID; + ImagePackToolDialog::ImagePackToolDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ImagePackToolDialog) @@ -151,6 +155,7 @@ ImagePackToolDialog::ImagePackToolDialog(QWidget *parent) : languageCode = "en"; + // 我们需要等创建本对话框的代码把 initialInfo 初始化后再执行此操作 QMetaObject::invokeMethod(this, &ImagePackToolDialog::startRetrievePresetInfo, Qt::QueuedConnection); } @@ -312,6 +317,11 @@ void ImagePackToolDialog::handleForkParamEdit(QListWidgetItem* item) void ImagePackToolDialog::startRetrievePresetInfo() { + if (STATE_presetQueryData.length() > 0 && initialInfo.program == STATE_presetFromExecutablePath) { + presetQueryData = STATE_presetQueryData; + handlePresetInfo(); + return; + } ExecutionInfo info = initialInfo; info.envs["PREPPIPE_TOOL"] = "assetmanager"; info.args.append("--dump-json"); @@ -319,6 +329,8 @@ void ImagePackToolDialog::startRetrievePresetInfo() w->init(info); connect(w, &ExecuteWindow::executionFinished, this, [=](){ presetQueryData = w->getOutput(); + STATE_presetQueryData = presetQueryData; + STATE_presetFromExecutablePath = initialInfo.program; }); connect(w, &ExecuteWindow::executionFinished, this, &ImagePackToolDialog::handlePresetInfo); connect(w, &ExecuteWindow::executionFinished, w, &QObject::deleteLater); @@ -401,7 +413,18 @@ void ImagePackToolDialog::handlePresetInfo() if (ui->presetComboBox->count() > 0) { ui->presetComboBox->setEnabled(true); ui->presetInfoPushButton->setEnabled(true); + if (STATE_lastSelectedPresetID.length() > 0) { + for (int i = 0, n = ui->presetComboBox->count(); i < n; ++i) { + if (ui->presetComboBox->itemData(i).toString() == STATE_lastSelectedPresetID) { + ui->presetComboBox->setCurrentIndex(i); + } + } + } } + // 这个需要在上面的载入完成之后再加上,否则给 QComboBox 加内容的时候就会触发此改动 + connect(ui->presetComboBox, &QComboBox::currentIndexChanged, this, [this](int index){ + STATE_lastSelectedPresetID = ui->presetComboBox->itemData(index).toString(); + }); } void ImagePackToolDialog::showPresetInfo() diff --git a/tooldialog/imagepacktooldialog.h b/tooldialog/imagepacktooldialog.h index fc873f4..e4ffbe9 100644 --- a/tooldialog/imagepacktooldialog.h +++ b/tooldialog/imagepacktooldialog.h @@ -70,6 +70,9 @@ private slots: static bool STATE_lastForkOptionEnable; static bool STATE_lastExportOptionEnable; static bool STATE_lastExportOverviewOptionEnable; + static QString STATE_presetQueryData; + static QString STATE_presetFromExecutablePath; + static QString STATE_lastSelectedPresetID; private: QPixmap getIconForTextForkParam(QString text, QColor color); QString getMangledTextForTextForkParam(QString text, QColor color);