Skip to content

Commit

Permalink
Improved caching of ImagePack tool dialog data
Browse files Browse the repository at this point in the history
  • Loading branch information
Shengjie Xu committed Jul 27, 2024
1 parent b07d392 commit 3368aa4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tooldialog/imagepacktooldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -151,6 +155,7 @@ ImagePackToolDialog::ImagePackToolDialog(QWidget *parent) :

languageCode = "en";

// 我们需要等创建本对话框的代码把 initialInfo 初始化后再执行此操作
QMetaObject::invokeMethod(this, &ImagePackToolDialog::startRetrievePresetInfo, Qt::QueuedConnection);
}

Expand Down Expand Up @@ -312,13 +317,20 @@ 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");
ExecuteWindow* w = new ExecuteWindow(this);
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);
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions tooldialog/imagepacktooldialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3368aa4

Please sign in to comment.