mirror of https://github.com/cutefishos/calamares
[calamares] The ViewManager is its own model
- Having a ProgressTreeModel that does nothing but proxy to ViewManager methods is kind of useless. - Move the relevant code from ProgressTreeModel to ViewManager. - Remove now-unused ProgressTreeModel.main
parent
b209668d33
commit
8f0a6d3065
@ -1,119 +0,0 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017, Adriaan de Groot <groot@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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ProgressTreeModel.h"
|
||||
|
||||
#include "Settings.h"
|
||||
#include "ViewManager.h"
|
||||
|
||||
ProgressTreeModel::ProgressTreeModel( QObject* parent )
|
||||
: QAbstractListModel( parent )
|
||||
{
|
||||
}
|
||||
|
||||
ProgressTreeModel::~ProgressTreeModel() {}
|
||||
|
||||
QVariant
|
||||
ProgressTreeModel::data( const QModelIndex& index, int role ) const
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const Calamares::ViewManager* vm = Calamares::ViewManager::instance();
|
||||
if ( !vm )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const auto steps = vm->viewSteps();
|
||||
if ( ( index.row() < 0 ) || ( index.row() >= steps.length() ) )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const auto* step = steps.at( index.row() );
|
||||
if ( !step )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
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>" );
|
||||
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( key.isValid() ? key.toString() : QStringLiteral( "built-in" ) ) );
|
||||
return toolTip;
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
ProgressTreeModel::rowCount( const QModelIndex& parent ) const
|
||||
{
|
||||
if ( parent.column() > 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const Calamares::ViewManager* vm = Calamares::ViewManager::instance();
|
||||
return vm ? vm->viewSteps().length() : 0;
|
||||
}
|
||||
|
||||
QHash< int, QByteArray >
|
||||
ProgressTreeModel::roleNames() const
|
||||
{
|
||||
auto h = QAbstractListModel::roleNames();
|
||||
h.insert( ProgressTreeItemCurrentRole, "current" );
|
||||
h.insert( ProgressTreeItemCompletedRole, "completed" );
|
||||
return h;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017, Adriaan de Groot <groot@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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROGRESSTREEMODEL_H
|
||||
#define PROGRESSTREEMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
/**
|
||||
* @brief The ProgressTreeModel class implements a model for the ProgressTreeView.
|
||||
*/
|
||||
class ProgressTreeModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Role
|
||||
{
|
||||
ProgressTreeItemCurrentRole = Qt::UserRole + 11, ///< Is this the *current* step?
|
||||
ProgressTreeItemCompletedRole = Qt::UserRole + 12 ///< Are we past this one?
|
||||
};
|
||||
|
||||
explicit ProgressTreeModel( QObject* parent = nullptr );
|
||||
virtual ~ProgressTreeModel() override;
|
||||
|
||||
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
|
||||
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
|
||||
|
||||
QHash< int, QByteArray > roleNames() const override;
|
||||
};
|
||||
|
||||
#endif // PROGRESSTREEMODEL_H
|
Loading…
Reference in New Issue