Improve for recent files list. Show duplicate file names with unique path
section. --HG-- branch : develop
This commit is contained in:
parent
880aa4de0c
commit
93910a2130
|
@ -30,6 +30,7 @@
|
|||
- All intersections are now treaded as a loop.
|
||||
- [#558] New export: Export pattern as step-by-step text.
|
||||
- Added options to control passmark angle type and passmark mark type.
|
||||
- Improve for recent files list. Show duplicate file names with unique path section.
|
||||
|
||||
# Version 0.6.2 (unreleased)
|
||||
- [#903] Bug in tool Cut Spline path.
|
||||
|
|
|
@ -104,8 +104,6 @@ TMainWindow::TMainWindow(QWidget *parent)
|
|||
labelPatternUnit(nullptr),
|
||||
isInitialized(false),
|
||||
mIsReadOnly(false),
|
||||
recentFileActs(QVector<QAction *>(MaxRecentFiles)),
|
||||
separatorAct(nullptr),
|
||||
hackedWidgets()
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
@ -127,7 +125,7 @@ TMainWindow::TMainWindow(QWidget *parent)
|
|||
ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
|
||||
ui->toolBarGradation->setContextMenuPolicy(Qt::PreventContextMenu);
|
||||
|
||||
recentFileActs.fill(nullptr);
|
||||
m_recentFileActs.fill(nullptr);
|
||||
|
||||
SetupMenu();
|
||||
UpdateWindowTitle();
|
||||
|
@ -689,6 +687,12 @@ void TMainWindow::ExportToCSVData(const QString &fileName, bool withHeader, int
|
|||
csv.toCSV(fileName, error, withHeader, separator, QTextCodec::codecForMib(mib));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList TMainWindow::RecentFileList() const
|
||||
{
|
||||
return qApp->TapeSettings()->GetRecentFileList();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool TMainWindow::FileSave()
|
||||
{
|
||||
|
@ -1940,7 +1944,7 @@ void TMainWindow::SetupMenu()
|
|||
});
|
||||
connect(ui->actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences);
|
||||
|
||||
for (auto & recentFileAct : recentFileActs)
|
||||
for (auto & recentFileAct : m_recentFileActs)
|
||||
{
|
||||
auto *action = new QAction(this);
|
||||
recentFileAct = action;
|
||||
|
@ -1959,10 +1963,10 @@ void TMainWindow::SetupMenu()
|
|||
recentFileAct->setVisible(false);
|
||||
}
|
||||
|
||||
separatorAct = new QAction(this);
|
||||
separatorAct->setSeparator(true);
|
||||
separatorAct->setVisible(false);
|
||||
ui->menuFile->insertAction(ui->actionPreferences, separatorAct );
|
||||
m_separatorAct = new QAction(this);
|
||||
m_separatorAct->setSeparator(true);
|
||||
m_separatorAct->setVisible(false);
|
||||
ui->menuFile->insertAction(ui->actionPreferences, m_separatorAct );
|
||||
|
||||
|
||||
connect(ui->actionQuit, &QAction::triggered, this, &TMainWindow::close);
|
||||
|
@ -2916,25 +2920,6 @@ bool TMainWindow::LoadFromExistingFile(const QString &path)
|
|||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TMainWindow::UpdateRecentFileActions()
|
||||
{
|
||||
qCDebug(tMainWindow, "Updating recent file actions.");
|
||||
const QStringList files = qApp->TapeSettings()->GetRecentFileList();
|
||||
const int numRecentFiles = qMin(files.size(), static_cast<int>(MaxRecentFiles));
|
||||
qCDebug(tMainWindow, "Updating recent file actions = %i ",numRecentFiles);
|
||||
|
||||
for (int i = 0; i < numRecentFiles; ++i)
|
||||
{
|
||||
const QString text = QStringLiteral("&%1. %2").arg(i + 1).arg(StrippedName(files.at(i)));
|
||||
qCDebug(tMainWindow, "file %i = %s", numRecentFiles, qUtf8Printable(text));
|
||||
recentFileActs.at(i)->setText(text);
|
||||
recentFileActs.at(i)->setData(files.at(i));
|
||||
recentFileActs.at(i)->setVisible(true);
|
||||
}
|
||||
|
||||
separatorAct->setVisible(numRecentFiles>0);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TMainWindow::CreateWindowMenu(QMenu *menu)
|
||||
|
|
|
@ -72,6 +72,7 @@ protected:
|
|||
virtual bool eventFilter(QObject *object, QEvent *event) override;
|
||||
virtual void ExportToCSVData(const QString &fileName, bool withHeader, int mib,
|
||||
const QChar &separator) final;
|
||||
virtual QStringList RecentFileList() const override;
|
||||
|
||||
private slots:
|
||||
void FileNew();
|
||||
|
@ -148,9 +149,7 @@ private:
|
|||
QLabel *labelPatternUnit;
|
||||
bool isInitialized;
|
||||
bool mIsReadOnly;
|
||||
enum { MaxRecentFiles = 5 };
|
||||
QVector<QAction *> recentFileActs;
|
||||
QAction *separatorAct;
|
||||
|
||||
QVector<QObject *> hackedWidgets;
|
||||
|
||||
void SetupMenu();
|
||||
|
@ -164,7 +163,6 @@ private:
|
|||
void ShowNewMData(bool fresh);
|
||||
void ShowUnits();
|
||||
void ShowHeaderUnits(QTableWidget *table, int column, const QString &unit);
|
||||
void UpdateRecentFileActions();
|
||||
|
||||
void MeasurementsWereSaved(bool saved);
|
||||
void SetCurrentFile(const QString &fileName);
|
||||
|
|
|
@ -176,8 +176,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
currentDrawIndex(0), currentToolBoxIndex(0),
|
||||
isDockToolOptionsVisible(true),
|
||||
isDockGroupsVisible(true),
|
||||
drawMode(true), recentFileActs(),
|
||||
separatorAct(nullptr),
|
||||
drawMode(true),
|
||||
leftGoToStage(nullptr), rightGoToStage(nullptr), autoSaveTimer(nullptr), guiEnabled(true),
|
||||
gradationHeights(nullptr),
|
||||
gradationSizes(nullptr),
|
||||
|
@ -193,11 +192,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
m_progressBar(new QProgressBar(this)),
|
||||
m_statusLabel(new QLabel(this))
|
||||
{
|
||||
for (int i = 0; i < MaxRecentFiles; ++i)
|
||||
{
|
||||
recentFileActs[i] = nullptr;
|
||||
}
|
||||
|
||||
CreateActions();
|
||||
InitScenes();
|
||||
|
||||
|
@ -4011,38 +4005,16 @@ bool MainWindow::MaybeSave()
|
|||
return true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MainWindow::UpdateRecentFileActions()
|
||||
{
|
||||
qCDebug(vMainWindow, "Updating recent file actions.");
|
||||
const QStringList files = qApp->ValentinaSettings()->GetRecentFileList();
|
||||
const int numRecentFiles = qMin(files.size(), static_cast<int>(MaxRecentFiles));
|
||||
|
||||
for (int i = 0; i < numRecentFiles; ++i)
|
||||
{
|
||||
QString text = QString("&%1. %2").arg(i + 1).arg(StrippedName(files.at(i)));
|
||||
recentFileActs[i]->setText(text);
|
||||
recentFileActs[i]->setData(files.at(i));
|
||||
recentFileActs[i]->setVisible(true);
|
||||
}
|
||||
for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
|
||||
{
|
||||
recentFileActs[j]->setVisible(false);
|
||||
}
|
||||
|
||||
separatorAct->setVisible(numRecentFiles > 0);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MainWindow::CreateMenus()
|
||||
{
|
||||
for (int i = 0; i < MaxRecentFiles; ++i)
|
||||
{
|
||||
ui->menuFile->insertAction(ui->actionPreferences, recentFileActs[i]);
|
||||
ui->menuFile->insertAction(ui->actionPreferences, m_recentFileActs.at(i));
|
||||
}
|
||||
separatorAct = new QAction(this);
|
||||
separatorAct->setSeparator(true);
|
||||
ui->menuFile->insertAction(ui->actionPreferences, separatorAct);
|
||||
m_separatorAct = new QAction(this);
|
||||
m_separatorAct->setSeparator(true);
|
||||
ui->menuFile->insertAction(ui->actionPreferences, m_separatorAct);
|
||||
UpdateRecentFileActions();
|
||||
|
||||
//Add Undo/Redo actions.
|
||||
|
@ -4060,9 +4032,9 @@ void MainWindow::CreateMenus()
|
|||
ui->menuPatternPiece->insertAction(ui->actionLast_tool, redoAction);
|
||||
ui->toolBarTools->addAction(redoAction);
|
||||
|
||||
separatorAct = new QAction(this);
|
||||
separatorAct->setSeparator(true);
|
||||
ui->menuPatternPiece->insertAction(ui->actionPattern_properties, separatorAct);
|
||||
m_separatorAct = new QAction(this);
|
||||
m_separatorAct->setSeparator(true);
|
||||
ui->menuPatternPiece->insertAction(ui->actionPattern_properties, m_separatorAct);
|
||||
|
||||
AddDocks();
|
||||
}
|
||||
|
@ -4559,8 +4531,8 @@ void MainWindow::CreateActions()
|
|||
{
|
||||
QAction *action = new QAction(this);
|
||||
action->setVisible(false);
|
||||
recentFileActs[i] = action;
|
||||
connect(recentFileActs[i], &QAction::triggered, this, [this]()
|
||||
m_recentFileActs[i] = action;
|
||||
connect(m_recentFileActs[i], &QAction::triggered, this, [this]()
|
||||
{
|
||||
if (QAction *action = qobject_cast<QAction*>(sender()))
|
||||
{
|
||||
|
|
|
@ -255,9 +255,6 @@ private:
|
|||
/** @brief drawMode true if we current draw scene. */
|
||||
bool drawMode;
|
||||
|
||||
enum { MaxRecentFiles = 5 };
|
||||
QAction *recentFileActs[MaxRecentFiles];
|
||||
QAction *separatorAct;
|
||||
QLabel *leftGoToStage;
|
||||
QLabel *rightGoToStage;
|
||||
QTimer *autoSaveTimer;
|
||||
|
@ -326,7 +323,6 @@ private:
|
|||
void WriteSettings();
|
||||
|
||||
bool MaybeSave();
|
||||
void UpdateRecentFileActions();
|
||||
void CreateMenus();
|
||||
void CreateActions();
|
||||
void InitAutoSave();
|
||||
|
|
|
@ -1038,6 +1038,12 @@ void MainWindowsNoGUI::InitTempLayoutScene()
|
|||
tempSceneLayout->setBackgroundBrush( QBrush(QColor(Qt::gray), Qt::SolidPattern) );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList MainWindowsNoGUI::RecentFileList() const
|
||||
{
|
||||
return qApp->ValentinaSettings()->GetRecentFileList();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QIcon MainWindowsNoGUI::ScenePreview(int i, QSize iconSize, PreviewQuatilty quality) const
|
||||
{
|
||||
|
|
|
@ -135,6 +135,7 @@ protected:
|
|||
void InitTempLayoutScene();
|
||||
virtual void CleanLayout()=0;
|
||||
virtual void PrepareSceneList(PreviewQuatilty quality)=0;
|
||||
virtual QStringList RecentFileList() const override;
|
||||
QIcon ScenePreview(int i, QSize iconSize, PreviewQuatilty quality) const;
|
||||
bool GenerateLayout(VLayoutGenerator& lGenerator);
|
||||
int ContinueIfLayoutStale();
|
||||
|
|
|
@ -40,11 +40,137 @@
|
|||
#include <QStyleFactory>
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList SplitFilePaths(const QString &path)
|
||||
{
|
||||
QStringList result;
|
||||
QString subPath = QDir::cleanPath(path);
|
||||
QString lastFileName;
|
||||
|
||||
do
|
||||
{
|
||||
QFileInfo fileInfo(subPath);
|
||||
lastFileName = fileInfo.fileName();
|
||||
if (not lastFileName.isEmpty())
|
||||
{
|
||||
result.prepend(lastFileName);
|
||||
subPath = fileInfo.path();
|
||||
}
|
||||
}
|
||||
while(not lastFileName.isEmpty());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList ReverseList(const QStringList &list)
|
||||
{
|
||||
if (list.isEmpty())
|
||||
{
|
||||
return list;
|
||||
}
|
||||
QVector<QString> reversedList(list.size());
|
||||
qint32 j = 0;
|
||||
for (qint32 i = list.size() - 1; i >= 0; --i)
|
||||
{
|
||||
reversedList.replace(j, list.at(i));
|
||||
++j;
|
||||
}
|
||||
return reversedList.toList();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList SelectNumber(QStringList path, int number)
|
||||
{
|
||||
path = ReverseList(path);
|
||||
QStringList subPath = path.mid(0, number);
|
||||
return ReverseList(subPath);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList RecentFiles(const QStringList &paths)
|
||||
{
|
||||
QVector<QStringList> table;
|
||||
table.reserve(paths.size());
|
||||
|
||||
for(auto &path : paths)
|
||||
{
|
||||
table.append(SplitFilePaths(path));
|
||||
}
|
||||
|
||||
auto CreateOptimized = [table](int tableRow)
|
||||
{
|
||||
QStringList optimized;
|
||||
bool isUnique = true;
|
||||
|
||||
QStringList path = table.at(tableRow);
|
||||
for (int count = 1; count <= path.size(); ++count)
|
||||
{
|
||||
isUnique = true;
|
||||
optimized = SelectNumber(path, count);
|
||||
|
||||
for (int row = 0; row < table.size(); ++row)
|
||||
{
|
||||
if (row == tableRow)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
QStringList testSubPath = SelectNumber(table.at(row), count);
|
||||
if (optimized.join(QDir::separator()) == testSubPath.join(QDir::separator()))
|
||||
{
|
||||
isUnique = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isUnique)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (optimized.size() >= 3)
|
||||
{
|
||||
optimized = QStringList({optimized.first(), QStringLiteral("…"), optimized.last()});
|
||||
}
|
||||
|
||||
return optimized;
|
||||
};
|
||||
|
||||
QVector<QStringList> optimizedPaths;
|
||||
optimizedPaths.reserve(paths.size());
|
||||
|
||||
for (int row = 0; row < table.size(); ++row)
|
||||
{
|
||||
optimizedPaths.append(CreateOptimized(row));
|
||||
}
|
||||
|
||||
QStringList recentFiles;
|
||||
recentFiles.reserve(paths.size());
|
||||
|
||||
for(auto &path : optimizedPaths)
|
||||
{
|
||||
recentFiles.append(path.join(QDir::separator()));
|
||||
}
|
||||
|
||||
return recentFiles;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VAbstractMainWindow::VAbstractMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
m_curFileFormatVersion(0x0),
|
||||
m_curFileFormatVersionStr(QLatin1String("0.0.0"))
|
||||
{}
|
||||
{
|
||||
for (int i = 0; i < MaxRecentFiles; ++i)
|
||||
{
|
||||
m_recentFileActs[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VAbstractMainWindow::ContinueFormatRewrite(const QString ¤tFormatVersion,
|
||||
|
@ -126,6 +252,28 @@ QString VAbstractMainWindow::CSVFilePath()
|
|||
return fileName;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractMainWindow::UpdateRecentFileActions()
|
||||
{
|
||||
const QStringList files = RecentFileList();
|
||||
const QStringList recentFiles = RecentFiles(files);
|
||||
const int numRecentFiles = qMin(files.size(), static_cast<int>(MaxRecentFiles));
|
||||
|
||||
for (int i = 0; i < numRecentFiles; ++i)
|
||||
{
|
||||
QString recent = recentFiles.at(i);
|
||||
if (not recent.isEmpty())
|
||||
{
|
||||
const QString text = QStringLiteral("&%1. %2").arg(i + 1).arg(recentFiles.at(i));
|
||||
m_recentFileActs.at(i)->setText(text);
|
||||
m_recentFileActs.at(i)->setData(files.at(i));
|
||||
m_recentFileActs.at(i)->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
m_separatorAct->setVisible(numRecentFiles>0);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractMainWindow::WindowsLocale()
|
||||
{
|
||||
|
|
|
@ -57,6 +57,9 @@ protected slots:
|
|||
protected:
|
||||
int m_curFileFormatVersion;
|
||||
QString m_curFileFormatVersionStr;
|
||||
enum { MaxRecentFiles = 5 };
|
||||
QVector<QAction *> m_recentFileActs{QVector<QAction *>(MaxRecentFiles)};
|
||||
QAction *m_separatorAct{nullptr};
|
||||
|
||||
bool ContinueFormatRewrite(const QString ¤tFormatVersion, const QString &maxFormatVersion);
|
||||
void ToolBarStyle(QToolBar *bar);
|
||||
|
@ -65,6 +68,9 @@ protected:
|
|||
|
||||
virtual void ExportToCSVData(const QString &fileName, bool withHeader, int mib, const QChar &separator)=0;
|
||||
|
||||
virtual QStringList RecentFileList() const =0;
|
||||
void UpdateRecentFileActions();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VAbstractMainWindow)
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user