Inherits QObject.
Class representing recently opened files as a QMenu.
Class provides easy API to add, remove and signal of the picking of the recent file item. Each item can have associated QIcon.
Class automatically maintains amount of the recent files and their order (i.e. most recently added and picked items always go to the top of the list).
Also class can store and load the list of the recent files through a QSetting object.
Usage of RecentFiles in the application
There are two ways of representation of the recent files: as a submenu and as an embedded list.
Usage as a submenu is very easy. Just create RecentFiles object and add its menu() to the appropriate action of the parent menu. Then connect activated() signal to the appropriate slot.
actionRecent->setMenu(myRecentFiles.menu());
connect(&myRecentFiles, SIGNAL(
activated(QString)),
this, SLOT(handleActivated(QString)));
Usage as an embedded list requires handling of aboutToShow() signal of the menu where you'd like to show the recent files.
First, as usual, create RecentFiles object. Then connect activated() signal to the appropriate slot.
Second, in the slot associatiated with this signal, you have to create all the menu actions and in a mean time, call populateMenu() function to provide internal connections and insert recent files list into the menu.
connect(&myRecentFiles, SIGNAL(
activated(QString)),
this, SLOT(handleActivated(QString)));
void MyAppWindow::on_fileMenu_aboutToShow()
{
fileMenu->clear();
fileMenu->addSeparator();
myRecentFiles.populate(fileMenu);
fileMenu->addSeparator();
}