From 231f6c67b00d1e8e2a7810eb8a1737dd7e7d9f90 Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Mon, 16 Jun 2014 16:22:36 +0200 Subject: Fix missing details on startup Fix that default selection is obscure --- src/dialog.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index 5118cbb..f6b67b1 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -23,6 +23,7 @@ Dialog::Dialog(QWidget *parent) model_[2] = new SessionTreeModel(parent); ui->setupUi(this); + tabs_[0] = ui->tabButtonLocal; tabs_[1] = ui->tabButtonMyClasses; tabs_[2] = ui->tabButtonAllClasses; @@ -47,10 +48,15 @@ Dialog::Dialog(QWidget *parent) ui->helpBox->hide(); ui->newsBox->hide(); + oldRow_ = 0; // this is the old row (when switching to a new tab) + this->addStatusString(STR_LOADING); + /* + * TODO: why connect signal/slot when no item was loaded yet? QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); + */ this->onTabButtonChanged(2); @@ -230,7 +236,7 @@ bool Dialog::selectSession(const QString& name) { // set selection ui->treeView->selectionModel()->clearSelection(); ui->treeView->selectionModel() - ->setCurrentIndex(index, QItemSelectionModel::Select); + ->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); return true; } } @@ -367,6 +373,9 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) { this->addStatusString(STR_NO_ITEMS); } + // give focus to treeView + ui->treeView->setFocus(); + // select last-session selectPreviousSession(); } @@ -442,9 +451,14 @@ void Dialog::onTabButtonChanged(int tab) { this->ui->filterEdit->setText(""); } + // save old row + //oldRow_ = ui->treeView->selectionModel()->currentIndex().row(); + // load the new list setListModel(model_[tab]); this->activeTab_ = tab; + ui->treeView->selectionModel()->select(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select); + treeView_selectionChanged(ui->treeView->model()->index(oldRow_, 0, ui->treeView->rootIndex()), ui->treeView->model()->index(0, 0, ui->treeView->rootIndex())); } void Dialog::on_filterEdit_textChanged() { @@ -468,11 +482,13 @@ void Dialog::setListModel(QAbstractItemModel *model) { ui->treeView->setModel(model); // reconnect the treeModel - QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), + QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); - if (ui->treeView->selectionModel()->selectedRows(0).count() == 0) { - ui->treeView->selectionModel()->setCurrentIndex(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select); + // select the first element, if no element is selected + if (ui->treeView->selectionModel()->selectedRows().count() == 0) { + //ui->treeView->selectionModel()->setCurrentIndex(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select); + ui->treeView->selectionModel()->select(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select); } } -- cgit v1.2.3-55-g7522