[packagechooser] Update other parts of the window on selection

main
Adriaan de Groot 6 years ago
parent f8d159dfa4
commit dc5cdbb38c

@ -28,29 +28,51 @@
PackageChooserPage::PackageChooserPage( QWidget* parent )
: QWidget( parent )
, 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 );
CALAMARES_RETRANSLATE( updateLabels(); )
}
void
PackageChooserPage::updateLabels()
PackageChooserPage::currentChanged( const QModelIndex& index )
{
ui->productName->setText( QString() );
ui->productScreenshot->hide();
ui->productDescription->setText( tr( "Please pick a product from the list." ) );
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
PackageChooserPage::setModel( QAbstractItemModel* model )
PackageChooserPage::updateLabels()
{
ui->products->setModel( model );
if ( ui && ui->products && ui->products->selectionModel() )
{
currentChanged( ui->products->selectionModel()->currentIndex() );
}
else
{
currentChanged( QModelIndex() );
}
}
void
PackageChooserPage::currentChanged( const QModelIndex& current )
PackageChooserPage::setModel( QAbstractItemModel* model )
{
updateLabels();
cDebug() << "Current updated to" << current.row();
cDebug() << ui->products->model()->data( current, Qt::DisplayRole );
ui->products->setModel( model );
connect( ui->products->selectionModel(),
&QItemSelectionModel::selectionChanged,
this,
&PackageChooserPage::updateLabels );
}

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

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

@ -21,6 +21,7 @@
#include <QAbstractListModel>
#include <QObject>
#include <QPixmap>
#include <QVector>
struct PackageItem
@ -32,9 +33,15 @@ struct PackageItem
QString name;
QString description;
// TODO: may be more than one
// QPixmap screenshot;
QPixmap screenshot;
/// @brief Create blank 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 );
// TODO: implement this

Loading…
Cancel
Save