diff --git a/src/calamares/progresstree/ProgressTreeDelegate.cpp b/src/calamares/progresstree/ProgressTreeDelegate.cpp index 67dfeebda..5fb9dbf8b 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.cpp +++ b/src/calamares/progresstree/ProgressTreeDelegate.cpp @@ -20,23 +20,28 @@ #include "ProgressTreeDelegate.h" #include "ProgressTreeModel.h" -#include "Branding.h" #include "CalamaresApplication.h" #include "CalamaresWindow.h" +#include "Branding.h" #include "utils/CalamaresUtilsGui.h" #include static constexpr int const item_margin = 8; -static inline int item_fontsize() { return CalamaresUtils::defaultFontSize() + 4; } +static inline int +item_fontsize() +{ + return CalamaresUtils::defaultFontSize() + 4; +} QSize -ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, - const QModelIndex& index ) const +ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const { if ( !index.isValid() ) + { return option.rect.size(); + } QFont font = qApp->font(); @@ -51,9 +56,7 @@ ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, void -ProgressTreeDelegate::paint( QPainter* painter, - const QStyleOptionViewItem& option, - const QModelIndex& index) const +ProgressTreeDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { QStyleOptionViewItem opt = option; @@ -62,10 +65,9 @@ ProgressTreeDelegate::paint( QPainter* painter, initStyleOption( &opt, index ); opt.text.clear(); - painter->setBrush( QColor( Calamares::Branding::instance()-> - styleString( Calamares::Branding::SidebarBackground ) ) ); - painter->setPen( QColor( Calamares::Branding::instance()-> - styleString( Calamares::Branding::SidebarText ) ) ); + painter->setBrush( + QColor( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackground ) ) ); + painter->setPen( QColor( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarText ) ) ); paintViewStep( painter, opt, index ); @@ -89,14 +91,17 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, if ( isCurrent ) { - painter->setPen( Calamares::Branding::instance()-> - styleString( Calamares::Branding::SidebarTextSelect ) ); - QString textHighlight = Calamares::Branding::instance()-> - styleString( Calamares::Branding::SidebarTextHighlight ); + painter->setPen( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarTextSelect ) ); + QString textHighlight + = Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarTextHighlight ); if ( textHighlight.isEmpty() ) + { painter->setBrush( CalamaresApplication::instance()->mainWindow()->palette().background() ); + } else + { painter->setBrush( QColor( textHighlight ) ); + } } @@ -114,17 +119,19 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, shrinkSteps++; QRectF boundingBox; - painter->drawText( textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString(), &boundingBox ); + painter->drawText( + textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString(), &boundingBox ); // The extra check here is to avoid the changing-font-size if we're not going to use // it in the next iteration of the loop anyway. - if ( ( shrinkSteps <= maximumShrink ) && (boundingBox.width() > textRect.width() ) ) + if ( ( shrinkSteps <= maximumShrink ) && ( boundingBox.width() > textRect.width() ) ) { font.setPointSize( item_fontsize() - shrinkSteps ); painter->setFont( font ); } else + { break; // It fits - } - while ( shrinkSteps <= maximumShrink ); + } + } while ( shrinkSteps <= maximumShrink ); } diff --git a/src/calamares/progresstree/ProgressTreeDelegate.h b/src/calamares/progresstree/ProgressTreeDelegate.h index 554824e06..d36bd4d14 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.h +++ b/src/calamares/progresstree/ProgressTreeDelegate.h @@ -33,16 +33,11 @@ public: using QStyledItemDelegate::QStyledItemDelegate; protected: - QSize sizeHint( const QStyleOptionViewItem& option, - const QModelIndex& index ) const override; - void paint( QPainter* painter, - const QStyleOptionViewItem& option, - const QModelIndex& index ) const override; + QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override; + void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override; private: - void paintViewStep( QPainter* painter, - const QStyleOptionViewItem& option, - const QModelIndex& index ) const; + void paintViewStep( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; }; #endif // PROGRESSTREEDELEGATE_H diff --git a/src/calamares/progresstree/ProgressTreeItem.cpp b/src/calamares/progresstree/ProgressTreeItem.cpp index 0445962ab..4c5b5b0c3 100644 --- a/src/calamares/progresstree/ProgressTreeItem.cpp +++ b/src/calamares/progresstree/ProgressTreeItem.cpp @@ -65,8 +65,9 @@ int ProgressTreeItem::row() const { if ( m_parentItem ) - return m_parentItem->m_childItems.indexOf( - const_cast< ProgressTreeItem* >( this ) ); + { + return m_parentItem->m_childItems.indexOf( const_cast< ProgressTreeItem* >( this ) ); + } return 0; } @@ -80,7 +81,8 @@ ProgressTreeItem::parent() ProgressTreeRoot::ProgressTreeRoot() : ProgressTreeItem() -{} +{ +} QVariant diff --git a/src/calamares/progresstree/ProgressTreeModel.cpp b/src/calamares/progresstree/ProgressTreeModel.cpp index e3b4fa030..d4b5a0321 100644 --- a/src/calamares/progresstree/ProgressTreeModel.cpp +++ b/src/calamares/progresstree/ProgressTreeModel.cpp @@ -19,7 +19,8 @@ #include "ProgressTreeModel.h" -#include "progresstree/ViewStepItem.h" +#include "ViewStepItem.h" + #include "ViewManager.h" ProgressTreeModel::ProgressTreeModel( QObject* parent ) @@ -40,7 +41,9 @@ Qt::ItemFlags ProgressTreeModel::flags( const QModelIndex& index ) const { if ( !index.isValid() ) + { return Qt::ItemFlags(); + } return Qt::ItemIsEnabled; } @@ -50,20 +53,30 @@ 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(); + } } @@ -71,13 +84,17 @@ 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 ); } @@ -87,7 +104,9 @@ QVariant ProgressTreeModel::data( const QModelIndex& index, int role ) const { if ( !index.isValid() ) + { return QVariant(); + } ProgressTreeItem* item = static_cast< ProgressTreeItem* >( index.internalPointer() ); @@ -111,12 +130,18 @@ 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(); } @@ -126,9 +151,13 @@ int ProgressTreeModel::columnCount( const QModelIndex& parent ) const { if ( parent.isValid() ) + { return static_cast< ProgressTreeItem* >( parent.internalPointer() )->columnCount(); + } else + { return m_rootItem->columnCount(); + } } @@ -152,7 +181,9 @@ 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 @@ -172,10 +203,13 @@ ProgressTreeModel::indexFromItem( ProgressTreeItem* item ) **/ 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 + while ( curItem != m_rootItem ) + { + int row = curItem->row(); //relative to its parent + if ( row < 0 ) // something went wrong, bail + { return QModelIndex(); + } childIndexList << row; @@ -184,7 +218,7 @@ ProgressTreeModel::indexFromItem( ProgressTreeItem* item ) // Now we rebuild the QModelIndex we need QModelIndex idx; - for ( int i = childIndexList.size() - 1; i >= 0 ; i-- ) + for ( int i = childIndexList.size() - 1; i >= 0; i-- ) { idx = index( childIndexList[ i ], 0, idx ); } diff --git a/src/calamares/progresstree/ProgressTreeView.cpp b/src/calamares/progresstree/ProgressTreeView.cpp index 079592848..5c81e3851 100644 --- a/src/calamares/progresstree/ProgressTreeView.cpp +++ b/src/calamares/progresstree/ProgressTreeView.cpp @@ -19,8 +19,9 @@ #include "ProgressTreeView.h" #include "ProgressTreeDelegate.h" -#include "ViewManager.h" + #include "Branding.h" +#include "ViewManager.h" ProgressTreeView* ProgressTreeView::s_instance = nullptr; @@ -33,9 +34,9 @@ ProgressTreeView::instance() ProgressTreeView::ProgressTreeView( QWidget* parent ) : QTreeView( parent ) { - s_instance = this; //FIXME: should assert when s_instance gets written and it wasn't nullptr + s_instance = this; //FIXME: should assert when s_instance gets written and it wasn't nullptr - this->setObjectName("sidebarMenuApp"); + this->setObjectName( "sidebarMenuApp" ); setFrameShape( QFrame::NoFrame ); setContentsMargins( 0, 0, 0, 0 ); @@ -55,31 +56,29 @@ ProgressTreeView::ProgressTreeView( QWidget* parent ) setItemDelegate( m_delegate ); QPalette plt = palette(); - plt.setColor( QPalette::Base, Calamares::Branding::instance()-> - styleString( Calamares::Branding::SidebarBackground ) ); + plt.setColor( QPalette::Base, + Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackground ) ); setPalette( plt ); } -ProgressTreeView::~ProgressTreeView() -{ -} +ProgressTreeView::~ProgressTreeView() {} void ProgressTreeView::setModel( QAbstractItemModel* model ) { if ( ProgressTreeView::model() ) + { return; + } QTreeView::setModel( model ); expandAll(); connect( Calamares::ViewManager::instance(), &Calamares::ViewManager::currentStepChanged, - this, [this]() - { - viewport()->update(); - }, - Qt::UniqueConnection ); + this, + [this]() { viewport()->update(); }, + Qt::UniqueConnection ); } diff --git a/src/calamares/progresstree/ViewStepItem.cpp b/src/calamares/progresstree/ViewStepItem.cpp index fe2fe6034..5af73fcfd 100644 --- a/src/calamares/progresstree/ViewStepItem.cpp +++ b/src/calamares/progresstree/ViewStepItem.cpp @@ -19,6 +19,7 @@ #include "ViewStepItem.h" #include "ProgressTreeModel.h" + #include "Settings.h" #include "ViewManager.h" #include "viewpages/ViewStep.h" @@ -35,8 +36,7 @@ ViewStepItem::ViewStepItem( std::function< QString() > prettyName, } -ViewStepItem::ViewStepItem( const Calamares::ViewStep* step, - ProgressTreeItem* parent ) +ViewStepItem::ViewStepItem( const Calamares::ViewStep* step, ProgressTreeItem* parent ) : ProgressTreeItem( parent ) { m_step = step; @@ -55,8 +55,7 @@ ViewStepItem::data( int role ) const { if ( role == Qt::DisplayRole ) { - return m_step ? m_step->prettyName() - : m_prettyName(); + return m_step ? m_step->prettyName() : m_prettyName(); } if ( Calamares::Settings::instance()->debugMode() && role == Qt::ToolTipRole ) { @@ -66,9 +65,9 @@ ViewStepItem::data( int role ) const 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().isEmpty() ? "built-in" - : m_step->moduleInstanceKey() ) ); + toolTip.append( + QString( "
Source:\t%1" ) + .arg( m_step->moduleInstanceKey().isEmpty() ? "built-in" : m_step->moduleInstanceKey() ) ); } else { @@ -78,8 +77,7 @@ ViewStepItem::data( int role ) const return toolTip; } if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole ) - return m_step ? - ( Calamares::ViewManager::instance()->currentStep() == m_step ) : - ( Calamares::ViewManager::instance()->currentStep() == m_accessor() ); + 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 index 5a7c79b4a..3095ef43b 100644 --- a/src/calamares/progresstree/ViewStepItem.h +++ b/src/calamares/progresstree/ViewStepItem.h @@ -37,8 +37,7 @@ public: std::function< const Calamares::ViewStep*() > accessor, ProgressTreeItem* parent = nullptr ); - explicit ViewStepItem( const Calamares::ViewStep* step, - ProgressTreeItem* parent = nullptr ); + explicit ViewStepItem( const Calamares::ViewStep* step, ProgressTreeItem* parent = nullptr ); void appendChild( ProgressTreeItem* item ) override;