[vlmc-devel] [PATCH 2/2] RecentProjects: Use QVariantList to store m_recentsProjects
yikei lu
luyikei.qmltu at gmail.com
Sun Apr 10 14:12:22 CEST 2016
Oh yes I don't have to :)
2016-04-10 21:09 GMT+09:00 Hugo Beauzée-Luyssen <hugo at beauzee.fr>:
> Hi,
>
> I'll assume that the most recent version is to be used?
>
> On 04/10/2016 09:48 AM, Yikai Lu wrote:
>> ---
>> src/Gui/wizard/WelcomePage.cpp | 10 ++---
>> src/Project/RecentProjects.cpp | 99 ++++++++++--------------------------------
>> src/Project/RecentProjects.h | 21 ++-------
>> 3 files changed, 31 insertions(+), 99 deletions(-)
>>
>> diff --git a/src/Gui/wizard/WelcomePage.cpp b/src/Gui/wizard/WelcomePage.cpp
>> index a598383..6e44cb8 100644
>> --- a/src/Gui/wizard/WelcomePage.cpp
>> +++ b/src/Gui/wizard/WelcomePage.cpp
>> @@ -118,13 +118,13 @@ void
>> WelcomePage::loadRecentsProjects()
>> {
>> m_ui.projectsListWidget->clear();
>> - const RecentProjects::List& recents = Core::instance()->recentProjects()->list();
>>
>> - for ( int i = 0; i < recents.count(); ++i )
>> + for ( const auto& var : Core::instance()->recentProjects()->toVariant().toList() )
>> {
>> - RecentProjects::RecentProject project = recents.at( i );
>> - QListWidgetItem* item = new QListWidgetItem( project.name );
>> - item->setData( FilePath, project.filePath );
>> + const auto& name = var.toMap()["name"].toString();
>> + const auto& filePath = var.toMap()["file"].toString();
>> + QListWidgetItem* item = new QListWidgetItem( name );
>> + item->setData( FilePath, filePath );
>> m_ui.projectsListWidget->addItem( item );
>> }
>> }
>> diff --git a/src/Project/RecentProjects.cpp b/src/Project/RecentProjects.cpp
>> index ec4df43..e99599b 100644
>> --- a/src/Project/RecentProjects.cpp
>> +++ b/src/Project/RecentProjects.cpp
>> @@ -20,106 +20,53 @@
>> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
>> *****************************************************************************/
>>
>> -#include <QStringList>
>> -
>> #include "RecentProjects.h"
>> -
>> -#include "Project/Project.h"
>> #include "Settings/Settings.h"
>> -#include "Tools/VlmcDebug.h"
>>
>> RecentProjects::RecentProjects( Settings* vlmcSettings, QObject *parent )
>> : QObject(parent)
>> , m_settings( new Settings )
>> {
>> - SettingValue* recentProjects = m_settings->createVar( SettingValue::String, "private/RecentsProjects", "",
>> + SettingValue* recentProjects = m_settings->createVar( SettingValue::List, "private/RecentsProjects", QVariantList(),
>> "", "", SettingValue::Private );
>> vlmcSettings->addSettings( "RecentProjects", *m_settings );
>>
>> - connect( recentProjects, SIGNAL( changed( QVariant ) ), this, SLOT( loadRecentProjects( QVariant ) ) );
>> -}
>> -
>> -void
>> -RecentProjects::projectLoaded(const QString& projectName, const QString& projectFile)
>> -{
>> - removeFromRecentProjects( projectName );
>> - RecentProject project;
>> - project.name = projectName;
>> - project.filePath = projectFile;
>> - m_recentsProjects.prepend( project );
>> - while ( m_recentsProjects.count() > 15 )
>> - m_recentsProjects.removeLast();
>> -
>> - m_settings->setValue( "private/RecentsProjects", flattenProjectList() );
>> + connect( m_settings, &Settings::postLoad, this,
>> + [this, recentProjects](){ m_recentsProjects = recentProjects->get().toList(); } );
>
> Do we need to keep a copy in m_recentProjects? Can't we just store the
> SettingValue and query it in toVariant() ?
>
>> }
>>
>> -const RecentProjects::List&
>> -RecentProjects::list() const
>> +RecentProjects::~RecentProjects()
>> {
>> - return m_recentsProjects;
>> + delete m_settings;
>> }
>>
>> -QString
>> -RecentProjects::flattenProjectList() const
>> +QVariant
>> +RecentProjects::toVariant() const
>> {
>> - if ( m_recentsProjects.count() == 0 )
>> - return QString();
>> - QString res;
>> - foreach ( RecentProject p, m_recentsProjects )
>> - {
>> - res += p.name + '#' + p.filePath + '#';
>> - }
>> - res.chop(1);
>> - return res;
>> + return QVariant( m_recentsProjects );
>> }
>>
>> void
>> -RecentProjects::removeFromRecentProjects( const QString &projectPath )
>> +RecentProjects::remove( const QString &projectFile )
>> {
>> - List::iterator it = m_recentsProjects.begin();
>> - List::iterator ite = m_recentsProjects.end();
>> -
>> - while ( it != ite )
>> + for ( int i = 0; i < m_recentsProjects.count(); ++i )
>> {
>> - if ( (*it).filePath == projectPath )
>> - it = m_recentsProjects.erase( it );
>> - else
>> - ++it;
>> + if ( m_recentsProjects[i].toMap()["file"].toString() == projectFile )
>> + {
>> + m_recentsProjects.removeAt( i );
>> + --i;
>> + }
>> }
>> }
>>
>> void
>> -RecentProjects::remove( const QString& projectPath )
>> +RecentProjects::projectLoaded( const QString& projectName, const QString& projectFile )
>> {
>> - removeFromRecentProjects( projectPath );
>> - m_settings->setValue( "private/RecentsProjects", flattenProjectList() );
>> -}
>> -
>> -void
>> -RecentProjects::loadRecentProjects( const QVariant& recentProjects )
>> -{
>> - // Only watch initial loading, we are now taking ownership of "private/RecentsProjects settings"
>> - disconnect( this, SLOT( loadRecentProjects( QVariant ) ) );
>> -
>> - const QStringList recentProjectsList = recentProjects.toString().split( '#' );
>> -
>> - if ( recentProjectsList.count() == 0 )
>> - return ;
>> -
>> - QStringList::const_iterator it = recentProjectsList.begin();
>> - QStringList::const_iterator ite = recentProjectsList.end();
>> - while ( it != ite )
>> - {
>> - RecentProject project;
>> - project.name = *it;
>> - ++it;
>> - if ( it == ite )
>> - {
>> - vlmcWarning() << "Invalid flattened recent projects list.";
>> - return ;
>> - }
>> - project.filePath = *it;
>> - ++it;
>> - m_recentsProjects.append( project );
>> - }
>> + QVariantMap var {
>> + { "name", projectName },
>> + { "file", projectFile }
>> + };
>> + m_recentsProjects.removeAll( var );
>> + m_recentsProjects.insert( 0, var );
>> + m_settings->setValue( "private/RecentsProjects", m_recentsProjects );
>> }
>> diff --git a/src/Project/RecentProjects.h b/src/Project/RecentProjects.h
>> index eb2c64f..4e395e9 100644
>> --- a/src/Project/RecentProjects.h
>> +++ b/src/Project/RecentProjects.h
>> @@ -33,32 +33,17 @@ class RecentProjects : public QObject
>> Q_OBJECT
>>
>> public:
>> - struct RecentProject
>> - {
>> - QString name;
>> - QString filePath;
>> - };
>> - typedef QList<RecentProject> List;
>> -
>> explicit RecentProjects(Settings* vlmcSettings, QObject *parent = 0 );
>> -
>> + ~RecentProjects();
>> + QVariant toVariant() const;
>> void remove( const QString& projectFile );
>> - const List& list() const;
>> -
>> - private:
>> - void removeFromRecentProjects( const QString &projectPath );
>> - QString flattenProjectList() const;
>> -
>>
>> public slots:
>> void projectLoaded( const QString& projectName, const QString& projectFile );
>>
>> - private slots:
>> - void loadRecentProjects(const QVariant& recentProjects);
>> -
>> private:
>> Settings* m_settings;
>> - List m_recentsProjects;
>> + QVariantList m_recentsProjects;
>>
>> };
>>
>>
>
>
> --
> Hugo Beauzée-Luyssen
> www.beauzee.fr
> _______________________________________________
> Vlmc-devel mailing list
> Vlmc-devel at videolan.org
> https://mailman.videolan.org/listinfo/vlmc-devel
More information about the Vlmc-devel
mailing list