[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.
This commit is contained in:
parent
b209668d33
commit
8f0a6d3065
@ -7,7 +7,6 @@ set( calamaresSources
|
|||||||
VariantModel.cpp
|
VariantModel.cpp
|
||||||
|
|
||||||
progresstree/ProgressTreeDelegate.cpp
|
progresstree/ProgressTreeDelegate.cpp
|
||||||
progresstree/ProgressTreeModel.cpp
|
|
||||||
progresstree/ProgressTreeView.cpp
|
progresstree/ProgressTreeView.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "CalamaresConfig.h"
|
#include "CalamaresConfig.h"
|
||||||
#include "CalamaresVersion.h"
|
#include "CalamaresVersion.h"
|
||||||
#include "CalamaresWindow.h"
|
#include "CalamaresWindow.h"
|
||||||
#include "progresstree/ProgressTreeModel.h"
|
|
||||||
#include "progresstree/ProgressTreeView.h"
|
#include "progresstree/ProgressTreeView.h"
|
||||||
|
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include "DebugWindow.h"
|
#include "DebugWindow.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "ViewManager.h"
|
#include "ViewManager.h"
|
||||||
#include "progresstree/ProgressTreeModel.h"
|
|
||||||
#include "progresstree/ProgressTreeView.h"
|
#include "progresstree/ProgressTreeView.h"
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
@ -94,7 +93,7 @@ CalamaresWindow::getWidgetSidebar( int desiredWidth )
|
|||||||
logoLayout->addStretch();
|
logoLayout->addStretch();
|
||||||
|
|
||||||
ProgressTreeView* tv = new ProgressTreeView( sideBox );
|
ProgressTreeView* tv = new ProgressTreeView( sideBox );
|
||||||
tv->setModel( new ProgressTreeModel );
|
tv->setModel( Calamares::ViewManager::instance() );
|
||||||
tv->setFocusPolicy( Qt::NoFocus );
|
tv->setFocusPolicy( Qt::NoFocus );
|
||||||
sideLayout->addWidget( tv );
|
sideLayout->addWidget( tv );
|
||||||
|
|
||||||
|
@ -18,11 +18,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ProgressTreeDelegate.h"
|
#include "ProgressTreeDelegate.h"
|
||||||
#include "ProgressTreeModel.h"
|
|
||||||
|
|
||||||
#include "CalamaresApplication.h"
|
#include "CalamaresApplication.h"
|
||||||
#include "CalamaresWindow.h"
|
#include "CalamaresWindow.h"
|
||||||
|
#include "ViewManager.h"
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
|
|
||||||
@ -87,7 +86,7 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
|
|||||||
painter->setFont( font );
|
painter->setFont( font );
|
||||||
|
|
||||||
bool isCurrent = false;
|
bool isCurrent = false;
|
||||||
isCurrent = index.data( ProgressTreeModel::ProgressTreeItemCurrentRole ).toBool();
|
isCurrent = index.data( Calamares::ViewManager::ProgressTreeItemCurrentRole ).toBool();
|
||||||
|
|
||||||
if ( isCurrent )
|
if ( isCurrent )
|
||||||
{
|
{
|
||||||
|
@ -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
|
|
@ -75,7 +75,7 @@ setButtonIcon( QPushButton* button, const QString& name )
|
|||||||
}
|
}
|
||||||
|
|
||||||
ViewManager::ViewManager( QObject* parent )
|
ViewManager::ViewManager( QObject* parent )
|
||||||
: QObject( parent )
|
: QAbstractListModel( parent )
|
||||||
, m_currentStep( 0 )
|
, m_currentStep( 0 )
|
||||||
, m_widget( new QWidget() )
|
, m_widget( new QWidget() )
|
||||||
{
|
{
|
||||||
@ -507,4 +507,85 @@ ViewManager::updateCancelEnabled( bool enabled )
|
|||||||
emit cancelEnabled( enabled );
|
emit cancelEnabled( enabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
ViewManager::data( const QModelIndex& index, int role ) const
|
||||||
|
{
|
||||||
|
if ( !index.isValid() )
|
||||||
|
{
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ( index.row() < 0 ) || ( index.row() >= m_steps.length() ) )
|
||||||
|
{
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto* step = m_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 currentStep() == step;
|
||||||
|
case ProgressTreeItemCompletedRole:
|
||||||
|
// Every step *before* the current step is considered "complete"
|
||||||
|
for ( const auto* otherstep : m_steps )
|
||||||
|
{
|
||||||
|
if ( otherstep == currentStep() )
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( otherstep == step )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// .. and the others (including current) are not.
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
ViewManager::rowCount( const QModelIndex& parent ) const
|
||||||
|
{
|
||||||
|
if ( parent.column() > 0 )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return m_steps.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash< int, QByteArray >
|
||||||
|
ViewManager::roleNames() const
|
||||||
|
{
|
||||||
|
auto h = QAbstractListModel::roleNames();
|
||||||
|
h.insert( ProgressTreeItemCurrentRole, "current" );
|
||||||
|
h.insert( ProgressTreeItemCompletedRole, "completed" );
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
#include "viewpages/ViewStep.h"
|
#include "viewpages/ViewStep.h"
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
@ -33,7 +34,7 @@ namespace Calamares
|
|||||||
* @brief The ViewManager class handles progression through view pages.
|
* @brief The ViewManager class handles progression through view pages.
|
||||||
* @note Singleton object, only use through ViewManager::instance().
|
* @note Singleton object, only use through ViewManager::instance().
|
||||||
*/
|
*/
|
||||||
class UIDLLEXPORT ViewManager : public QObject
|
class UIDLLEXPORT ViewManager : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@ -147,6 +148,23 @@ private:
|
|||||||
QPushButton* m_back;
|
QPushButton* m_back;
|
||||||
QPushButton* m_next;
|
QPushButton* m_next;
|
||||||
QPushButton* m_quit;
|
QPushButton* m_quit;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** @section Model
|
||||||
|
*
|
||||||
|
* These are the methods and enums used for the as-a-model part
|
||||||
|
* of the ViewManager.
|
||||||
|
*/
|
||||||
|
enum Role
|
||||||
|
{
|
||||||
|
ProgressTreeItemCurrentRole = Qt::UserRole + 11, ///< Is this the *current* step?
|
||||||
|
ProgressTreeItemCompletedRole = Qt::UserRole + 12 ///< Are we past this one?
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
Loading…
Reference in New Issue
Block a user