From 5a59eb1963d3826ccf463d3c3cc25bbe8a641255 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Mar 2020 13:43:04 -0500 Subject: [PATCH 01/14] [calamares] Remove unused method from progresstreemodel --- .../progresstree/ProgressTreeModel.cpp | 50 ------------------- .../progresstree/ProgressTreeModel.h | 1 - 2 files changed, 51 deletions(-) diff --git a/src/calamares/progresstree/ProgressTreeModel.cpp b/src/calamares/progresstree/ProgressTreeModel.cpp index d4b5a0321..3c0511e75 100644 --- a/src/calamares/progresstree/ProgressTreeModel.cpp +++ b/src/calamares/progresstree/ProgressTreeModel.cpp @@ -175,53 +175,3 @@ ProgressTreeModel::setupModelData() m_rootItem->appendChild( new ViewStepItem( step, m_rootItem ) ); } } - - -QModelIndex -ProgressTreeModel::indexFromItem( ProgressTreeItem* item ) -{ - if ( !item || !item->parent() ) - { - return QModelIndex(); - } - - // Reconstructs a QModelIndex from a ProgressTreeItem that is somewhere in the tree. - // Traverses the item to the root node, then rebuilds the qmodelindices from there - // back down; each int is the row of that item in the parent. - /** - * In this diagram, if the item is G, childIndexList will contain [0, 2, 0] - * - * A - * D - * E - * F - * G - * H - * B - * C - * - **/ - QList< int > childIndexList; - ProgressTreeItem* curItem = item; - while ( curItem != m_rootItem ) - { - int row = curItem->row(); //relative to its parent - if ( row < 0 ) // something went wrong, bail - { - return QModelIndex(); - } - - childIndexList << row; - - curItem = curItem->parent(); - } - - // Now we rebuild the QModelIndex we need - QModelIndex idx; - for ( int i = childIndexList.size() - 1; i >= 0; i-- ) - { - idx = index( childIndexList[ i ], 0, idx ); - } - - return idx; -} diff --git a/src/calamares/progresstree/ProgressTreeModel.h b/src/calamares/progresstree/ProgressTreeModel.h index e424f9d8d..1e3f8a49d 100644 --- a/src/calamares/progresstree/ProgressTreeModel.h +++ b/src/calamares/progresstree/ProgressTreeModel.h @@ -52,7 +52,6 @@ public: private: void setupModelData(); - QModelIndex indexFromItem( ProgressTreeItem* item ); ProgressTreeRoot* m_rootItem; }; From 76144fb3dcc119a2a25ca9a6c0c0e24420ccc79e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Mar 2020 14:06:35 -0500 Subject: [PATCH 02/14] [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. --- src/calamares/CMakeLists.txt | 1 - .../progresstree/ProgressTreeModel.cpp | 157 +++++------------- .../progresstree/ProgressTreeModel.h | 15 +- src/calamares/progresstree/ViewStepItem.cpp | 85 ---------- src/calamares/progresstree/ViewStepItem.h | 53 ------ 5 files changed, 39 insertions(+), 272 deletions(-) delete mode 100644 src/calamares/progresstree/ViewStepItem.cpp delete mode 100644 src/calamares/progresstree/ViewStepItem.h diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index 9327af8e3..cb460f14b 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -10,7 +10,6 @@ set( calamaresSources progresstree/ProgressTreeItem.cpp progresstree/ProgressTreeModel.cpp progresstree/ProgressTreeView.cpp - progresstree/ViewStepItem.cpp ) include_directories( diff --git a/src/calamares/progresstree/ProgressTreeModel.cpp b/src/calamares/progresstree/ProgressTreeModel.cpp index 3c0511e75..00f2884a3 100644 --- a/src/calamares/progresstree/ProgressTreeModel.cpp +++ b/src/calamares/progresstree/ProgressTreeModel.cpp @@ -19,84 +19,17 @@ #include "ProgressTreeModel.h" -#include "ViewStepItem.h" - +#include "Settings.h" #include "ViewManager.h" ProgressTreeModel::ProgressTreeModel( QObject* parent ) - : QAbstractItemModel( parent ) - , m_rootItem( nullptr ) + : QAbstractListModel( parent ) { - setupModelData(); } 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(); } - 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 -ProgressTreeModel::headerData( int section, Qt::Orientation orientation, int role ) const -{ - Q_UNUSED( section ) - Q_UNUSED( orientation ) - Q_UNUSED( role ) - + if ( role == Qt::DisplayRole ) + { + return step->prettyName(); + } + if ( Calamares::Settings::instance()->debugMode() && role == Qt::ToolTipRole ) + { + QString toolTip( "Debug information" ); + if ( step ) + { + toolTip.append( "
Type:\tViewStep" ); + toolTip.append( QString( "
Pretty:\t%1" ).arg( step->prettyName() ) ); + toolTip.append( QString( "
Status:\t%1" ).arg( step->prettyStatus() ) ); + toolTip.append( QString( "
Source:\t%1" ) + .arg( step->moduleInstanceKey().isValid() ? step->moduleInstanceKey().toString() + : QStringLiteral( "built-in" ) ) ); + } + else + { + toolTip.append( "
Type:\tDelegate" ); + } + return toolTip; + } + if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole ) + { + return step && (Calamares::ViewManager::instance()->currentStep() == step); + } return QVariant(); } + int ProgressTreeModel::rowCount( const QModelIndex& parent ) const { - ProgressTreeItem* parentItem; if ( parent.column() > 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 auto steps = vm->viewSteps(); - for ( const Calamares::ViewStep* step : steps ) - { - m_rootItem->appendChild( new ViewStepItem( step, m_rootItem ) ); - } + return vm ? vm->viewSteps().length() : 0; } diff --git a/src/calamares/progresstree/ProgressTreeModel.h b/src/calamares/progresstree/ProgressTreeModel.h index 1e3f8a49d..51f1f4126 100644 --- a/src/calamares/progresstree/ProgressTreeModel.h +++ b/src/calamares/progresstree/ProgressTreeModel.h @@ -20,7 +20,7 @@ #ifndef PROGRESSTREEMODEL_H #define PROGRESSTREEMODEL_H -#include +#include class ProgressTreeRoot; class ProgressTreeItem; @@ -29,7 +29,7 @@ class ProgressTreeItem; /** * @brief The ProgressTreeModel class implements a model for the ProgressTreeView. */ -class ProgressTreeModel : public QAbstractItemModel +class ProgressTreeModel : public QAbstractListModel { Q_OBJECT public: @@ -41,19 +41,8 @@ public: explicit ProgressTreeModel( QObject* parent = nullptr ); 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 headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) 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 diff --git a/src/calamares/progresstree/ViewStepItem.cpp b/src/calamares/progresstree/ViewStepItem.cpp deleted file mode 100644 index bbb2846ce..000000000 --- a/src/calamares/progresstree/ViewStepItem.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2014-2015, Teo Mrnjavac - * - * 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 . - */ - -#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( "Debug information" ); - if ( m_step ) - { - toolTip.append( "
Type:\tViewStep" ); - toolTip.append( QString( "
Pretty:\t%1" ).arg( m_step->prettyName() ) ); - toolTip.append( QString( "
Status:\t%1" ).arg( m_step->prettyStatus() ) ); - toolTip.append( QString( "
Source:\t%1" ) - .arg( m_step->moduleInstanceKey().isValid() ? m_step->moduleInstanceKey().toString() - : QStringLiteral( "built-in" ) ) ); - } - else - { - toolTip.append( "
Type:\tDelegate" ); - toolTip.append( QString( "
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(); -} diff --git a/src/calamares/progresstree/ViewStepItem.h b/src/calamares/progresstree/ViewStepItem.h deleted file mode 100644 index 84b9e0e98..000000000 --- a/src/calamares/progresstree/ViewStepItem.h +++ /dev/null @@ -1,53 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2014-2015, Teo Mrnjavac - * - * 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 . - */ - -#ifndef VIEWSTEPITEM_H -#define VIEWSTEPITEM_H - -#include "ProgressTreeItem.h" - -#include - -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 From d3f55af51ee4a311db0b44ea83a8b672f312647b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Mar 2020 14:13:18 -0500 Subject: [PATCH 03/14] [calamares] Clean up progress tree model - It's still not a real tree - Remove unused classes / files - Apply coding style --- src/calamares/CMakeLists.txt | 1 - .../progresstree/ProgressTreeItem.cpp | 92 ------------------- src/calamares/progresstree/ProgressTreeItem.h | 60 ------------ .../progresstree/ProgressTreeModel.cpp | 21 ++--- .../progresstree/ProgressTreeModel.h | 4 - 5 files changed, 10 insertions(+), 168 deletions(-) delete mode 100644 src/calamares/progresstree/ProgressTreeItem.cpp delete mode 100644 src/calamares/progresstree/ProgressTreeItem.h diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index cb460f14b..5ae4449a7 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -7,7 +7,6 @@ set( calamaresSources VariantModel.cpp progresstree/ProgressTreeDelegate.cpp - progresstree/ProgressTreeItem.cpp progresstree/ProgressTreeModel.cpp progresstree/ProgressTreeView.cpp ) diff --git a/src/calamares/progresstree/ProgressTreeItem.cpp b/src/calamares/progresstree/ProgressTreeItem.cpp deleted file mode 100644 index 4c5b5b0c3..000000000 --- a/src/calamares/progresstree/ProgressTreeItem.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2014, Teo Mrnjavac - * - * 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 . - */ - -#include "ProgressTreeItem.h" - -#include "ProgressTreeModel.h" - - -ProgressTreeItem::ProgressTreeItem( ProgressTreeItem* parent ) -{ - m_parentItem = parent; -} - - -ProgressTreeItem::~ProgressTreeItem() -{ - qDeleteAll( m_childItems ); -} - - -void -ProgressTreeItem::appendChild( ProgressTreeItem* item ) -{ - m_childItems.append( item ); -} - - -ProgressTreeItem* -ProgressTreeItem::child( int row ) -{ - return m_childItems.value( row ); -} - - -int -ProgressTreeItem::childCount() const -{ - return m_childItems.count(); -} - - -int -ProgressTreeItem::columnCount() const -{ - return 1; -} - - -int -ProgressTreeItem::row() const -{ - if ( m_parentItem ) - { - return m_parentItem->m_childItems.indexOf( const_cast< ProgressTreeItem* >( this ) ); - } - return 0; -} - - -ProgressTreeItem* -ProgressTreeItem::parent() -{ - return m_parentItem; -} - - -ProgressTreeRoot::ProgressTreeRoot() - : ProgressTreeItem() -{ -} - - -QVariant -ProgressTreeRoot::data( int ) const -{ - return QVariant(); -} diff --git a/src/calamares/progresstree/ProgressTreeItem.h b/src/calamares/progresstree/ProgressTreeItem.h deleted file mode 100644 index fd93ab0ef..000000000 --- a/src/calamares/progresstree/ProgressTreeItem.h +++ /dev/null @@ -1,60 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2014, Teo Mrnjavac - * - * 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 . - */ - -#ifndef PROGRESSTREEITEM_H -#define PROGRESSTREEITEM_H - -#include -#include - - -/** - * @brief The ProgressTreeItem class represents an item in the - * ProgressTreeModel/ProgressTreeView. - * Each item generally represents a ViewStep. - */ -class ProgressTreeItem -{ -public: - explicit ProgressTreeItem( ProgressTreeItem* parent = nullptr ); - - virtual ~ProgressTreeItem(); - - virtual void appendChild( ProgressTreeItem* item ); - - virtual ProgressTreeItem* child( int row ); - virtual int childCount() const; - virtual int columnCount() const; - virtual QVariant data( int role ) const = 0; - virtual int row() const; - virtual ProgressTreeItem* parent(); - -private: - QList< ProgressTreeItem* > m_childItems; - ProgressTreeItem* m_parentItem; -}; - -class ProgressTreeRoot : public ProgressTreeItem -{ -public: - explicit ProgressTreeRoot(); - - virtual QVariant data( int role ) const; -}; - -#endif // PROGRESSTREEITEM_H diff --git a/src/calamares/progresstree/ProgressTreeModel.cpp b/src/calamares/progresstree/ProgressTreeModel.cpp index 00f2884a3..9127398e8 100644 --- a/src/calamares/progresstree/ProgressTreeModel.cpp +++ b/src/calamares/progresstree/ProgressTreeModel.cpp @@ -27,11 +27,7 @@ ProgressTreeModel::ProgressTreeModel( QObject* parent ) { } - -ProgressTreeModel::~ProgressTreeModel() -{ -} - +ProgressTreeModel::~ProgressTreeModel() {} QVariant ProgressTreeModel::data( const QModelIndex& index, int role ) const @@ -42,14 +38,18 @@ ProgressTreeModel::data( const QModelIndex& index, int role ) const } const Calamares::ViewManager* vm = Calamares::ViewManager::instance(); - if ( !vm) + if ( !vm ) + { return QVariant(); + } const auto steps = vm->viewSteps(); - if ( (index.row() < 0 ) || (index.row() >= steps.length() ) ) + if ( ( index.row() < 0 ) || ( index.row() >= steps.length() ) ) + { return QVariant(); + } - const auto* step = steps.at(index.row()); + const auto* step = steps.at( index.row() ); if ( role == Qt::DisplayRole ) { @@ -65,7 +65,7 @@ ProgressTreeModel::data( const QModelIndex& index, int role ) const toolTip.append( QString( "
Status:\t%1" ).arg( step->prettyStatus() ) ); toolTip.append( QString( "
Source:\t%1" ) .arg( step->moduleInstanceKey().isValid() ? step->moduleInstanceKey().toString() - : QStringLiteral( "built-in" ) ) ); + : QStringLiteral( "built-in" ) ) ); } else { @@ -75,13 +75,12 @@ ProgressTreeModel::data( const QModelIndex& index, int role ) const } if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole ) { - return step && (Calamares::ViewManager::instance()->currentStep() == step); + return step && ( Calamares::ViewManager::instance()->currentStep() == step ); } return QVariant(); } - int ProgressTreeModel::rowCount( const QModelIndex& parent ) const { diff --git a/src/calamares/progresstree/ProgressTreeModel.h b/src/calamares/progresstree/ProgressTreeModel.h index 51f1f4126..e52ecf189 100644 --- a/src/calamares/progresstree/ProgressTreeModel.h +++ b/src/calamares/progresstree/ProgressTreeModel.h @@ -22,10 +22,6 @@ #include -class ProgressTreeRoot; -class ProgressTreeItem; - - /** * @brief The ProgressTreeModel class implements a model for the ProgressTreeView. */ From ba4b42b4eea9b4177ee3cded5bbd21d772e3c848 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Mar 2020 16:52:34 -0500 Subject: [PATCH 04/14] [calamares] Introduce a "completed" role - This is for future support of a QML progress view --- .../progresstree/ProgressTreeModel.cpp | 49 +++++++++++++------ .../progresstree/ProgressTreeModel.h | 3 +- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/calamares/progresstree/ProgressTreeModel.cpp b/src/calamares/progresstree/ProgressTreeModel.cpp index 9127398e8..eb5479e23 100644 --- a/src/calamares/progresstree/ProgressTreeModel.cpp +++ b/src/calamares/progresstree/ProgressTreeModel.cpp @@ -50,34 +50,51 @@ 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 ) { - QString toolTip( "Debug information" ); - if ( step ) + case Qt::DisplayRole: + return step->prettyName(); + case Qt::ToolTipRole: + if ( Calamares::Settings::instance()->debugMode() ) { + auto key = step->moduleInstanceKey(); + QString toolTip( "Debug information" ); toolTip.append( "
Type:\tViewStep" ); toolTip.append( QString( "
Pretty:\t%1" ).arg( step->prettyName() ) ); toolTip.append( QString( "
Status:\t%1" ).arg( step->prettyStatus() ) ); - toolTip.append( QString( "
Source:\t%1" ) - .arg( step->moduleInstanceKey().isValid() ? step->moduleInstanceKey().toString() - : QStringLiteral( "built-in" ) ) ); + toolTip.append( + QString( "
Source:\t%1" ).arg( key.isValid() ? key.toString() : QStringLiteral( "built-in" ) ) ); + return toolTip; } else { - toolTip.append( "
Type:\tDelegate" ); + return QVariant(); } - return toolTip; + 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(); } - if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole ) - { - return step && ( Calamares::ViewManager::instance()->currentStep() == step ); - } - return QVariant(); } diff --git a/src/calamares/progresstree/ProgressTreeModel.h b/src/calamares/progresstree/ProgressTreeModel.h index e52ecf189..9fed4ae1f 100644 --- a/src/calamares/progresstree/ProgressTreeModel.h +++ b/src/calamares/progresstree/ProgressTreeModel.h @@ -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 ); From 04cb5f14f792606f233f04a86b6b96f35045436b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Mar 2020 16:56:22 -0500 Subject: [PATCH 05/14] [calamares] Role names for progress model --- src/calamares/progresstree/ProgressTreeModel.cpp | 9 +++++++++ src/calamares/progresstree/ProgressTreeModel.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/calamares/progresstree/ProgressTreeModel.cpp b/src/calamares/progresstree/ProgressTreeModel.cpp index eb5479e23..d136cbef7 100644 --- a/src/calamares/progresstree/ProgressTreeModel.cpp +++ b/src/calamares/progresstree/ProgressTreeModel.cpp @@ -108,3 +108,12 @@ ProgressTreeModel::rowCount( const QModelIndex& parent ) const 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; +} diff --git a/src/calamares/progresstree/ProgressTreeModel.h b/src/calamares/progresstree/ProgressTreeModel.h index 9fed4ae1f..3553b97d9 100644 --- a/src/calamares/progresstree/ProgressTreeModel.h +++ b/src/calamares/progresstree/ProgressTreeModel.h @@ -40,6 +40,8 @@ public: 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 From 9a63d63d5bfdf776daa4d8ee93de6d838aeb22f3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Mar 2020 17:13:19 -0500 Subject: [PATCH 06/14] [calamares] Factor out the creation of the sidebar --- src/calamares/CalamaresWindow.cpp | 101 +++++++++++++++++------------- src/calamares/CalamaresWindow.h | 2 + 2 files changed, 60 insertions(+), 43 deletions(-) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 1c7ecf813..f3accdd42 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -57,58 +57,19 @@ windowDimensionToPixels( const Calamares::Branding::WindowDimension& u ) return 0; } -CalamaresWindow::CalamaresWindow( QWidget* parent ) - : QWidget( parent ) - , m_debugWindow( nullptr ) - , m_viewManager( nullptr ) + +QWidget* +CalamaresWindow::getWidgetSidebar( int desiredWidth ) { - // If we can never cancel, don't show the window-close button - if ( Calamares::Settings::instance()->disableCancel() ) - { - setWindowFlag( Qt::WindowCloseButtonHint, false ); - } - - CALAMARES_RETRANSLATE( setWindowTitle( Calamares::Settings::instance()->isSetupMode() - ? tr( "%1 Setup Program" ).arg( *Calamares::Branding::ProductName ) - : tr( "%1 Installer" ).arg( *Calamares::Branding::ProductName ) ); ) - const Calamares::Branding* const branding = Calamares::Branding::instance(); - using CalamaresUtils::windowMinimumHeight; - using CalamaresUtils::windowMinimumWidth; - using CalamaresUtils::windowPreferredHeight; - using CalamaresUtils::windowPreferredWidth; - - // Needs to match what's checked in DebugWindow - this->setObjectName( "mainApp" ); - - QSize availableSize = qApp->desktop()->availableGeometry( this ).size(); - QSize minimumSize( qBound( windowMinimumWidth, availableSize.width(), windowPreferredWidth ), - qBound( windowMinimumHeight, availableSize.height(), windowPreferredHeight ) ); - setMinimumSize( minimumSize ); - - cDebug() << "Available desktop" << availableSize << "minimum size" << minimumSize; - - auto brandingSizes = branding->windowSize(); - - int w = qBound( minimumSize.width(), windowDimensionToPixels( brandingSizes.first ), availableSize.width() ); - int h = qBound( minimumSize.height(), windowDimensionToPixels( brandingSizes.second ), availableSize.height() ); - - cDebug() << Logger::SubEntry << "Proposed window size:" << w << h; - resize( w, h ); - - QBoxLayout* mainLayout = new QHBoxLayout; - setLayout( mainLayout ); - QWidget* sideBox = new QWidget( this ); sideBox->setObjectName( "sidebarApp" ); - mainLayout->addWidget( sideBox ); QBoxLayout* sideLayout = new QVBoxLayout; sideBox->setLayout( sideLayout ); // Set this attribute into qss file - sideBox->setFixedWidth( - qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) ); + sideBox->setFixedWidth( desiredWidth ); sideBox->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); QHBoxLayout* logoLayout = new QHBoxLayout; @@ -164,6 +125,60 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) } CalamaresUtils::unmarginLayout( sideLayout ); + return sideBox; +} + + +CalamaresWindow::CalamaresWindow( QWidget* parent ) + : QWidget( parent ) + , m_debugWindow( nullptr ) + , m_viewManager( nullptr ) +{ + // If we can never cancel, don't show the window-close button + if ( Calamares::Settings::instance()->disableCancel() ) + { + setWindowFlag( Qt::WindowCloseButtonHint, false ); + } + + CALAMARES_RETRANSLATE( setWindowTitle( Calamares::Settings::instance()->isSetupMode() + ? tr( "%1 Setup Program" ).arg( *Calamares::Branding::ProductName ) + : tr( "%1 Installer" ).arg( *Calamares::Branding::ProductName ) ); ) + + const Calamares::Branding* const branding = Calamares::Branding::instance(); + + using CalamaresUtils::windowMinimumHeight; + using CalamaresUtils::windowMinimumWidth; + using CalamaresUtils::windowPreferredHeight; + using CalamaresUtils::windowPreferredWidth; + + // Needs to match what's checked in DebugWindow + this->setObjectName( "mainApp" ); + + QSize availableSize = qApp->desktop()->availableGeometry( this ).size(); + QSize minimumSize( qBound( windowMinimumWidth, availableSize.width(), windowPreferredWidth ), + qBound( windowMinimumHeight, availableSize.height(), windowPreferredHeight ) ); + setMinimumSize( minimumSize ); + + cDebug() << "Available desktop" << availableSize << "minimum size" << minimumSize; + + auto brandingSizes = branding->windowSize(); + + int w = qBound( minimumSize.width(), windowDimensionToPixels( brandingSizes.first ), availableSize.width() ); + int h = qBound( minimumSize.height(), windowDimensionToPixels( brandingSizes.second ), availableSize.height() ); + + cDebug() << Logger::SubEntry << "Proposed window size:" << w << h; + resize( w, h ); + + QBoxLayout* mainLayout = new QHBoxLayout; + setLayout( mainLayout ); + + QWidget* sideBox = getWidgetSidebar( + qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) ); + if ( sideBox ) + { + mainLayout->addWidget( sideBox ); + } + CalamaresUtils::unmarginLayout( mainLayout ); m_viewManager = Calamares::ViewManager::instance( this ); diff --git a/src/calamares/CalamaresWindow.h b/src/calamares/CalamaresWindow.h index 03ae560ec..00d50394e 100644 --- a/src/calamares/CalamaresWindow.h +++ b/src/calamares/CalamaresWindow.h @@ -51,6 +51,8 @@ protected: virtual void closeEvent( QCloseEvent* e ) override; private: + QWidget* getWidgetSidebar( int desiredWidth ); + QPointer< Calamares::DebugWindow > m_debugWindow; // Managed by self Calamares::ViewManager* m_viewManager; }; From 80f49bed1daa580e6894a2870454ad50dd4beeca Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Mar 2020 17:59:06 -0500 Subject: [PATCH 07/14] [libcalamaresui] Add a sidebar flavor setting --- src/branding/default/branding.desc | 6 ++++++ src/libcalamaresui/Branding.cpp | 19 ++++++++++++++++++- src/libcalamaresui/Branding.h | 11 +++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index af1d39ca4..c3c0796cd 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -41,6 +41,12 @@ windowSize: 800px,520px # *windowExpanding* set to "fullscreen"). windowPlacement: center +# Kind of sidebar (panel on the left, showing progress). +# - "widget" or unset, use traditional sidebar (logo, items) +# - "none", hide it entirely +# - "qml", use sidebar.qml from branding folder +sidebar: none + # These are strings shown to the user in the user interface. # There is no provision for translating them -- since they # are names, the string is included as-is. diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 9bdccfa51..34ba23436 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -89,6 +89,7 @@ const QStringList Branding::s_styleEntryStrings = // clang-format on // *INDENT-ON* + const NamedEnumTable< Branding::WindowDimensionUnit >& Branding::WindowDimension::suffixes() { @@ -407,14 +408,24 @@ getString( const YAML::Node& doc, const char* key ) void Branding::initSimpleSettings( const YAML::Node& doc ) { + // *INDENT-OFF* + // clang-format off static const NamedEnumTable< WindowExpansion > expansionNames { { QStringLiteral( "normal" ), WindowExpansion::Normal }, { QStringLiteral( "fullscreen" ), WindowExpansion::Fullscreen }, { QStringLiteral( "noexpand" ), WindowExpansion::Fixed } }; static const NamedEnumTable< WindowPlacement > placementNames { - { QStringLiteral( "free" ), WindowPlacement::Free }, { QStringLiteral( "center" ), WindowPlacement::Center } + { QStringLiteral( "free" ), WindowPlacement::Free }, + { QStringLiteral( "center" ), WindowPlacement::Center } }; + static const NamedEnumTable< SidebarFlavor > sidebarFlavorNames { + { QStringLiteral( "widget" ), SidebarFlavor::Widget }, + { QStringLiteral( "none" ), SidebarFlavor::None }, + { QStringLiteral( "qml" ), SidebarFlavor::Qml } + }; + // clang-format on + // *INDENT-ON* bool ok = false; m_welcomeStyleCalamares = doc[ "welcomeStyleCalamares" ].as< bool >( false ); @@ -431,6 +442,12 @@ Branding::initSimpleSettings( const YAML::Node& doc ) cWarning() << "Branding module-setting *windowPlacement* interpreted as" << placementNames.find( m_windowPlacement, ok ); } + m_sidebarFlavor = sidebarFlavorNames.find( getString( doc, "sidebar" ), ok ); + if ( !ok ) + { + cWarning() << "Branding module-setting *sidebar* interpreted as" + << sidebarFlavorNames.find( m_sidebarFlavor, ok ); + } QString windowSize = getString( doc, "windowSize" ); if ( !windowSize.isEmpty() ) diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 3dfcd0586..6bc85875c 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -122,6 +122,15 @@ public: Center, Free }; + Q_ENUM( WindowPlacement ) + ///@brief What kind of sidebar to use in the main window + enum class SidebarFlavor + { + None, + Widget, + Qml + }; + Q_ENUM( SidebarFlavor ) static Branding* instance(); @@ -214,6 +223,8 @@ private: WindowExpansion m_windowExpansion; WindowDimension m_windowHeight, m_windowWidth; WindowPlacement m_windowPlacement; + + SidebarFlavor m_sidebarFlavor = SidebarFlavor::Widget; }; template < typename U > From e9965d37e3a98f2c91964926d87f4d20ebb143b5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Mar 2020 18:05:24 -0500 Subject: [PATCH 08/14] [calamares] Don't create sidebar if we don't want it --- src/calamares/CalamaresWindow.cpp | 8 ++++++-- src/libcalamaresui/Branding.h | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index f3accdd42..d1c6f3bba 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -172,8 +172,12 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) QBoxLayout* mainLayout = new QHBoxLayout; setLayout( mainLayout ); - QWidget* sideBox = getWidgetSidebar( - qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) ); + QWidget* sideBox = nullptr; + if ( branding->sidebarFlavor() == Calamares::Branding::SidebarFlavor::Widget ) + { + sideBox = getWidgetSidebar( + qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) ); + } if ( sideBox ) { mainLayout->addWidget( sideBox ); diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 6bc85875c..88f658473 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -184,6 +184,9 @@ public: } bool windowPlacementCentered() const { return m_windowPlacement == WindowPlacement::Center; } + ///@brief Which sidebar flavor is configured + SidebarFlavor sidebarFlavor() const { return m_sidebarFlavor; } + /** * Creates a map called "branding" in the global storage, and inserts an * entry for each of the branding strings. This makes the branding From 290a708e5684c3b21d269faca401f872fc04edcb Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Mar 2020 21:26:05 -0500 Subject: [PATCH 09/14] [calamares] No need for progresstreeview to be singleton --- src/calamares/progresstree/ProgressTreeView.cpp | 10 ---------- src/calamares/progresstree/ProgressTreeView.h | 4 ---- 2 files changed, 14 deletions(-) diff --git a/src/calamares/progresstree/ProgressTreeView.cpp b/src/calamares/progresstree/ProgressTreeView.cpp index d4f652363..f7496c5fb 100644 --- a/src/calamares/progresstree/ProgressTreeView.cpp +++ b/src/calamares/progresstree/ProgressTreeView.cpp @@ -23,19 +23,9 @@ #include "Branding.h" #include "ViewManager.h" -ProgressTreeView* ProgressTreeView::s_instance = nullptr; - -ProgressTreeView* -ProgressTreeView::instance() -{ - return s_instance; -} - ProgressTreeView::ProgressTreeView( QWidget* parent ) : QTreeView( parent ) { - s_instance = this; //FIXME: should assert when s_instance gets written and it wasn't nullptr - this->setObjectName( "sidebarMenuApp" ); setFrameShape( QFrame::NoFrame ); setContentsMargins( 0, 0, 0, 0 ); diff --git a/src/calamares/progresstree/ProgressTreeView.h b/src/calamares/progresstree/ProgressTreeView.h index 0b48a5f2a..0922bdf0a 100644 --- a/src/calamares/progresstree/ProgressTreeView.h +++ b/src/calamares/progresstree/ProgressTreeView.h @@ -27,14 +27,11 @@ class ProgressTreeDelegate; /** * @brief The ProgressTreeView class is a modified QTreeView which displays the * available view steps and the user's progress through them. - * @note singleton, only access through ProgressTreeView::instance(). */ class ProgressTreeView : public QTreeView { Q_OBJECT public: - static ProgressTreeView* instance(); - explicit ProgressTreeView( QWidget* parent = nullptr ); virtual ~ProgressTreeView() override; @@ -44,7 +41,6 @@ public: void setModel( QAbstractItemModel* model ) override; private: - static ProgressTreeView* s_instance; ProgressTreeDelegate* m_delegate; }; From b209668d3387929cad57b29b35a24a6aa87184f9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 11 Mar 2020 04:37:10 +0100 Subject: [PATCH 10/14] [calamares] Fix singleton-ness of the progress view - Create the ViewManager earlier, - Create a ProgressTreeModel here for the view, - Do not weirdly set the model much later. --- src/calamares/CalamaresApplication.cpp | 4 ++-- src/calamares/CalamaresWindow.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 234d5d45c..576a7c182 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -339,8 +339,8 @@ CalamaresApplication::initViewSteps() m_mainwindow->show(); } - ProgressTreeModel* m = new ProgressTreeModel( nullptr ); - ProgressTreeView::instance()->setModel( m ); + // ProgressTreeModel* m = new ProgressTreeModel( nullptr ); + // ProgressTreeView::instance()->setModel( m ); cDebug() << "STARTUP: Window now visible and ProgressTreeView populated"; const auto steps = Calamares::ViewManager::instance()->viewSteps(); diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index d1c6f3bba..33e3ff3c5 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -25,6 +25,7 @@ #include "DebugWindow.h" #include "Settings.h" #include "ViewManager.h" +#include "progresstree/ProgressTreeModel.h" #include "progresstree/ProgressTreeView.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" @@ -93,8 +94,9 @@ CalamaresWindow::getWidgetSidebar( int desiredWidth ) logoLayout->addStretch(); ProgressTreeView* tv = new ProgressTreeView( sideBox ); - sideLayout->addWidget( tv ); + tv->setModel( new ProgressTreeModel ); tv->setFocusPolicy( Qt::NoFocus ); + sideLayout->addWidget( tv ); if ( Calamares::Settings::instance()->debugMode() || ( Logger::logLevel() >= Logger::LOGVERBOSE ) ) { @@ -169,6 +171,8 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) cDebug() << Logger::SubEntry << "Proposed window size:" << w << h; resize( w, h ); + m_viewManager = Calamares::ViewManager::instance( this ); + QBoxLayout* mainLayout = new QHBoxLayout; setLayout( mainLayout ); @@ -183,9 +187,6 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) mainLayout->addWidget( sideBox ); } - CalamaresUtils::unmarginLayout( mainLayout ); - - m_viewManager = Calamares::ViewManager::instance( this ); if ( branding->windowExpands() ) { connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge ); @@ -200,6 +201,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) // event, which is also the ViewManager's responsibility. mainLayout->addWidget( m_viewManager->centralWidget() ); + CalamaresUtils::unmarginLayout( mainLayout ); setStyleSheet( Calamares::Branding::instance()->stylesheet() ); } From 8f0a6d30656fa40232071826f4d63cba201f62be Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 11 Mar 2020 04:49:38 +0100 Subject: [PATCH 11/14] [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. --- src/calamares/CMakeLists.txt | 1 - src/calamares/CalamaresApplication.cpp | 1 - src/calamares/CalamaresWindow.cpp | 3 +- .../progresstree/ProgressTreeDelegate.cpp | 5 +- .../progresstree/ProgressTreeModel.cpp | 119 ------------------ .../progresstree/ProgressTreeModel.h | 47 ------- src/libcalamaresui/ViewManager.cpp | 83 +++++++++++- src/libcalamaresui/ViewManager.h | 20 ++- 8 files changed, 104 insertions(+), 175 deletions(-) delete mode 100644 src/calamares/progresstree/ProgressTreeModel.cpp delete mode 100644 src/calamares/progresstree/ProgressTreeModel.h diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index 5ae4449a7..78245f614 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -7,7 +7,6 @@ set( calamaresSources VariantModel.cpp progresstree/ProgressTreeDelegate.cpp - progresstree/ProgressTreeModel.cpp progresstree/ProgressTreeView.cpp ) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 576a7c182..2d36f5a49 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -21,7 +21,6 @@ #include "CalamaresConfig.h" #include "CalamaresVersion.h" #include "CalamaresWindow.h" -#include "progresstree/ProgressTreeModel.h" #include "progresstree/ProgressTreeView.h" #include "Branding.h" diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 33e3ff3c5..2e2c776f3 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -25,7 +25,6 @@ #include "DebugWindow.h" #include "Settings.h" #include "ViewManager.h" -#include "progresstree/ProgressTreeModel.h" #include "progresstree/ProgressTreeView.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" @@ -94,7 +93,7 @@ CalamaresWindow::getWidgetSidebar( int desiredWidth ) logoLayout->addStretch(); ProgressTreeView* tv = new ProgressTreeView( sideBox ); - tv->setModel( new ProgressTreeModel ); + tv->setModel( Calamares::ViewManager::instance() ); tv->setFocusPolicy( Qt::NoFocus ); sideLayout->addWidget( tv ); diff --git a/src/calamares/progresstree/ProgressTreeDelegate.cpp b/src/calamares/progresstree/ProgressTreeDelegate.cpp index 9db508c6e..e7041d1b9 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.cpp +++ b/src/calamares/progresstree/ProgressTreeDelegate.cpp @@ -18,11 +18,10 @@ */ #include "ProgressTreeDelegate.h" -#include "ProgressTreeModel.h" #include "CalamaresApplication.h" #include "CalamaresWindow.h" - +#include "ViewManager.h" #include "Branding.h" #include "utils/CalamaresUtilsGui.h" @@ -87,7 +86,7 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, painter->setFont( font ); bool isCurrent = false; - isCurrent = index.data( ProgressTreeModel::ProgressTreeItemCurrentRole ).toBool(); + isCurrent = index.data( Calamares::ViewManager::ProgressTreeItemCurrentRole ).toBool(); if ( isCurrent ) { diff --git a/src/calamares/progresstree/ProgressTreeModel.cpp b/src/calamares/progresstree/ProgressTreeModel.cpp deleted file mode 100644 index d136cbef7..000000000 --- a/src/calamares/progresstree/ProgressTreeModel.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2014-2015, Teo Mrnjavac - * Copyright 2017, Adriaan de Groot - * - * 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 . - */ - -#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( "Debug information" ); - toolTip.append( "
Type:\tViewStep" ); - toolTip.append( QString( "
Pretty:\t%1" ).arg( step->prettyName() ) ); - toolTip.append( QString( "
Status:\t%1" ).arg( step->prettyStatus() ) ); - toolTip.append( - QString( "
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; -} diff --git a/src/calamares/progresstree/ProgressTreeModel.h b/src/calamares/progresstree/ProgressTreeModel.h deleted file mode 100644 index 3553b97d9..000000000 --- a/src/calamares/progresstree/ProgressTreeModel.h +++ /dev/null @@ -1,47 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2014, Teo Mrnjavac - * Copyright 2017, Adriaan de Groot - * - * 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 . - */ - -#ifndef PROGRESSTREEMODEL_H -#define PROGRESSTREEMODEL_H - -#include - -/** - * @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 diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 7492f1f8b..f9fd48dc5 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -75,7 +75,7 @@ setButtonIcon( QPushButton* button, const QString& name ) } ViewManager::ViewManager( QObject* parent ) - : QObject( parent ) + : QAbstractListModel( parent ) , m_currentStep( 0 ) , m_widget( new QWidget() ) { @@ -507,4 +507,85 @@ ViewManager::updateCancelEnabled( bool 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( "Debug information" ); + toolTip.append( "
Type:\tViewStep" ); + toolTip.append( QString( "
Pretty:\t%1" ).arg( step->prettyName() ) ); + toolTip.append( QString( "
Status:\t%1" ).arg( step->prettyStatus() ) ); + toolTip.append( + QString( "
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 diff --git a/src/libcalamaresui/ViewManager.h b/src/libcalamaresui/ViewManager.h index 42fb9ad8f..7ca6eb377 100644 --- a/src/libcalamaresui/ViewManager.h +++ b/src/libcalamaresui/ViewManager.h @@ -23,6 +23,7 @@ #include "DllMacro.h" #include "viewpages/ViewStep.h" +#include #include #include #include @@ -33,7 +34,7 @@ namespace Calamares * @brief The ViewManager class handles progression through view pages. * @note Singleton object, only use through ViewManager::instance(). */ -class UIDLLEXPORT ViewManager : public QObject +class UIDLLEXPORT ViewManager : public QAbstractListModel { Q_OBJECT public: @@ -147,6 +148,23 @@ private: QPushButton* m_back; QPushButton* m_next; 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 From 99c03f7fbb8f35e0254ad72969e098aac30ac6f7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 11 Mar 2020 05:01:39 +0100 Subject: [PATCH 12/14] [libcalamaresui] Behave better as a model --- src/libcalamaresui/ViewManager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index f9fd48dc5..96d4cc3a0 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -157,6 +157,7 @@ ViewManager::addViewStep( ViewStep* step ) void ViewManager::insertViewStep( int before, ViewStep* step ) { + emit beginInsertRows( QModelIndex(), before, before ); m_steps.insert( before, step ); connect( step, &ViewStep::enlarge, this, &ViewManager::enlarge ); connect( step, &ViewStep::nextStatusChanged, this, [this]( bool status ) { @@ -183,6 +184,7 @@ ViewManager::insertViewStep( int before, ViewStep* step ) m_stack->insertWidget( before, step->widget() ); m_stack->setCurrentIndex( 0 ); step->widget()->setFocus(); + emit endInsertRows(); } From 4ab5b4a5e641ad6d3cd350bc2512009bee6886e8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 11 Mar 2020 05:02:06 +0100 Subject: [PATCH 13/14] [calamares] Progress"tree" is a list - No need for a TreeView when it's just a one-dimensional list of items. --- src/calamares/progresstree/ProgressTreeView.cpp | 16 +++------------- src/calamares/progresstree/ProgressTreeView.h | 9 ++------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/calamares/progresstree/ProgressTreeView.cpp b/src/calamares/progresstree/ProgressTreeView.cpp index f7496c5fb..22b11bfc6 100644 --- a/src/calamares/progresstree/ProgressTreeView.cpp +++ b/src/calamares/progresstree/ProgressTreeView.cpp @@ -24,26 +24,17 @@ #include "ViewManager.h" ProgressTreeView::ProgressTreeView( QWidget* parent ) - : QTreeView( parent ) + : QListView( parent ) { this->setObjectName( "sidebarMenuApp" ); setFrameShape( QFrame::NoFrame ); setContentsMargins( 0, 0, 0, 0 ); - setHeaderHidden( true ); - setRootIsDecorated( true ); - setExpandsOnDoubleClick( true ); - setSelectionMode( QAbstractItemView::NoSelection ); setDragDropMode( QAbstractItemView::NoDragDrop ); setAcceptDrops( false ); - setUniformRowHeights( false ); - setIndentation( 0 ); - setSortingEnabled( false ); - - m_delegate = new ProgressTreeDelegate( this ); - setItemDelegate( m_delegate ); + setItemDelegate( new ProgressTreeDelegate( this ) ); QPalette plt = palette(); plt.setColor( QPalette::Base, @@ -63,8 +54,7 @@ ProgressTreeView::setModel( QAbstractItemModel* model ) return; } - QTreeView::setModel( model ); - expandAll(); + QListView::setModel( model ); connect( Calamares::ViewManager::instance(), diff --git a/src/calamares/progresstree/ProgressTreeView.h b/src/calamares/progresstree/ProgressTreeView.h index 0922bdf0a..4a1bf9f2d 100644 --- a/src/calamares/progresstree/ProgressTreeView.h +++ b/src/calamares/progresstree/ProgressTreeView.h @@ -20,15 +20,13 @@ #ifndef PROGRESSTREEVIEW_H #define PROGRESSTREEVIEW_H -#include - -class ProgressTreeDelegate; +#include /** * @brief The ProgressTreeView class is a modified QTreeView which displays the * available view steps and the user's progress through them. */ -class ProgressTreeView : public QTreeView +class ProgressTreeView : public QListView { Q_OBJECT public: @@ -39,9 +37,6 @@ public: * @brief setModel assigns a model to this view. */ void setModel( QAbstractItemModel* model ) override; - -private: - ProgressTreeDelegate* m_delegate; }; #endif // PROGRESSTREEVIEW_H From a0b4d5800040be75c3eecacb54dab7d3e25aea88 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 11 Mar 2020 19:39:28 +0100 Subject: [PATCH 14/14] [calamares] The very simplest of QML sidebars --- src/calamares/CalamaresWindow.cpp | 18 +++++++++++++++++- src/calamares/CalamaresWindow.h | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 2e2c776f3..f65e0acdf 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include static inline int @@ -129,6 +130,13 @@ CalamaresWindow::getWidgetSidebar( int desiredWidth ) return sideBox; } +QWidget* +CalamaresWindow::getQmlSidebar( int desiredWidth ) +{ + QQuickWidget* w = new QQuickWidget( this ); + w->setSource( QUrl( ":/sidebar.qml" ) ); + return w; +} CalamaresWindow::CalamaresWindow( QWidget* parent ) : QWidget( parent ) @@ -176,10 +184,18 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) setLayout( mainLayout ); QWidget* sideBox = nullptr; - if ( branding->sidebarFlavor() == Calamares::Branding::SidebarFlavor::Widget ) + switch ( branding->sidebarFlavor() ) { + case Calamares::Branding::SidebarFlavor::Widget: sideBox = getWidgetSidebar( qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) ); + break; + case Calamares::Branding::SidebarFlavor::Qml: + sideBox = getQmlSidebar( + qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) ); + break; + default: + sideBox = nullptr; } if ( sideBox ) { diff --git a/src/calamares/CalamaresWindow.h b/src/calamares/CalamaresWindow.h index 00d50394e..5cbbdfca6 100644 --- a/src/calamares/CalamaresWindow.h +++ b/src/calamares/CalamaresWindow.h @@ -52,6 +52,7 @@ protected: private: QWidget* getWidgetSidebar( int desiredWidth ); + QWidget* getQmlSidebar( int desiredWidth ); QPointer< Calamares::DebugWindow > m_debugWindow; // Managed by self Calamares::ViewManager* m_viewManager;