[netinstall] Introduce constexpr names for columns and roles

This commit is contained in:
Adriaan de Groot 2020-03-10 12:22:56 -05:00
parent 3d68c74a19
commit df86972ea7
2 changed files with 13 additions and 3 deletions

View File

@ -117,7 +117,7 @@ PackageModel::data( const QModelIndex& index, int role ) const
} }
PackageTreeItem* item = static_cast< PackageTreeItem* >( index.internalPointer() ); PackageTreeItem* item = static_cast< PackageTreeItem* >( index.internalPointer() );
if ( index.column() == 0 && role == Qt::CheckStateRole ) if ( index.column() == NameColumn && role == Qt::CheckStateRole )
{ {
return item->isSelected(); return item->isSelected();
} }
@ -156,7 +156,7 @@ PackageModel::flags( const QModelIndex& index ) const
{ {
return Qt::ItemFlags(); return Qt::ItemFlags();
} }
if ( index.column() == 0 ) if ( index.column() == NameColumn )
{ {
return Qt::ItemIsUserCheckable | QAbstractItemModel::flags( index ); return Qt::ItemIsUserCheckable | QAbstractItemModel::flags( index );
} }
@ -168,7 +168,7 @@ PackageModel::headerData( int section, Qt::Orientation orientation, int role ) c
{ {
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
{ {
return ( section == 0 ) ? tr( "Name" ) : tr( "Description" ); return ( section == NameColumn ) ? tr( "Name" ) : tr( "Description" );
} }
return QVariant(); return QVariant();
} }

View File

@ -39,6 +39,16 @@ class PackageModel : public QAbstractItemModel
public: public:
using PackageItemDataList = QList< PackageTreeItem::ItemData >; using PackageItemDataList = QList< PackageTreeItem::ItemData >;
// Names for columns (unused in the code)
static constexpr const int NameColumn = 0;
static constexpr const int DescriptionColumn = 1;
/* The only interesting roles are DisplayRole (with text depending
* on the column, and MetaExpandRole which tells if an index
* should be initially expanded.
*/
static constexpr const int MetaExpandRole = Qt::UserRole + 1;
explicit PackageModel( const YAML::Node& data, QObject* parent = nullptr ); explicit PackageModel( const YAML::Node& data, QObject* parent = nullptr );
~PackageModel() override; ~PackageModel() override;