[calamares] Introduce a "completed" role

- This is for future support of a QML progress view
This commit is contained in:
Adriaan de Groot 2020-03-10 16:52:34 -05:00
parent d3f55af51e
commit ba4b42b4ee
2 changed files with 35 additions and 17 deletions

View File

@ -50,35 +50,52 @@ ProgressTreeModel::data( const QModelIndex& index, int role ) const
}
const auto* step = steps.at( index.row() );
if ( role == Qt::DisplayRole )
if ( !step )
{
return step->prettyName();
return QVariant();
}
if ( Calamares::Settings::instance()->debugMode() && role == Qt::ToolTipRole )
switch ( role )
{
case Qt::DisplayRole:
return step->prettyName();
case Qt::ToolTipRole:
if ( Calamares::Settings::instance()->debugMode() )
{
auto key = step->moduleInstanceKey();
QString toolTip( "<b>Debug information</b>" );
if ( step )
{
toolTip.append( "<br/>Type:\tViewStep" );
toolTip.append( QString( "<br/>Pretty:\t%1" ).arg( step->prettyName() ) );
toolTip.append( QString( "<br/>Status:\t%1" ).arg( step->prettyStatus() ) );
toolTip.append( QString( "<br/>Source:\t%1" )
.arg( step->moduleInstanceKey().isValid() ? step->moduleInstanceKey().toString()
: QStringLiteral( "built-in" ) ) );
toolTip.append(
QString( "<br/>Source:\t%1" ).arg( key.isValid() ? key.toString() : QStringLiteral( "built-in" ) ) );
return toolTip;
}
else
{
toolTip.append( "<br/>Type:\tDelegate" );
}
return toolTip;
}
if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole )
{
return step && ( Calamares::ViewManager::instance()->currentStep() == step );
}
return QVariant();
}
case ProgressTreeItemCurrentRole:
return vm->currentStep() == step;
case ProgressTreeItemCompletedRole:
// Every step *before* the current step is considered "complete"
for ( const auto* otherstep : steps )
{
if ( otherstep == vm->currentStep() )
{
break;
}
if ( otherstep == step )
{
return true;
}
}
// .. and the others (including current) are not.
return false;
default:
return QVariant();
}
}
int

View File

@ -31,7 +31,8 @@ class ProgressTreeModel : public QAbstractListModel
public:
enum Role
{
ProgressTreeItemCurrentRole = Qt::UserRole + 11
ProgressTreeItemCurrentRole = Qt::UserRole + 11, ///< Is this the *current* step?
ProgressTreeItemCompletedRole = Qt::UserRole + 12 ///< Are we past this one?
};
explicit ProgressTreeModel( QObject* parent = nullptr );