示例#1
0
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 );
    }
}
示例#2
0
void RecentFileMenu::clear()
{
    for( QString filename : mRecentFiles )
    {
        removeRecentFile( filename );
    }
    QMenu::clear();
    mRecentFiles.clear();
    mRecentActions.clear();
}
示例#3
0
 foreach (QString filename, m_recentFiles)
 {
     removeRecentFile(filename);
 }