Store lambdas that call tr in ViewStepItem and TextTreeItem.

This commit is contained in:
Teo Mrnjavac 2015-04-08 19:10:24 +02:00
parent 24fc227e76
commit 2d2d5ca30c
5 changed files with 36 additions and 19 deletions

View File

@ -133,7 +133,11 @@ ProgressTreeModel::setupModelData()
m_rootItem = new ProgressTreeRoot(); m_rootItem = new ProgressTreeRoot();
const Calamares::ViewManager* vm = Calamares::ViewManager::instance(); const Calamares::ViewManager* vm = Calamares::ViewManager::instance();
TextTreeItem* prepare = new TextTreeItem( tr( "Prepare" ), m_rootItem ); TextTreeItem* prepare = new TextTreeItem( []() -> QString
{
return tr( "Prepare" );
},
m_rootItem );
m_rootItem->appendChild( prepare ); m_rootItem->appendChild( prepare );
foreach ( const Calamares::ViewStep* step, vm->prepareSteps() ) foreach ( const Calamares::ViewStep* step, vm->prepareSteps() )
@ -141,13 +145,21 @@ ProgressTreeModel::setupModelData()
prepare->appendChild( new ViewStepItem( step, prepare ) ); prepare->appendChild( new ViewStepItem( step, prepare ) );
} }
m_rootItem->appendChild( new ViewStepItem( tr( "Install" ), m_rootItem->appendChild( new ViewStepItem(
[]() -> QString
{
return tr( "Install" );
},
[vm]() -> const Calamares::ViewStep* [vm]() -> const Calamares::ViewStep*
{ {
return vm->installationStep(); return vm->installationStep();
}, m_rootItem ) ); }, m_rootItem ) );
m_rootItem->appendChild( new ViewStepItem( tr( "Finish" ), m_rootItem->appendChild( new ViewStepItem(
[]() -> QString
{
return tr( "Finish" );
},
[vm]() -> const Calamares::ViewStep* [vm]() -> const Calamares::ViewStep*
{ {
return vm->finishedStep(); return vm->finishedStep();

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,10 +20,12 @@
#include "ProgressTreeModel.h" #include "ProgressTreeModel.h"
TextTreeItem::TextTreeItem( const QString& text, ProgressTreeItem* parent ) TextTreeItem::TextTreeItem( std::function< QString() > textReturner,
ProgressTreeItem* parent )
: ProgressTreeItem( parent ) : ProgressTreeItem( parent )
, m_text( text ) {
{} m_textReturner = textReturner;
}
QVariant QVariant
@ -32,6 +34,6 @@ TextTreeItem::data( int role ) const
if ( role == ProgressTreeModel::ProgressTreeItemRole ) if ( role == ProgressTreeModel::ProgressTreeItemRole )
return this; return this;
if ( role == Qt::DisplayRole ) if ( role == Qt::DisplayRole )
return m_text; return m_textReturner();
return QVariant(); return QVariant();
} }

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,16 +21,19 @@
#include "ProgressTreeItem.h" #include "ProgressTreeItem.h"
#include <functional>
class TextTreeItem : public ProgressTreeItem class TextTreeItem : public ProgressTreeItem
{ {
public: public:
explicit TextTreeItem( const QString& text, ProgressTreeItem* parent = nullptr ); explicit TextTreeItem( std::function< QString() > textReturner,
ProgressTreeItem* parent = nullptr );
virtual QVariant data( int role ) const override; virtual QVariant data( int role ) const override;
private: private:
QString m_text; std::function< QString() > m_textReturner;
}; };
#endif // TEXTTREEITEM_H #endif // TEXTTREEITEM_H

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -23,13 +23,13 @@
#include "viewpages/ViewStep.h" #include "viewpages/ViewStep.h"
ViewStepItem::ViewStepItem( const QString& prettyName, ViewStepItem::ViewStepItem( std::function< QString() > prettyName,
std::function< const Calamares::ViewStep*() > accessor, std::function< const Calamares::ViewStep*() > accessor,
ProgressTreeItem* parent ) ProgressTreeItem* parent )
: ProgressTreeItem( parent ) : ProgressTreeItem( parent )
, m_step( 0 ) , m_step( nullptr )
, m_prettyName( prettyName )
{ {
m_prettyName = prettyName;
m_accessor = accessor; m_accessor = accessor;
} }
@ -54,7 +54,7 @@ ViewStepItem::data( int role ) const
if ( role == ProgressTreeModel::ProgressTreeItemRole ) if ( role == ProgressTreeModel::ProgressTreeItemRole )
return this; return this;
if ( role == Qt::DisplayRole ) if ( role == Qt::DisplayRole )
return m_step ? m_step->prettyName() : m_prettyName; return m_step ? m_step->prettyName() : m_prettyName();
if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole ) if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole )
return m_step ? return m_step ?
( Calamares::ViewManager::instance()->currentStep() == m_step ) : ( Calamares::ViewManager::instance()->currentStep() == m_step ) :

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -31,7 +31,7 @@ class ViewStep;
class ViewStepItem : public ProgressTreeItem class ViewStepItem : public ProgressTreeItem
{ {
public: public:
explicit ViewStepItem( const QString& prettyName, explicit ViewStepItem( std::function< QString() > prettyName,
std::function< const Calamares::ViewStep*() > accessor, std::function< const Calamares::ViewStep*() > accessor,
ProgressTreeItem* parent = nullptr ); ProgressTreeItem* parent = nullptr );
@ -44,7 +44,7 @@ public:
private: private:
std::function< const Calamares::ViewStep*() > m_accessor; std::function< const Calamares::ViewStep*() > m_accessor;
QString m_prettyName; std::function< QString() > m_prettyName;
const Calamares::ViewStep* m_step; const Calamares::ViewStep* m_step;
}; };