summaryrefslogtreecommitdiffstats
path: root/examples/testapp
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2011-06-01 14:55:19 +0200
committerkh1 <qt-info@nokia.com>2011-06-01 14:55:19 +0200
commit351907678da36edc59df7b3006168bd1940c6a47 (patch)
tree88e346d7148d648003e2872a550077a640eee90f /examples/testapp
parenta48a6eec657840b5a5068537e6fd88a3c1303207 (diff)
Adjust to fit the new component model.
Diffstat (limited to 'examples/testapp')
-rw-r--r--examples/testapp/componentselectiondialog.cpp90
-rw-r--r--examples/testapp/componentselectiondialog.h17
2 files changed, 45 insertions, 62 deletions
diff --git a/examples/testapp/componentselectiondialog.cpp b/examples/testapp/componentselectiondialog.cpp
index 4062857e4..b7f620d39 100644
--- a/examples/testapp/componentselectiondialog.cpp
+++ b/examples/testapp/componentselectiondialog.cpp
@@ -33,18 +33,19 @@
#include "componentselectiondialog.h"
#include "ui_componentselectiondialog.h"
-#include <QPushButton>
-#include <QHeaderView>
-
#include <componentmodel.h>
#include <qinstaller.h>
#include <qinstallercomponent.h>
+#include <QtGui/QHeaderView>
+#include <QtGui/QPushButton>
+
using namespace QInstaller;
class ComponentSelectionDialog::Private : public QObject
{
Q_OBJECT
+
public:
Private(ComponentSelectionDialog *qq, Installer *inst)
: q(qq),
@@ -52,32 +53,21 @@ public:
{
}
- void selectionChanged()
+ void currentChanged(const QModelIndex &index)
{
- int selectionCount = 0;
- // no component selected disables the ok button
- foreach (Component *component, installer->components(true, UpdaterMode)) {
- if (component->isSelected())
- ++selectionCount;
- }
-
- installBtn->setEnabled(selectionCount > 0);
+ installBtn->setEnabled(componentModel->hasCheckedComponents());
+ const int selectionCount = componentModel->checkedComponents().count();
installBtn->setText(selectionCount > 1 ? tr("Install %1 Items").arg(selectionCount) :
selectionCount == 1 ? tr("Install 1 Item") : tr("Install"));
+ ui.buttonBox->button(QDialogButtonBox::Cancel)->setText(selectionCount > 0 ? tr("Cancel")
+ : tr("Close"));
- if (selectionCount > 0) {
- ui.buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
+ if (index.isValid()) {
+ ui.textBrowser->setHtml(componentModel->data(componentModel->index(index.row(), 0,
+ index.parent()), Qt::ToolTipRole).toString());
} else {
- ui.buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Close"));
- }
-
- const QModelIndex index = ui.treeView->currentIndex();
- if (!index.isValid()) {
ui.textBrowser->clear();
- return;
}
-
- ui.textBrowser->setHtml(index.sibling(index.row(), 0).data(Qt::ToolTipRole).toString());
}
void modelReset()
@@ -93,7 +83,6 @@ public:
hasChildren = ui.treeView->model()->hasChildren(ui.treeView->model()->index(row, 0));
ui.treeView->setRootIsDecorated(hasChildren);
ui.treeView->expandToDepth(0);
- selectionChanged();
}
private:
@@ -112,14 +101,12 @@ public Q_SLOTS:
void ComponentSelectionDialog::Private::selectAll()
{
- foreach (Component *component, installer->components(false, UpdaterMode))
- component->setSelected(true);
+ componentModel->selectAll();
}
void ComponentSelectionDialog::Private::deselectAll()
{
- foreach (Component *component, installer->components(false, UpdaterMode))
- component->setSelected(false);
+ componentModel->deselectAll();
}
@@ -130,38 +117,40 @@ ComponentSelectionDialog::ComponentSelectionDialog(Installer *installer, QWidget
d(new Private(this, installer))
{
d->ui.setupUi(this);
+ d->ui.icon->setPixmap(windowIcon().pixmap(48, 48));
+
+ d->ui.splitter->setStretchFactor(0, 2);
+ d->ui.splitter->setStretchFactor(1, 1);
+ d->ui.splitter->setCollapsible(0, false);
+
d->componentModel = new ComponentModel(5, installer);
+ d->componentModel->setHeaderData(0, Qt::Horizontal, tr("Name"));
+ d->componentModel->setHeaderData(1, Qt::Horizontal, tr("Installed Version"));
+ d->componentModel->setHeaderData(2, Qt::Horizontal, tr("New Version"));
+ d->componentModel->setHeaderData(3, Qt::Horizontal, tr("Size"));
+
d->ui.treeView->setModel(d->componentModel);
-
- d->ui.labelLicenseBlurb->setAttribute(Qt::WA_MacSmallSize);
- d->ui.labelSubTitle->setAttribute(Qt::WA_MacSmallSize);
d->ui.treeView->setAttribute(Qt::WA_MacShowFocusRect, false);
+ connect(d->ui.treeView->model(), SIGNAL(modelReset()), this, SLOT(modelReset()));
+ connect(d->ui.treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+ this, SLOT(currentChanged(QModelIndex)));
+
+ d->ui.labelSubTitle->setAttribute(Qt::WA_MacSmallSize);
+ d->ui.labelLicenseBlurb->setAttribute(Qt::WA_MacSmallSize);
d->ui.textBrowser->setAttribute(Qt::WA_MacShowFocusRect, false);
- d->ui.splitter->setCollapsible(0, false);
+
d->installBtn = d->ui.buttonBox->addButton(tr("Install"), QDialogButtonBox::AcceptRole) ;
if (!d->ui.buttonBox->button(QDialogButtonBox::Cancel)->icon().isNull())
d->installBtn->setIcon(style()->standardIcon(QStyle::SP_DialogOkButton));
- d->ui.icon->setPixmap(windowIcon().pixmap(48, 48));
-
- connect(d->ui.treeView->model(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
- this, SLOT(selectionChanged()));
- connect(d->ui.treeView->model(), SIGNAL(modelReset()),
- this, SLOT(modelReset()));
- connect(d->ui.treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- this, SLOT(selectionChanged()));
connect(d->installBtn, SIGNAL(clicked()), this, SIGNAL(requestUpdate()));
connect(d->ui.selectAll, SIGNAL(clicked()), d, SLOT(selectAll()), Qt::QueuedConnection);
connect(d->ui.deselectAll, SIGNAL(clicked()), d, SLOT(deselectAll()), Qt::QueuedConnection);
-
- d->ui.treeView->setCurrentIndex(d->ui.treeView->model()->index(0, 0));
- d->ui.splitter->setStretchFactor(0, 2);
- d->ui.splitter->setStretchFactor(1, 1);
d->ui.treeView->header()->setStretchLastSection(true);
+ d->ui.treeView->setCurrentIndex(d->ui.treeView->model()->index(0, 0));
for (int i = 0; i < d->ui.treeView->model()->columnCount(); ++i)
d->ui.treeView->resizeColumnToContents(i);
- d->selectionChanged();
d->modelReset();
}
@@ -185,25 +174,20 @@ void ComponentSelectionDialog::install()
emit requestUpdate();
}
-void ComponentSelectionDialog::selectComponent(const QString& id)
+void ComponentSelectionDialog::selectComponent(const QString &id)
{
const QModelIndex &idx = d->componentModel->indexFromComponentName(id);
if (!idx.isValid())
return;
- d->componentModel->setData(idx, Qt::Checked);
+ d->componentModel->setData(idx, Qt::Checked, Qt::CheckStateRole);
}
-void ComponentSelectionDialog::deselectComponent(const QString& id)
+void ComponentSelectionDialog::deselectComponent(const QString &id)
{
const QModelIndex &idx = d->componentModel->indexFromComponentName(id);
if (!idx.isValid())
return;
- d->componentModel->setData(idx, Qt::Unchecked);
-}
-
-void ComponentSelectionDialog::refreshDialog()
-{
- d->selectionChanged();
+ d->componentModel->setData(idx, Qt::Unchecked, Qt::CheckStateRole);
}
#include "moc_componentselectiondialog.cpp"
diff --git a/examples/testapp/componentselectiondialog.h b/examples/testapp/componentselectiondialog.h
index f75a62c7b..609d08eb4 100644
--- a/examples/testapp/componentselectiondialog.h
+++ b/examples/testapp/componentselectiondialog.h
@@ -37,26 +37,25 @@ class ComponentSelectionDialog : public QDialog
Q_OBJECT
public:
- explicit ComponentSelectionDialog( QInstaller::Installer* installer, QWidget* parent = 0 );
+ explicit ComponentSelectionDialog(QInstaller::Installer *installer, QWidget *parent = 0);
virtual ~ComponentSelectionDialog();
- Q_INVOKABLE void selectComponent( const QString& compoenent );
- Q_INVOKABLE void deselectComponent( const QString& component );
+
+ Q_INVOKABLE void selectComponent(const QString &compoenent);
+ Q_INVOKABLE void deselectComponent(const QString &component);
Q_INVOKABLE void selectAll();
Q_INVOKABLE void deselectAll();
Q_INVOKABLE void install();
-public Q_SLOTS:
- void refreshDialog();
-
Q_SIGNALS:
void requestUpdate();
private:
+ Q_PRIVATE_SLOT(d, void modelReset())
+ Q_PRIVATE_SLOT(d, void currentChanged(const QModelIndex &index))
+
+private:
class Private;
Private *d;
-
- Q_PRIVATE_SLOT( d, void selectionChanged() )
- Q_PRIVATE_SLOT( d, void modelReset() )
};
#endif