From 4b8a300b162ace3a2a5d7d24fa19874a9bf37647 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 17 Jul 2008 09:39:01 +0000 Subject: [PATCH] Add clear() method and max history count property --- src/Qtx/QtxMRUAction.cxx | 54 +++++++++++++++++++++++++++++++++++++--- src/Qtx/QtxMRUAction.h | 7 ++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/Qtx/QtxMRUAction.cxx b/src/Qtx/QtxMRUAction.cxx index c3767ca5f..8df4dd128 100755 --- a/src/Qtx/QtxMRUAction.cxx +++ b/src/Qtx/QtxMRUAction.cxx @@ -38,6 +38,7 @@ QtxMRUAction::QtxMRUAction( QObject* parent ) : QtxAction( "Most Recently Used", "Most Recently Used", 0, parent ), myVisCount( 5 ), + myHistoryCount( -1 ), myLinkType( LinkAuto ), myInsertMode( MoveFirst ) { @@ -54,6 +55,7 @@ QtxMRUAction::QtxMRUAction( QObject* parent ) QtxMRUAction::QtxMRUAction( const QString& text, const QString& menuText, QObject* parent ) : QtxAction( text, menuText, 0, parent ), myVisCount( 5 ), + myHistoryCount( -1 ), myLinkType( LinkAuto ), myInsertMode( MoveFirst ) { @@ -72,6 +74,7 @@ QtxMRUAction::QtxMRUAction( const QString& text, const QIcon& icon, const QString& menuText, QObject* parent ) : QtxAction( text, icon, menuText, 0, parent ), myVisCount( 5 ), + myHistoryCount( -1 ), myLinkType( LinkAuto ), myInsertMode( MoveFirst ) { @@ -169,6 +172,32 @@ void QtxMRUAction::setVisibleCount( int num ) myVisCount = num; } +/*! + \brief Get number of totally stored MRU items. + \return number of MRU items stored in the preferences + \sa setHistoryCount(), saveLinks(), loadLinks() +*/ +int QtxMRUAction::historyCount() const +{ + return myHistoryCount; +} + +/*! + \brief Set number of totally stored MRU items. + + This option allows setting number of MRU items to be stored + in the preferences file. + + If \a num < 0, then number of stored MRU items is not limited. + + \return number of MRU items stored in the preferences + \sa historyCount(), saveLinks(), loadLinks() +*/ +void QtxMRUAction::setHistoryCount( const int num ) +{ + myHistoryCount = num; +} + /*! \brief Insert MRU item. @@ -223,6 +252,14 @@ void QtxMRUAction::remove( const QString& link ) myLinks.removeAll( link ); } +/*! + \brief Remove all MRU items. +*/ +void QtxMRUAction::clear() +{ + myLinks.clear(); +} + /*! \brief Get MRU item \param idx MRU item index @@ -302,8 +339,16 @@ void QtxMRUAction::saveLinks( QtxResourceMgr* resMgr, const QString& section, co if ( !resMgr || section.isEmpty() ) return; - if ( clear ) - resMgr->remove( section ); + QString itemPrefix( "item_" ); + + if ( clear ) { + QStringList items = resMgr->parameters( section ); + for ( QStringList::const_iterator it = items.begin(); it != items.end(); ++it ) + { + if ( (*it).startsWith( itemPrefix ) ) + resMgr->remove( section, *it ); + } + } QStringList lst; QMap map; @@ -313,7 +358,6 @@ void QtxMRUAction::saveLinks( QtxResourceMgr* resMgr, const QString& section, co map.insert( *itr, 0 ); } - QString itemPrefix( "item_" ); QStringList items = resMgr->parameters( section ); for ( QStringList::const_iterator it = items.begin(); it != items.end(); ++it ) { @@ -331,7 +375,9 @@ void QtxMRUAction::saveLinks( QtxResourceMgr* resMgr, const QString& section, co } int counter = 0; - for ( QStringList::const_iterator iter = lst.begin(); iter != lst.end(); ++iter, counter++ ) + for ( QStringList::const_iterator iter = lst.begin(); + iter != lst.end() && ( myHistoryCount < 0 || counter < myHistoryCount ); + ++iter, counter++ ) resMgr->setValue( section, itemPrefix + QString().sprintf( "%03d", counter ), *iter ); } diff --git a/src/Qtx/QtxMRUAction.h b/src/Qtx/QtxMRUAction.h index 708383f43..ee1159add 100755 --- a/src/Qtx/QtxMRUAction.h +++ b/src/Qtx/QtxMRUAction.h @@ -67,6 +67,9 @@ public: int visibleCount() const; void setVisibleCount( const int ); + int historyCount() const; + void setHistoryCount( const int ); + void remove( const int ); void remove( const QString& ); void insert( const QString& ); @@ -78,6 +81,9 @@ public: virtual void loadLinks( QtxResourceMgr*, const QString&, const bool = true ); virtual void saveLinks( QtxResourceMgr*, const QString&, const bool = true ) const; +public slots: + void clear(); + signals: void activated( const QString& ); @@ -91,6 +97,7 @@ private: private: QStringList myLinks; //!< most recent used items int myVisCount; //!< number of visible MRU items + int myHistoryCount; //!< number of stored MRU items int myLinkType; //!< type of link names in menu int myInsertMode; //!< items insertion policy }; -- 2.39.2