void RecentFileMenu::addRecentFile( QString filename ) { if ( mRecentFiles.contains( filename ) ) { removeRecentFile( filename ); } while ( mRecentFiles.size() >= MAX_RECENT_FILES ) { removeRecentFile( mRecentFiles.last() ); } mRecentFiles.prepend( filename ); QAction* action = new QAction( filename, this ); action->setData( QVariant( filename ) ); QObject::connect( action, SIGNAL( triggered() ), this, SLOT( onRecentFileTriggered() ) ); mRecentActions.emplace( filename, action ); if ( mRecentFiles.size() == 1 ) { addAction( action ); } else { QString firstFile = mRecentFiles[ 1 ]; qDebug() << "Recent file" << firstFile; insertAction( mRecentActions[ firstFile ], action ); } }
void RecentFileMenu::clear() { for( QString filename : mRecentFiles ) { removeRecentFile( filename ); } QMenu::clear(); mRecentFiles.clear(); mRecentActions.clear(); }
foreach (QString filename, m_recentFiles) { removeRecentFile(filename); }