[libcalamaresui] Expose just currentIndex

- drop the current and completed roles, and expose only
  the currentIndex. QML can use the QObject property on
  the model, while QWidgets can call internally through
  the model's data() function.
- we don't need to provide role names for this, so drop that bit.
- simplify the delegate code while here.
This commit is contained in:
Adriaan de Groot 2020-03-30 14:14:10 +02:00
parent aad79f664e
commit 3d7e5bc90d
3 changed files with 1 additions and 34 deletions

View File

@ -85,10 +85,7 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
font.setBold( false );
painter->setFont( font );
bool isCurrent = false;
isCurrent = index.data( Calamares::ViewManager::ProgressTreeItemCurrentRole ).toBool();
if ( isCurrent )
if ( index.row() == index.data( Calamares::ViewManager::ProgressTreeItemCurrentIndex ).toInt() )
{
painter->setPen( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarTextSelect ) );
QString textHighlight

View File

@ -561,23 +561,6 @@ ViewManager::data( const QModelIndex& index, int role ) const
}
case ProgressTreeItemCurrentIndex:
return m_currentStep;
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();
}
@ -594,13 +577,4 @@ ViewManager::rowCount( const QModelIndex& parent ) const
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

View File

@ -153,15 +153,11 @@ public:
*/
enum Role
{
ProgressTreeItemCurrentRole = Qt::UserRole + 11, ///< Is this the *current* step?
ProgressTreeItemCompletedRole = Qt::UserRole + 12, ///< Are we past this one?
ProgressTreeItemCurrentIndex = Qt::UserRole + 13 ///< Index (row) of the current step
};
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