[calamares] Reformat the progresstree

- add { } to single-line blocks
 - group some includes better
 - lines broken at a different length, some shuffling around of
   parameter lists.
This commit is contained in:
Adriaan de Groot 2019-06-11 13:19:53 +02:00
parent 8053bf6f3a
commit 9235499f7f
7 changed files with 94 additions and 60 deletions

View File

@ -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 <QPainter>
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,15 +91,18 @@ 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 ) );
}
}
// Draw the text at least once. If it doesn't fit, then shrink the font
@ -114,7 +119,8 @@ 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.
@ -124,7 +130,8 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
painter->setFont( font );
}
else
{
break; // It fits
}
while ( shrinkSteps <= maximumShrink );
} while ( shrinkSteps <= maximumShrink );
}

View File

@ -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

View File

@ -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

View File

@ -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,34 +53,48 @@ 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 );
}
@ -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,10 +151,14 @@ int
ProgressTreeModel::columnCount( const QModelIndex& parent ) const
{
if ( parent.isValid() )
{
return static_cast< ProgressTreeItem* >( parent.internalPointer() )->columnCount();
}
else
{
return m_rootItem->columnCount();
}
}
void
@ -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 ) {
while ( curItem != m_rootItem )
{
int row = curItem->row(); //relative to its parent
if ( row < 0 ) // something went wrong, bail
{
return QModelIndex();
}
childIndexList << row;

View File

@ -19,8 +19,9 @@
#include "ProgressTreeView.h"
#include "ProgressTreeDelegate.h"
#include "ViewManager.h"
#include "Branding.h"
#include "ViewManager.h"
ProgressTreeView* ProgressTreeView::s_instance = nullptr;
@ -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();
},
this,
[this]() { viewport()->update(); },
Qt::UniqueConnection );
}

View File

@ -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( "<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().isEmpty() ? "built-in"
: m_step->moduleInstanceKey() ) );
toolTip.append(
QString( "<br/>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();
}

View File

@ -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;