Store lambdas that call tr in ViewStepItem and TextTreeItem.

main
Teo Mrnjavac 10 years ago
parent 24fc227e76
commit 2d2d5ca30c

@ -133,7 +133,11 @@ ProgressTreeModel::setupModelData()
m_rootItem = new ProgressTreeRoot();
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 );
foreach ( const Calamares::ViewStep* step, vm->prepareSteps() )
@ -141,13 +145,21 @@ ProgressTreeModel::setupModelData()
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*
{
return vm->installationStep();
}, m_rootItem ) );
m_rootItem->appendChild( new ViewStepItem( tr( "Finish" ),
m_rootItem->appendChild( new ViewStepItem(
[]() -> QString
{
return tr( "Finish" );
},
[vm]() -> const Calamares::ViewStep*
{
return vm->finishedStep();

@ -1,6 +1,6 @@
/* === 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
* it under the terms of the GNU General Public License as published by
@ -20,10 +20,12 @@
#include "ProgressTreeModel.h"
TextTreeItem::TextTreeItem( const QString& text, ProgressTreeItem* parent )
TextTreeItem::TextTreeItem( std::function< QString() > textReturner,
ProgressTreeItem* parent )
: ProgressTreeItem( parent )
, m_text( text )
{}
{
m_textReturner = textReturner;
}
QVariant
@ -32,6 +34,6 @@ TextTreeItem::data( int role ) const
if ( role == ProgressTreeModel::ProgressTreeItemRole )
return this;
if ( role == Qt::DisplayRole )
return m_text;
return m_textReturner();
return QVariant();
}

@ -1,6 +1,6 @@
/* === 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
* it under the terms of the GNU General Public License as published by
@ -21,16 +21,19 @@
#include "ProgressTreeItem.h"
#include <functional>
class TextTreeItem : public ProgressTreeItem
{
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;
private:
QString m_text;
std::function< QString() > m_textReturner;
};
#endif // TEXTTREEITEM_H

@ -1,6 +1,6 @@
/* === 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
* it under the terms of the GNU General Public License as published by
@ -23,13 +23,13 @@
#include "viewpages/ViewStep.h"
ViewStepItem::ViewStepItem( const QString& prettyName,
ViewStepItem::ViewStepItem( std::function< QString() > prettyName,
std::function< const Calamares::ViewStep*() > accessor,
ProgressTreeItem* parent )
: ProgressTreeItem( parent )
, m_step( 0 )
, m_prettyName( prettyName )
, m_step( nullptr )
{
m_prettyName = prettyName;
m_accessor = accessor;
}
@ -54,7 +54,7 @@ ViewStepItem::data( int role ) const
if ( role == ProgressTreeModel::ProgressTreeItemRole )
return this;
if ( role == Qt::DisplayRole )
return m_step ? m_step->prettyName() : m_prettyName;
return m_step ? m_step->prettyName() : m_prettyName();
if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole )
return m_step ?
( Calamares::ViewManager::instance()->currentStep() == m_step ) :

@ -1,6 +1,6 @@
/* === 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
* it under the terms of the GNU General Public License as published by
@ -31,7 +31,7 @@ class ViewStep;
class ViewStepItem : public ProgressTreeItem
{
public:
explicit ViewStepItem( const QString& prettyName,
explicit ViewStepItem( std::function< QString() > prettyName,
std::function< const Calamares::ViewStep*() > accessor,
ProgressTreeItem* parent = nullptr );
@ -44,7 +44,7 @@ public:
private:
std::function< const Calamares::ViewStep*() > m_accessor;
QString m_prettyName;
std::function< QString() > m_prettyName;
const Calamares::ViewStep* m_step;
};

Loading…
Cancel
Save