From fe57e862779da63061d9bd939201dbf574a445d3 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sat, 13 Oct 2012 23:14:39 +0200 Subject: [PATCH 1/5] Replaced on_localScan_clicked with selectionChanged handler * A signal handler is now used to process user input for localScan tree, since this will also handle keyboard navigation. * Renamed `handle_selection_change` to `handle_himd_selection_change` to make it unambiguous which selection change should be processed. --- qhimdtransfer/qhimdmainwindow.cpp | 27 ++++++++++++++++----------- qhimdtransfer/qhimdmainwindow.h | 4 ++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/qhimdtransfer/qhimdmainwindow.cpp b/qhimdtransfer/qhimdmainwindow.cpp index b79d9a0..a34bd03 100644 --- a/qhimdtransfer/qhimdmainwindow.cpp +++ b/qhimdtransfer/qhimdmainwindow.cpp @@ -229,7 +229,7 @@ void QHiMDMainWindow::init_himd_browser() for(;i < trackmodel.columnCount(); i++) ui->TrackList->resizeColumnToContents(i); QObject::connect(ui->TrackList->selectionModel(), SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)), - this, SLOT(handle_selection_change(const QItemSelection&, const QItemSelection&))); + this, SLOT(handle_himd_selection_change(const QItemSelection&, const QItemSelection&))); } void QHiMDMainWindow::init_local_browser() @@ -248,6 +248,8 @@ void QHiMDMainWindow::init_local_browser() ui->localScan->hideColumn(2); ui->localScan->hideColumn(3); ui->localScan->setColumnWidth(0, 350); + QObject::connect(ui->localScan->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), + this, SLOT(handle_local_selection_change(const QItemSelection&, const QItemSelection&))); } void QHiMDMainWindow::save_window_settings() @@ -478,27 +480,30 @@ void QHiMDMainWindow::on_action_Connect_triggered() open_himd_at(HiMDDirectory); } -void QHiMDMainWindow::on_localScan_clicked(QModelIndex index) -{ - if(localmodel.fileInfo(index).isDir()) - { - ui->updir->setText(localmodel.filePath(index)); - settings.setValue("lastUploadDirectory", localmodel.filePath(index)); - } -} - void QHiMDMainWindow::on_upload_button_clicked() { upload_to(ui->updir->text()); } -void QHiMDMainWindow::handle_selection_change(const QItemSelection&, const QItemSelection&) +void QHiMDMainWindow::handle_himd_selection_change(const QItemSelection&, const QItemSelection&) { bool nonempty = ui->TrackList->selectionModel()->selectedRows(0).length() != 0; + ui->action_Upload->setEnabled(nonempty); ui->upload_button->setEnabled(nonempty); } +void QHiMDMainWindow::handle_local_selection_change(const QItemSelection&, const QItemSelection&) +{ + QModelIndex index = ui->localScan->currentIndex(); + + if(localmodel.fileInfo(index).isDir()) + { + ui->updir->setText(localmodel.filePath(index)); + settings.setValue("lastUploadDirectory", localmodel.filePath(index)); + } +} + void QHiMDMainWindow::himd_found(QString HiMDPath) { int index; diff --git a/qhimdtransfer/qhimdmainwindow.h b/qhimdtransfer/qhimdmainwindow.h index 0ca406f..2fc2135 100644 --- a/qhimdtransfer/qhimdmainwindow.h +++ b/qhimdtransfer/qhimdmainwindow.h @@ -62,9 +62,9 @@ private slots: void on_action_Download_triggered(); void on_action_Quit_triggered(); void on_action_About_triggered(); - void on_localScan_clicked(QModelIndex index); void on_upload_button_clicked(); - void handle_selection_change(const QItemSelection&, const QItemSelection&); + void handle_himd_selection_change(const QItemSelection&, const QItemSelection&); + void handle_local_selection_change(const QItemSelection&, const QItemSelection&); void himd_found(QString path); void himd_removed(QString path); void on_himd_devices_activated(QString device); -- 1.7.12.3