From d348229028f5e31374b9abfc5cb1bd6c261b9561 Mon Sep 17 00:00:00 2001 From: Srivats P Date: Fri, 8 Sep 2017 21:13:53 +0530 Subject: [PATCH] UX: Improve PortStatsWindow select, toolbar buttons - Automatic full column selection - Enable/Disable toolbar buttons based on selection - Code refactoring to avoid unncessary selectedColumns computation --- client/portstatswindow.cpp | 70 ++++++++++++++++++++++++-------------- client/portstatswindow.h | 6 ++-- client/portstatswindow.ui | 8 +++-- 3 files changed, 55 insertions(+), 29 deletions(-) diff --git a/client/portstatswindow.cpp b/client/portstatswindow.cpp index 0e7b73f..c06177b 100644 --- a/client/portstatswindow.cpp +++ b/client/portstatswindow.cpp @@ -47,6 +47,12 @@ PortStatsWindow::PortStatsWindow(PortGroupList *pgl, QWidget *parent) tvPortStats->verticalHeader()->setDefaultSectionSize( tvPortStats->verticalHeader()->minimumSectionSize()); + connect(tvPortStats->selectionModel(), + SIGNAL(selectionChanged( + const QItemSelection&, const QItemSelection&)), + SLOT(when_tvPortStats_selectionChanged( + const QItemSelection&, const QItemSelection&))); + when_tvPortStats_selectionChanged(QItemSelection(), QItemSelection()); } PortStatsWindow::~PortStatsWindow() @@ -70,12 +76,43 @@ void PortStatsWindow::showMyReservedPortsOnly(bool enabled) } /* ------------- SLOTS (private) -------------- */ + +void PortStatsWindow::when_tvPortStats_selectionChanged( + const QItemSelection& /*selected*/, + const QItemSelection& /*deselected*/) +{ + QModelIndexList indexList = + tvPortStats->selectionModel()->selectedColumns(); + + if (proxyStatsModel) { + selectedColumns.clear(); + foreach(QModelIndex index, indexList) + selectedColumns.append(proxyStatsModel->mapToSource(index)); + } + else + selectedColumns = indexList; + + bool isEmpty = selectedColumns.isEmpty(); + + tbStartTransmit->setDisabled(isEmpty); + tbStopTransmit->setDisabled(isEmpty); + + tbStartCapture->setDisabled(isEmpty); + tbStopCapture->setDisabled(isEmpty); + tbViewCapture->setDisabled(isEmpty); + + tbClear->setDisabled(isEmpty); + + tbResolveNeighbors->setDisabled(isEmpty); + tbClearNeighbors->setDisabled(isEmpty); +} + void PortStatsWindow::on_tbStartTransmit_clicked() { QList pgpl; // Get selected ports - model->portListFromIndex(selectedColumns(), pgpl); + model->portListFromIndex(selectedColumns, pgpl); // Clear selected ports, portgroup by portgroup for (int i = 0; i < pgpl.size(); i++) @@ -90,7 +127,7 @@ void PortStatsWindow::on_tbStopTransmit_clicked() QList pgpl; // Get selected ports - model->portListFromIndex(selectedColumns(), pgpl); + model->portListFromIndex(selectedColumns, pgpl); // Clear selected ports, portgroup by portgroup for (int i = 0; i < pgpl.size(); i++) @@ -106,7 +143,7 @@ void PortStatsWindow::on_tbStartCapture_clicked() QList pgpl; // Get selected ports - model->portListFromIndex(selectedColumns(), pgpl); + model->portListFromIndex(selectedColumns, pgpl); // Clear selected ports, portgroup by portgroup for (int i = 0; i < pgpl.size(); i++) @@ -122,7 +159,7 @@ void PortStatsWindow::on_tbStopCapture_clicked() QList pgpl; // Get selected ports - model->portListFromIndex(selectedColumns(), pgpl); + model->portListFromIndex(selectedColumns, pgpl); // Clear selected ports, portgroup by portgroup for (int i = 0; i < pgpl.size(); i++) @@ -138,7 +175,7 @@ void PortStatsWindow::on_tbViewCapture_clicked() QList pgpl; // Get selected ports - model->portListFromIndex(selectedColumns(), pgpl); + model->portListFromIndex(selectedColumns, pgpl); // Clear selected ports, portgroup by portgroup for (int i = 0; i < pgpl.size(); i++) @@ -153,7 +190,7 @@ void PortStatsWindow::on_tbResolveNeighbors_clicked() QList portList; // Get selected ports - model->portListFromIndex(selectedColumns(), portList); + model->portListFromIndex(selectedColumns, portList); // Resolve ARP/ND for selected ports, portgroup by portgroup for (int i = 0; i < portList.size(); i++) @@ -168,7 +205,7 @@ void PortStatsWindow::on_tbClearNeighbors_clicked() QList portList; // Get selected ports - model->portListFromIndex(selectedColumns(), portList); + model->portListFromIndex(selectedColumns, portList); // Clear ARP/ND for ports, portgroup by portgroup for (int i = 0; i < portList.size(); i++) @@ -183,7 +220,7 @@ void PortStatsWindow::on_tbClear_clicked() QList portList; // Get selected ports - model->portListFromIndex(selectedColumns(), portList); + model->portListFromIndex(selectedColumns, portList); // Clear selected ports, portgroup by portgroup for (int i = 0; i < portList.size(); i++) @@ -252,20 +289,3 @@ void PortStatsWindow::on_tbFilter_clicked() hv->moveSection(hv->visualIndex(newColumns.at(vi)), vi); } } - -/* ------------ Private Methods -------------- */ - -QModelIndexList PortStatsWindow::selectedColumns() -{ - QModelIndexList indexList = - tvPortStats->selectionModel()->selectedColumns(); - QModelIndexList sourceIndexList; - - if (!proxyStatsModel) - return indexList; - - foreach(QModelIndex index, indexList) - sourceIndexList.append(proxyStatsModel->mapToSource(index)); - - return sourceIndexList; -} diff --git a/client/portstatswindow.h b/client/portstatswindow.h index dfb5fbf..e5d993a 100644 --- a/client/portstatswindow.h +++ b/client/portstatswindow.h @@ -40,6 +40,9 @@ public slots: void showMyReservedPortsOnly(bool enabled); private slots: + void when_tvPortStats_selectionChanged(const QItemSelection &selected, + const QItemSelection &deselected); + void on_tbStartTransmit_clicked(); void on_tbStopTransmit_clicked(); @@ -56,11 +59,10 @@ private slots: void on_tbFilter_clicked(); private: - QModelIndexList selectedColumns(); - PortGroupList *pgl; PortStatsModel *model; QSortFilterProxyModel *proxyStatsModel; + QModelIndexList selectedColumns; }; diff --git a/client/portstatswindow.ui b/client/portstatswindow.ui index 1406a4b..f285b37 100644 --- a/client/portstatswindow.ui +++ b/client/portstatswindow.ui @@ -237,7 +237,7 @@ Qt::Horizontal - + 40 20 @@ -263,7 +263,11 @@ - + + + QAbstractItemView::SelectColumns + +