UX: Improve PortStatsWindow select, toolbar buttons

- Automatic full column selection
- Enable/Disable toolbar buttons based on selection
- Code refactoring to avoid unncessary selectedColumns computation
This commit is contained in:
Srivats P 2017-09-08 21:13:53 +05:30
parent 88cea753b6
commit d348229028
3 changed files with 55 additions and 29 deletions

View File

@ -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<PortStatsModel::PortGroupAndPortList> 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<PortStatsModel::PortGroupAndPortList> 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<PortStatsModel::PortGroupAndPortList> 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<PortStatsModel::PortGroupAndPortList> 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<PortStatsModel::PortGroupAndPortList> 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<PortStatsModel::PortGroupAndPortList> 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<PortStatsModel::PortGroupAndPortList> 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<PortStatsModel::PortGroupAndPortList> 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;
}

View File

@ -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;
};

View File

@ -237,7 +237,7 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint">
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
@ -263,7 +263,11 @@
</widget>
</item>
<item>
<widget class="QTableView" name="tvPortStats"/>
<widget class="QTableView" name="tvPortStats">
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectColumns</enum>
</property>
</widget>
</item>
</layout>
</widget>