[packagechooser] Update other parts of the window on selection

This commit is contained in:
Adriaan de Groot 2019-08-02 16:07:47 +02:00
parent f8d159dfa4
commit dc5cdbb38c
4 changed files with 45 additions and 14 deletions

View File

@ -28,29 +28,51 @@
PackageChooserPage::PackageChooserPage( QWidget* parent ) PackageChooserPage::PackageChooserPage( QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, ui( new Ui::PackageChooserPage ) , ui( new Ui::PackageChooserPage )
, m_introduction( QString(),
QString(),
tr( "Package Selection" ),
tr( "Please pick a product from the list. The selected product will be installed." ) )
{ {
ui->setupUi( this ); ui->setupUi( this );
CALAMARES_RETRANSLATE( updateLabels(); ) CALAMARES_RETRANSLATE( updateLabels(); )
} }
void
PackageChooserPage::currentChanged( const QModelIndex& index )
{
if ( !index.isValid() || !ui->products->selectionModel()->hasSelection() )
{
ui->productName->setText( m_introduction.name );
ui->productScreenshot->setPixmap( m_introduction.screenshot );
ui->productDescription->setText( m_introduction.description );
}
else
{
ui->productName->setText( QString::number( index.row() ) );
ui->productScreenshot->hide();
ui->productDescription->setText( "derp" );
}
}
void void
PackageChooserPage::updateLabels() PackageChooserPage::updateLabels()
{ {
ui->productName->setText( QString() ); if ( ui && ui->products && ui->products->selectionModel() )
ui->productScreenshot->hide(); {
ui->productDescription->setText( tr( "Please pick a product from the list." ) ); currentChanged( ui->products->selectionModel()->currentIndex() );
}
else
{
currentChanged( QModelIndex() );
}
} }
void void
PackageChooserPage::setModel( QAbstractItemModel* model ) PackageChooserPage::setModel( QAbstractItemModel* model )
{ {
ui->products->setModel( model ); ui->products->setModel( model );
} connect( ui->products->selectionModel(),
&QItemSelectionModel::selectionChanged,
void this,
PackageChooserPage::currentChanged( const QModelIndex& current ) &PackageChooserPage::updateLabels );
{
updateLabels();
cDebug() << "Current updated to" << current.row();
cDebug() << ui->products->model()->data( current, Qt::DisplayRole );
} }

View File

@ -19,6 +19,8 @@
#ifndef PACKAGECHOOSERPAGE_H #ifndef PACKAGECHOOSERPAGE_H
#define PACKAGECHOOSERPAGE_H #define PACKAGECHOOSERPAGE_H
#include "PackageModel.h"
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QWidget> #include <QWidget>
@ -36,11 +38,12 @@ public:
void setModel( QAbstractItemModel* model ); void setModel( QAbstractItemModel* model );
public slots: public slots:
void currentChanged( const QModelIndex& index );
void updateLabels(); void updateLabels();
void currentChanged( const QModelIndex& current );
private: private:
Ui::PackageChooserPage* ui; Ui::PackageChooserPage* ui;
PackageItem m_introduction;
}; };
#endif // PACKAGECHOOSERPAGE_H #endif // PACKAGECHOOSERPAGE_H

View File

@ -73,7 +73,6 @@ PackageListModel::rowCount( const QModelIndex& index ) const
QVariant QVariant
PackageListModel::data( const QModelIndex& index, int role ) const PackageListModel::data( const QModelIndex& index, int role ) const
{ {
cDebug() << "Data" << m_packages.count() << index.isValid() << ( index.isValid() ? index.row() : -1 );
if ( !index.isValid() ) if ( !index.isValid() )
{ {
return QVariant(); return QVariant();

View File

@ -21,6 +21,7 @@
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QObject> #include <QObject>
#include <QPixmap>
#include <QVector> #include <QVector>
struct PackageItem struct PackageItem
@ -32,9 +33,15 @@ struct PackageItem
QString name; QString name;
QString description; QString description;
// TODO: may be more than one // TODO: may be more than one
// QPixmap screenshot; QPixmap screenshot;
/// @brief Create blank PackageItem
PackageItem(); PackageItem();
/** @brief Creates a PackageItem from given strings
*
* This constructor sets all the text members,
* but leaves the screenshot blank. Set that separately.
*/
PackageItem( const QString& id, const QString& package, const QString& name, const QString& description ); PackageItem( const QString& id, const QString& package, const QString& name, const QString& description );
// TODO: implement this // TODO: implement this