18#include "recentfilemenu.h"
25RecentFileMenu::RecentFileMenu(
const QString& title,
QWidget *parent) :
28 mClearSeparator =
new QAction(
this);
29 mClearSeparator->setSeparator(
true);
31 mClearAction =
new QAction(tr(
"Clear",
"Clear Recent File menu"),
this);
32 mEmptyAction =
new QAction(tr(
"Empty",
"Showing when Recent File Menu is empty"),
this);
33 mEmptyAction->setEnabled(
false);
36RecentFileMenu::~RecentFileMenu()
38 delete mClearSeparator;
43void RecentFileMenu::clearRecentFiles()
45 for (
const QString& filename : mRecentFiles)
47 removeRecentFile(filename);
52 mRecentActions.clear();
56void RecentFileMenu::setRecentFiles(
const QStringList& filenames)
61 for (
auto filename = filenames.
crbegin(); filename != filenames.
crend(); filename++)
63 if (!filename->isEmpty())
65 addRecentFile(*filename);
70bool RecentFileMenu::loadFromDisk()
80 setRecentFiles(recentFileList);
84bool RecentFileMenu::saveToDisk()
87 settings.setValue(
"RecentFiles",
QVariant(mRecentFiles));
91void RecentFileMenu::addRecentFile(
const QString& filename)
93 if (mRecentFiles.contains(filename))
95 removeRecentFile(filename);
98 while (mRecentFiles.size() >= MAX_RECENT_FILES)
100 removeRecentFile(mRecentFiles.last());
103 mRecentFiles.prepend(filename);
110 mRecentActions.emplace(filename, action);
111 if (mRecentFiles.size() == 1)
125 QString firstFile = mRecentFiles[1];
130void RecentFileMenu::removeRecentFile(
const QString& filename)
132 if (mRecentFiles.contains(filename))
134 QAction* action = mRecentActions.at(filename);
137 mRecentActions.erase(filename);
138 mRecentFiles.removeOne(filename);
143void RecentFileMenu::onRecentFileTriggered()
150 emit loadRecentFile(filePath);
QVariant data() const const
void setData(const QVariant &userData)
void triggered(bool checked)
QList::const_reverse_iterator crbegin() const const
QList::const_reverse_iterator crend() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * sender() const const
bool isEmpty() const const
bool isNull() const const
QString toString() const const
QStringList toStringList() const const