[netinstall] Rip out derpy translations of PackageModel

- The model always has two columns, and the column names are always
  the same. We don't need to specially set headers for that.
- Use QCoreApplication::translation() to re-use the existing
  translations and avoid creating "new" strings (in a new context).
This commit is contained in:
Adriaan de Groot 2020-02-19 12:51:01 +01:00
parent da66ef42d7
commit c20f7ee534
3 changed files with 13 additions and 32 deletions

View File

@ -66,15 +66,9 @@ NetInstallPage::setPageTitle( CalamaresUtils::Locale::TranslatedString* t )
retranslate(); retranslate();
} }
void void
NetInstallPage::retranslate() NetInstallPage::retranslate()
{ {
if ( m_groups )
{
m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) );
m_groups->setHeaderData( 1, Qt::Horizontal, tr( "Description" ) );
}
if ( ui && m_title ) if ( ui && m_title )
{ {
ui->label->setText( m_title->get() ); // That's get() on the TranslatedString ui->label->setText( m_title->get() ); // That's get() on the TranslatedString

View File

@ -21,9 +21,11 @@
#include "utils/Yaml.h" #include "utils/Yaml.h"
// TODO: see headerData(), remove after 3.2.19
#include <QCoreApplication>
PackageModel::PackageModel( const YAML::Node& data, QObject* parent ) PackageModel::PackageModel( const YAML::Node& data, QObject* parent )
: QAbstractItemModel( parent ) : QAbstractItemModel( parent )
, m_columnHeadings()
{ {
m_rootItem = new PackageTreeItem(); m_rootItem = new PackageTreeItem();
setupModelData( data, m_rootItem ); setupModelData( data, m_rootItem );
@ -150,26 +152,6 @@ PackageModel::setData( const QModelIndex& index, const QVariant& value, int role
return true; return true;
} }
bool
PackageModel::setHeaderData( int section, Qt::Orientation orientation, const QVariant& value, int role )
{
Q_UNUSED( role )
if ( orientation == Qt::Horizontal )
{
if ( m_columnHeadings.value( section ) != QVariant() )
{
m_columnHeadings.replace( section, value );
}
else
{
m_columnHeadings.insert( section, value );
}
emit headerDataChanged( orientation, section, section );
}
return true;
}
Qt::ItemFlags Qt::ItemFlags
PackageModel::flags( const QModelIndex& index ) const PackageModel::flags( const QModelIndex& index ) const
{ {
@ -189,7 +171,12 @@ 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 m_columnHeadings.value( section ); // Unusual translation call uses the existing translation from the NetInstallPage
// class (now removed).
//
// TODO: after 3.2.19, change this to just tr() and push TX
return ( section == 0 ) ? QCoreApplication::translate( "NetInstallPage", "Name" )
: QCoreApplication::translate( "NetInstallPage", "Description" );
} }
return QVariant(); return QVariant();
} }

View File

@ -44,14 +44,15 @@ public:
QVariant data( const QModelIndex& index, int role ) const override; QVariant data( const QModelIndex& index, int role ) const override;
bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ) override; bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ) override;
bool
setHeaderData( int section, Qt::Orientation orientation, const QVariant& value, int role = Qt::EditRole ) override;
Qt::ItemFlags flags( const QModelIndex& index ) const override; Qt::ItemFlags flags( const QModelIndex& index ) const override;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override; QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override;
QModelIndex parent( const QModelIndex& index ) const override; QModelIndex parent( const QModelIndex& index ) const override;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
int rowCount( const QModelIndex& parent = QModelIndex() ) const override; int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
int columnCount( const QModelIndex& parent = QModelIndex() ) const override; int columnCount( const QModelIndex& parent = QModelIndex() ) const override;
PackageItemDataList getPackages() const; PackageItemDataList getPackages() const;
QList< PackageTreeItem* > getItemPackages( PackageTreeItem* item ) const; QList< PackageTreeItem* > getItemPackages( PackageTreeItem* item ) const;
@ -60,7 +61,6 @@ private:
PackageTreeItem* m_rootItem; PackageTreeItem* m_rootItem;
QList< PackageTreeItem* > m_hiddenItems; QList< PackageTreeItem* > m_hiddenItems;
QVariantList m_columnHeadings;
}; };
#endif // PACKAGEMODEL_H #endif // PACKAGEMODEL_H