[calamares] Remove superfluous ViewStepItem
- The model is a simple list, not a tree (it may have been in the distant past). - All the information needed comes from the ViewSteps held by the ViewManager. - The delegate and fake-step handling was never used.
This commit is contained in:
parent
5a59eb1963
commit
76144fb3dc
@ -10,7 +10,6 @@ set( calamaresSources
|
|||||||
progresstree/ProgressTreeItem.cpp
|
progresstree/ProgressTreeItem.cpp
|
||||||
progresstree/ProgressTreeModel.cpp
|
progresstree/ProgressTreeModel.cpp
|
||||||
progresstree/ProgressTreeView.cpp
|
progresstree/ProgressTreeView.cpp
|
||||||
progresstree/ViewStepItem.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
@ -19,84 +19,17 @@
|
|||||||
|
|
||||||
#include "ProgressTreeModel.h"
|
#include "ProgressTreeModel.h"
|
||||||
|
|
||||||
#include "ViewStepItem.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
#include "ViewManager.h"
|
#include "ViewManager.h"
|
||||||
|
|
||||||
ProgressTreeModel::ProgressTreeModel( QObject* parent )
|
ProgressTreeModel::ProgressTreeModel( QObject* parent )
|
||||||
: QAbstractItemModel( parent )
|
: QAbstractListModel( parent )
|
||||||
, m_rootItem( nullptr )
|
|
||||||
{
|
{
|
||||||
setupModelData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ProgressTreeModel::~ProgressTreeModel()
|
ProgressTreeModel::~ProgressTreeModel()
|
||||||
{
|
{
|
||||||
delete m_rootItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Qt::ItemFlags
|
|
||||||
ProgressTreeModel::flags( const QModelIndex& index ) const
|
|
||||||
{
|
|
||||||
if ( !index.isValid() )
|
|
||||||
{
|
|
||||||
return Qt::ItemFlags();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Qt::ItemIsEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QModelIndex
|
|
||||||
ProgressTreeModel::index( int row, int column, const QModelIndex& parent ) const
|
|
||||||
{
|
|
||||||
if ( !hasIndex( row, column, parent ) )
|
|
||||||
{
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
ProgressTreeItem* parentItem;
|
|
||||||
|
|
||||||
if ( !parent.isValid() )
|
|
||||||
{
|
|
||||||
parentItem = m_rootItem;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
parentItem = static_cast< ProgressTreeItem* >( parent.internalPointer() );
|
|
||||||
}
|
|
||||||
|
|
||||||
ProgressTreeItem* childItem = parentItem->child( row );
|
|
||||||
if ( childItem )
|
|
||||||
{
|
|
||||||
return createIndex( row, column, childItem );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QModelIndex
|
|
||||||
ProgressTreeModel::parent( const QModelIndex& index ) const
|
|
||||||
{
|
|
||||||
if ( !index.isValid() )
|
|
||||||
{
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
ProgressTreeItem* childItem = static_cast< ProgressTreeItem* >( index.internalPointer() );
|
|
||||||
ProgressTreeItem* parentItem = childItem->parent();
|
|
||||||
|
|
||||||
if ( parentItem == m_rootItem )
|
|
||||||
{
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
return createIndex( parentItem->row(), 0, parentItem );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -108,70 +41,54 @@ ProgressTreeModel::data( const QModelIndex& index, int role ) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgressTreeItem* item = static_cast< ProgressTreeItem* >( index.internalPointer() );
|
const Calamares::ViewManager* vm = Calamares::ViewManager::instance();
|
||||||
|
if ( !vm)
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
return item->data( role );
|
const auto steps = vm->viewSteps();
|
||||||
}
|
if ( (index.row() < 0 ) || (index.row() >= steps.length() ) )
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
const auto* step = steps.at(index.row());
|
||||||
|
|
||||||
QVariant
|
if ( role == Qt::DisplayRole )
|
||||||
ProgressTreeModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
{
|
||||||
{
|
return step->prettyName();
|
||||||
Q_UNUSED( section )
|
}
|
||||||
Q_UNUSED( orientation )
|
if ( Calamares::Settings::instance()->debugMode() && role == Qt::ToolTipRole )
|
||||||
Q_UNUSED( role )
|
{
|
||||||
|
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" ) ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
toolTip.append( "<br/>Type:\tDelegate" );
|
||||||
|
}
|
||||||
|
return toolTip;
|
||||||
|
}
|
||||||
|
if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole )
|
||||||
|
{
|
||||||
|
return step && (Calamares::ViewManager::instance()->currentStep() == step);
|
||||||
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
ProgressTreeModel::rowCount( const QModelIndex& parent ) const
|
ProgressTreeModel::rowCount( const QModelIndex& parent ) const
|
||||||
{
|
{
|
||||||
ProgressTreeItem* parentItem;
|
|
||||||
if ( parent.column() > 0 )
|
if ( parent.column() > 0 )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !parent.isValid() )
|
|
||||||
{
|
|
||||||
parentItem = m_rootItem;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
parentItem = static_cast< ProgressTreeItem* >( parent.internalPointer() );
|
|
||||||
}
|
|
||||||
|
|
||||||
return parentItem->childCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
ProgressTreeModel::columnCount( const QModelIndex& parent ) const
|
|
||||||
{
|
|
||||||
if ( parent.isValid() )
|
|
||||||
{
|
|
||||||
return static_cast< ProgressTreeItem* >( parent.internalPointer() )->columnCount();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return m_rootItem->columnCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ProgressTreeModel::setupModelData()
|
|
||||||
{
|
|
||||||
delete m_rootItem;
|
|
||||||
|
|
||||||
m_rootItem = new ProgressTreeRoot();
|
|
||||||
const Calamares::ViewManager* vm = Calamares::ViewManager::instance();
|
const Calamares::ViewManager* vm = Calamares::ViewManager::instance();
|
||||||
|
return vm ? vm->viewSteps().length() : 0;
|
||||||
const auto steps = vm->viewSteps();
|
|
||||||
for ( const Calamares::ViewStep* step : steps )
|
|
||||||
{
|
|
||||||
m_rootItem->appendChild( new ViewStepItem( step, m_rootItem ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#ifndef PROGRESSTREEMODEL_H
|
#ifndef PROGRESSTREEMODEL_H
|
||||||
#define PROGRESSTREEMODEL_H
|
#define PROGRESSTREEMODEL_H
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
class ProgressTreeRoot;
|
class ProgressTreeRoot;
|
||||||
class ProgressTreeItem;
|
class ProgressTreeItem;
|
||||||
@ -29,7 +29,7 @@ class ProgressTreeItem;
|
|||||||
/**
|
/**
|
||||||
* @brief The ProgressTreeModel class implements a model for the ProgressTreeView.
|
* @brief The ProgressTreeModel class implements a model for the ProgressTreeView.
|
||||||
*/
|
*/
|
||||||
class ProgressTreeModel : public QAbstractItemModel
|
class ProgressTreeModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@ -41,19 +41,8 @@ public:
|
|||||||
explicit ProgressTreeModel( QObject* parent = nullptr );
|
explicit ProgressTreeModel( QObject* parent = nullptr );
|
||||||
virtual ~ProgressTreeModel() override;
|
virtual ~ProgressTreeModel() override;
|
||||||
|
|
||||||
// Reimplemented from QAbstractItemModel
|
|
||||||
Qt::ItemFlags flags( const QModelIndex& index ) const override;
|
|
||||||
QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override;
|
|
||||||
QModelIndex parent( const QModelIndex& index ) const override;
|
|
||||||
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
|
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
|
||||||
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
|
|
||||||
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
|
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
|
||||||
int columnCount( const QModelIndex& parent = QModelIndex() ) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setupModelData();
|
|
||||||
|
|
||||||
ProgressTreeRoot* m_rootItem;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROGRESSTREEMODEL_H
|
#endif // PROGRESSTREEMODEL_H
|
||||||
|
@ -1,85 +0,0 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* 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 "ViewStepItem.h"
|
|
||||||
|
|
||||||
#include "ProgressTreeModel.h"
|
|
||||||
|
|
||||||
#include "Settings.h"
|
|
||||||
#include "ViewManager.h"
|
|
||||||
#include "viewpages/ViewStep.h"
|
|
||||||
|
|
||||||
|
|
||||||
ViewStepItem::ViewStepItem( std::function< QString() > prettyName,
|
|
||||||
std::function< const Calamares::ViewStep*() > accessor,
|
|
||||||
ProgressTreeItem* parent )
|
|
||||||
: ProgressTreeItem( parent )
|
|
||||||
, m_accessor( accessor )
|
|
||||||
, m_prettyName( prettyName )
|
|
||||||
, m_step( nullptr )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ViewStepItem::ViewStepItem( const Calamares::ViewStep* step, ProgressTreeItem* parent )
|
|
||||||
: ProgressTreeItem( parent )
|
|
||||||
, m_step( step )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ViewStepItem::appendChild( ProgressTreeItem* item )
|
|
||||||
{
|
|
||||||
Q_ASSERT( false );
|
|
||||||
Q_UNUSED( item )
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
|
||||||
ViewStepItem::data( int role ) const
|
|
||||||
{
|
|
||||||
if ( role == Qt::DisplayRole )
|
|
||||||
{
|
|
||||||
return m_step ? m_step->prettyName() : m_prettyName();
|
|
||||||
}
|
|
||||||
if ( Calamares::Settings::instance()->debugMode() && role == Qt::ToolTipRole )
|
|
||||||
{
|
|
||||||
QString toolTip( "<b>Debug information</b>" );
|
|
||||||
if ( m_step )
|
|
||||||
{
|
|
||||||
toolTip.append( "<br/>Type:\tViewStep" );
|
|
||||||
toolTip.append( QString( "<br/>Pretty:\t%1" ).arg( m_step->prettyName() ) );
|
|
||||||
toolTip.append( QString( "<br/>Status:\t%1" ).arg( m_step->prettyStatus() ) );
|
|
||||||
toolTip.append( QString( "<br/>Source:\t%1" )
|
|
||||||
.arg( m_step->moduleInstanceKey().isValid() ? m_step->moduleInstanceKey().toString()
|
|
||||||
: QStringLiteral( "built-in" ) ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
toolTip.append( "<br/>Type:\tDelegate" );
|
|
||||||
toolTip.append( QString( "<br/>Pretty:\t%1" ).arg( m_prettyName() ) );
|
|
||||||
}
|
|
||||||
return toolTip;
|
|
||||||
}
|
|
||||||
if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole )
|
|
||||||
{
|
|
||||||
return m_step ? ( Calamares::ViewManager::instance()->currentStep() == m_step )
|
|
||||||
: ( Calamares::ViewManager::instance()->currentStep() == m_accessor() );
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* 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 VIEWSTEPITEM_H
|
|
||||||
#define VIEWSTEPITEM_H
|
|
||||||
|
|
||||||
#include "ProgressTreeItem.h"
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
namespace Calamares
|
|
||||||
{
|
|
||||||
class ViewStep;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ViewStepItem : public ProgressTreeItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// We take a std::function< QString() > instead of a QString because the view asks for
|
|
||||||
// new strings on LanguageChange, and tr needs to be called again in that case.
|
|
||||||
explicit ViewStepItem( std::function< QString() > prettyName,
|
|
||||||
std::function< const Calamares::ViewStep*() > accessor,
|
|
||||||
ProgressTreeItem* parent = nullptr );
|
|
||||||
|
|
||||||
explicit ViewStepItem( const Calamares::ViewStep* step, ProgressTreeItem* parent = nullptr );
|
|
||||||
|
|
||||||
void appendChild( ProgressTreeItem* item ) override;
|
|
||||||
|
|
||||||
QVariant data( int role ) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::function< const Calamares::ViewStep*() > m_accessor;
|
|
||||||
const std::function< QString() > m_prettyName;
|
|
||||||
const Calamares::ViewStep* const m_step;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // VIEWSTEPITEM_H
|
|
Loading…
Reference in New Issue
Block a user