解决手动将缩略栏图片进行排序调整后,使用“从扫描插入”功能扫描出的图片顺序与本地文件排序不同的问题,BUG-836

This commit is contained in:
luoliangyi 2023-12-09 15:39:40 +08:00
parent e156c5db26
commit 7ddb5b1a11
1 changed files with 144 additions and 1 deletions

View File

@ -50,6 +50,7 @@
#include <assert.h>
#include "lang/app_language.h"
#include "huagao/brand.h"
#include <algorithm>
#define PASSWORD_KEY 4
@ -749,6 +750,11 @@ void MainWindow::on_itemSelectingChanged()
updateActionStatus();
}
static bool Greater(const QString &str1, const QString &str2)
{
return str1 < str2;
}
void MainWindow::on_currItemChanged(int index)
{
HGImage img = nullptr;
@ -871,6 +877,143 @@ void MainWindow::on_currItemChanged(int index)
m_wndStatusBar->setPageInfo(count, m_currIndex);
updateStatusBarPixelInfo();
updateActionStatus();
if (!m_isScanning && !m_curBatchFileList.empty())
{
std::vector<QString> fileNames;
int count = 0;
m_thumb->getItemCount(&count);
for (int i = 0; i < count; ++i)
{
QString fileName;
m_thumb->getItemFileName(i, fileName);
std::list<QString>::iterator iter;
for (iter = m_curBatchFileList.begin(); iter != m_curBatchFileList.end(); ++iter)
{
if (*iter == fileName)
{
HGChar name[256];
HGBase_GetFileName(fileName.toLocal8Bit().toStdString().c_str(), name, 256);
HGChar filePrefix[256];
HGBase_GetFilePrefix(name, filePrefix, 256);
fileNames.push_back(filePrefix);
break;
}
}
}
std::vector<QString> backupFileNames = fileNames;
std::sort(fileNames.begin(), fileNames.end(), Greater);
if (backupFileNames != fileNames)
{
std::list<QString> batchTmpFileList;
for (int i = 0; i < count; ++i)
{
QString fileName;
m_thumb->getItemFileName(i, fileName);
std::list<QString>::iterator iter;
for (iter = m_curBatchFileList.begin(); iter != m_curBatchFileList.end(); ++iter)
{
if (*iter == fileName)
{
HGChar filePath[256];
HGBase_GetFilePath(fileName.toLocal8Bit().toStdString().c_str(), filePath, 256);
HGChar name[256];
HGBase_GetFileName(fileName.toLocal8Bit().toStdString().c_str(), name, 256);
HGChar filePrefix[256];
HGBase_GetFilePrefix(name, filePrefix, 256);
HGChar fileSuffix[256];
HGBase_GetFileSuffix(name, fileSuffix, 256);
HGChar uuid[256];
HGBase_GetUuid(uuid, 256);
QString strFilePath = QString::fromLocal8Bit(filePath);
QString strFileSuffix = QString::fromLocal8Bit(fileSuffix);
QString strUuid = QString::fromLocal8Bit(uuid);
QString newFileName = strFilePath + strUuid + "." + strFileSuffix;
QFile file(fileName);
file.rename(newFileName);
m_thumb->updateItem(fileName, newFileName, false);
m_curBatchFileList.erase(iter);
batchTmpFileList.push_back(newFileName);
break;
}
}
}
std::list<QString>::iterator iter;
for (iter = batchTmpFileList.begin(); iter != batchTmpFileList.end(); ++iter)
{
HGChar filePath[256];
HGBase_GetFilePath((*iter).toLocal8Bit().toStdString().c_str(), filePath, 256);
HGChar fileSuffix[256];
HGBase_GetFileSuffix((*iter).toLocal8Bit().toStdString().c_str(), fileSuffix, 256);
QString strFilePath = QString::fromLocal8Bit(filePath);
QString strFileSuffix = QString::fromLocal8Bit(fileSuffix);
QString newFileName;
while (!fileNames.empty())
{
QString fileName = strFilePath + fileNames.front() + "." + strFileSuffix;
QFileInfo fileInfo(fileName);
if (fileInfo.isFile())
{
fileNames.erase(fileNames.begin());
}
else
{
newFileName = fileName;
break;
}
}
if (!newFileName.isEmpty())
{
QFile file(*iter);
file.rename(newFileName);
m_thumb->updateItem(*iter, newFileName, false);
m_curBatchFileList.push_back(newFileName);
fileNames.erase(fileNames.begin());
}
else
{
while (1)
{
QString fileName = strFilePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2")
.arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0'))
.arg(strFileSuffix);
QFileInfo fileInfo(fileName);
if (fileInfo.isFile())
{
++m_aquireIntoSaveParam.m_fileNameStartIndex;
}
else
{
newFileName = fileName;
break;
}
}
if (!newFileName.isEmpty())
{
QFile file(*iter);
file.rename(newFileName);
m_thumb->updateItem(*iter, newFileName, false);
m_curBatchFileList.push_back(newFileName);
++m_aquireIntoSaveParam.m_fileNameStartIndex;
}
}
}
batchTmpFileList.clear();
}
}
}
void MainWindow::on_itemDoubleClicked(int index)
@ -1050,7 +1193,7 @@ void MainWindow::on_post_new_image(QString fileName)
HGBase_LeaveLock(m_lockPreviewImage);
updateStatusBarPixelInfo();
if ((ScanType_ScanInto == m_scanType))
if (ScanType_ScanInto == m_scanType)
{
m_curBatchFileList.push_back(stdFileName);
}