Feature: Show My Reserved Ports Only linked to Port Stats window also
This commit is contained in:
parent
ad3a279cd6
commit
efbc2dcf48
@ -100,6 +100,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
connect(actionViewShowMyReservedPortsOnly, SIGNAL(toggled(bool)),
|
||||
portsWindow, SLOT(showMyReservedPortsOnly(bool)));
|
||||
connect(actionViewShowMyReservedPortsOnly, SIGNAL(toggled(bool)),
|
||||
statsWindow, SLOT(showMyReservedPortsOnly(bool)));
|
||||
|
||||
connect(updater, SIGNAL(newVersionAvailable(QString)),
|
||||
this, SLOT(onNewVersion(QString)));
|
||||
|
@ -42,8 +42,9 @@ HEADERS += \
|
||||
portgroup.h \
|
||||
portgrouplist.h \
|
||||
portmodel.h \
|
||||
portstatsmodel.h \
|
||||
portstatsfilterdialog.h \
|
||||
portstatsmodel.h \
|
||||
portstatsproxymodel.h \
|
||||
portstatswindow.h \
|
||||
portswindow.h \
|
||||
preferences.h \
|
||||
|
@ -118,6 +118,10 @@ QVariant PortStatsModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
switch(row)
|
||||
{
|
||||
// Info
|
||||
case e_INFO_USER:
|
||||
return pgl->mPortGroups.at(pgidx)->mPorts[pidx]->userName();
|
||||
|
||||
// States
|
||||
case e_LINK_STATE:
|
||||
return LinkStateName.at(stats.state().link_state());
|
||||
@ -179,12 +183,10 @@ QVariant PortStatsModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
else if (role == Qt::TextAlignmentRole)
|
||||
{
|
||||
if (row >= e_STATE_START && row <= e_STATE_END)
|
||||
return Qt::AlignHCenter;
|
||||
else if (row >= e_STATISTICS_START && row <= e_STATISTICS_END)
|
||||
return Qt::AlignRight;
|
||||
if (row >= e_STATISTICS_START && row <= e_STATISTICS_END)
|
||||
return Qt::AlignRight; // right-align numbers
|
||||
else
|
||||
return QVariant();
|
||||
return Qt::AlignHCenter; // center-align everything else
|
||||
}
|
||||
else
|
||||
return QVariant();
|
||||
@ -299,6 +301,8 @@ void PortStatsModel::when_portListChanged()
|
||||
reset();
|
||||
}
|
||||
|
||||
// FIXME: unused? if used, the index calculation row/column needs to be swapped
|
||||
#if 0
|
||||
void PortStatsModel::on_portStatsUpdate(int port, void* /*stats*/)
|
||||
{
|
||||
QModelIndex topLeft = index(port, 0, QModelIndex());
|
||||
@ -306,6 +310,7 @@ void PortStatsModel::on_portStatsUpdate(int port, void* /*stats*/)
|
||||
|
||||
emit dataChanged(topLeft, bottomRight);
|
||||
}
|
||||
#endif
|
||||
|
||||
void PortStatsModel::updateStats()
|
||||
{
|
||||
@ -320,7 +325,7 @@ void PortStatsModel::when_portGroup_stats_update(quint32 /*portGroupId*/)
|
||||
// FIXME(MED): update only the changed ports, not all
|
||||
|
||||
QModelIndex topLeft = index(0, 0, QModelIndex());
|
||||
QModelIndex bottomRight = index(rowCount(), columnCount(), QModelIndex());
|
||||
QModelIndex bottomRight = index(rowCount()-1, columnCount()-1, QModelIndex());
|
||||
|
||||
emit dataChanged(topLeft, bottomRight);
|
||||
}
|
||||
|
@ -26,8 +26,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
class QTimer;
|
||||
|
||||
typedef enum {
|
||||
// Info
|
||||
e_INFO_START = 0,
|
||||
|
||||
e_INFO_USER = e_INFO_START,
|
||||
|
||||
e_INFO_END = e_INFO_USER,
|
||||
|
||||
// State
|
||||
e_STATE_START = 0,
|
||||
e_STATE_START,
|
||||
|
||||
e_LINK_STATE = e_STATE_START,
|
||||
e_TRANSMIT_STATE,
|
||||
@ -65,6 +72,8 @@ typedef enum {
|
||||
} PortStat;
|
||||
|
||||
static QStringList PortStatName = (QStringList()
|
||||
<< "User"
|
||||
|
||||
<< "Link State"
|
||||
<< "Transmit State"
|
||||
<< "Capture State"
|
||||
@ -127,7 +136,7 @@ class PortStatsModel : public QAbstractTableModel
|
||||
|
||||
public slots:
|
||||
void when_portListChanged();
|
||||
void on_portStatsUpdate(int port, void*stats);
|
||||
//void on_portStatsUpdate(int port, void*stats);
|
||||
void when_portGroup_stats_update(quint32 portGroupId);
|
||||
|
||||
private slots:
|
||||
|
52
client/portstatsproxymodel.h
Normal file
52
client/portstatsproxymodel.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright (C) 2015 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _PORT_STATS_PROXY_MODEL_H
|
||||
#define _PORT_STATS_PROXY_MODEL_H
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
class PortStatsProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PortStatsProxyModel(QObject *parent = 0)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
bool filterAcceptsColumn(int sourceColumn,
|
||||
const QModelIndex &sourceParent) const
|
||||
{
|
||||
QModelIndex index = sourceModel()->index(0, sourceColumn, sourceParent);
|
||||
QString user = sourceModel()->data(index).toString();
|
||||
|
||||
return filterRegExp().exactMatch(user) ? true : false;
|
||||
}
|
||||
bool filterAcceptsRow(int sourceRow,
|
||||
const QModelIndex &sourceParent) const
|
||||
{
|
||||
// Hide row 0 - username (needed only by this filter class)
|
||||
return (sourceRow > 0) ? true : false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -19,19 +19,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
|
||||
#include "portstatswindow.h"
|
||||
#include "portstatsmodel.h"
|
||||
#include "portstatsfilterdialog.h"
|
||||
|
||||
#include "QHeaderView"
|
||||
#include "portstatsfilterdialog.h"
|
||||
#include "portstatsmodel.h"
|
||||
#include "portstatsproxymodel.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
|
||||
PortStatsWindow::PortStatsWindow(PortGroupList *pgl, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent), proxyStatsModel(NULL)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
this->pgl = pgl;
|
||||
model = pgl->getPortStatsModel();
|
||||
tvPortStats->setModel(model);
|
||||
|
||||
proxyStatsModel = new PortStatsProxyModel(this);
|
||||
if (proxyStatsModel) {
|
||||
proxyStatsModel->setSourceModel(model);
|
||||
tvPortStats->setModel(proxyStatsModel);
|
||||
}
|
||||
else
|
||||
tvPortStats->setModel(model);
|
||||
|
||||
tvPortStats->verticalHeader()->setHighlightSections(false);
|
||||
tvPortStats->verticalHeader()->setDefaultSectionSize(
|
||||
@ -41,17 +51,31 @@ PortStatsWindow::PortStatsWindow(PortGroupList *pgl, QWidget *parent)
|
||||
|
||||
PortStatsWindow::~PortStatsWindow()
|
||||
{
|
||||
delete proxyStatsModel;
|
||||
}
|
||||
|
||||
/* ------------- SLOTS -------------- */
|
||||
/* ------------- SLOTS (public) -------------- */
|
||||
|
||||
void PortStatsWindow::showMyReservedPortsOnly(bool enabled)
|
||||
{
|
||||
if (!proxyStatsModel)
|
||||
return;
|
||||
|
||||
if (enabled) {
|
||||
QString rx(appSettings->value(kUserKey, kUserDefaultValue).toString());
|
||||
proxyStatsModel->setFilterRegExp(QRegExp::escape(rx));
|
||||
}
|
||||
else
|
||||
proxyStatsModel->setFilterRegExp(QRegExp(".*")); // match all
|
||||
}
|
||||
|
||||
/* ------------- SLOTS (private) -------------- */
|
||||
void PortStatsWindow::on_tbStartTransmit_clicked()
|
||||
{
|
||||
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
||||
|
||||
// Get selected ports
|
||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
||||
pgpl);
|
||||
model->portListFromIndex(selectedColumns(), pgpl);
|
||||
|
||||
// Clear selected ports, portgroup by portgroup
|
||||
for (int i = 0; i < pgpl.size(); i++)
|
||||
@ -66,8 +90,7 @@ void PortStatsWindow::on_tbStopTransmit_clicked()
|
||||
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
||||
|
||||
// Get selected ports
|
||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
||||
pgpl);
|
||||
model->portListFromIndex(selectedColumns(), pgpl);
|
||||
|
||||
// Clear selected ports, portgroup by portgroup
|
||||
for (int i = 0; i < pgpl.size(); i++)
|
||||
@ -83,8 +106,7 @@ void PortStatsWindow::on_tbStartCapture_clicked()
|
||||
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
||||
|
||||
// Get selected ports
|
||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
||||
pgpl);
|
||||
model->portListFromIndex(selectedColumns(), pgpl);
|
||||
|
||||
// Clear selected ports, portgroup by portgroup
|
||||
for (int i = 0; i < pgpl.size(); i++)
|
||||
@ -100,8 +122,7 @@ void PortStatsWindow::on_tbStopCapture_clicked()
|
||||
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
||||
|
||||
// Get selected ports
|
||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
||||
pgpl);
|
||||
model->portListFromIndex(selectedColumns(), pgpl);
|
||||
|
||||
// Clear selected ports, portgroup by portgroup
|
||||
for (int i = 0; i < pgpl.size(); i++)
|
||||
@ -117,8 +138,7 @@ void PortStatsWindow::on_tbViewCapture_clicked()
|
||||
QList<PortStatsModel::PortGroupAndPortList> pgpl;
|
||||
|
||||
// Get selected ports
|
||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
||||
pgpl);
|
||||
model->portListFromIndex(selectedColumns(), pgpl);
|
||||
|
||||
// Clear selected ports, portgroup by portgroup
|
||||
for (int i = 0; i < pgpl.size(); i++)
|
||||
@ -133,8 +153,7 @@ void PortStatsWindow::on_tbClear_clicked()
|
||||
QList<PortStatsModel::PortGroupAndPortList> portList;
|
||||
|
||||
// Get selected ports
|
||||
model->portListFromIndex(tvPortStats->selectionModel()->selectedColumns(),
|
||||
portList);
|
||||
model->portListFromIndex(selectedColumns(), portList);
|
||||
|
||||
// Clear selected ports, portgroup by portgroup
|
||||
for (int i = 0; i < portList.size(); i++)
|
||||
@ -146,6 +165,7 @@ void PortStatsWindow::on_tbClear_clicked()
|
||||
|
||||
void PortStatsWindow::on_tbClearAll_clicked()
|
||||
{
|
||||
// FIXME: we clear all, not just all ports currently displayed!!!
|
||||
for (int i = 0; i < pgl->numPortGroups(); i++)
|
||||
{
|
||||
pgl->portGroupByIndex(i).clearPortStats();
|
||||
@ -157,10 +177,14 @@ void PortStatsWindow::on_tbFilter_clicked()
|
||||
bool ok;
|
||||
QList<uint> currentColumns, newColumns;
|
||||
PortStatsFilterDialog dialog;
|
||||
QAbstractItemModel *mdl = model;
|
||||
|
||||
if (proxyStatsModel)
|
||||
mdl = proxyStatsModel;
|
||||
|
||||
// create the input list for the filter dialog -
|
||||
// list of logical-indexes ordered by their current visual indexes
|
||||
for(int vi = 0; vi < model->columnCount(); vi++) {
|
||||
for(int vi = 0; vi < mdl->columnCount(); vi++) {
|
||||
int li = tvPortStats->horizontalHeader()->logicalIndex(vi);
|
||||
if (!tvPortStats->isColumnHidden(li)) {
|
||||
currentColumns.append(li);
|
||||
@ -169,14 +193,14 @@ void PortStatsWindow::on_tbFilter_clicked()
|
||||
|
||||
// return list from the filter dialog -
|
||||
// list of logical-indexes ordered by their new visual indexes
|
||||
newColumns = dialog.getItemList(&ok, model, Qt::Horizontal, currentColumns);
|
||||
newColumns = dialog.getItemList(&ok, mdl, Qt::Horizontal, currentColumns);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
QHeaderView *hv = tvPortStats->horizontalHeader();
|
||||
|
||||
// hide/show sections first ...
|
||||
for(int li = 0; li < model->columnCount(); li++)
|
||||
for(int li = 0; li < mdl->columnCount(); li++)
|
||||
tvPortStats->setColumnHidden(li, !newColumns.contains(li));
|
||||
|
||||
// ... then for the 'shown' columns, set the visual index
|
||||
@ -184,3 +208,20 @@ 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;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "portgrouplist.h"
|
||||
#include "portstatsmodel.h"
|
||||
|
||||
class QSortFilterProxyModel;
|
||||
|
||||
class PortStatsWindow : public QWidget, public Ui::PortStatsWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -34,9 +36,8 @@ public:
|
||||
PortStatsWindow(PortGroupList *pgl, QWidget *parent = 0);
|
||||
~PortStatsWindow();
|
||||
|
||||
private:
|
||||
PortGroupList *pgl;
|
||||
PortStatsModel *model;
|
||||
public slots:
|
||||
void showMyReservedPortsOnly(bool enabled);
|
||||
|
||||
private slots:
|
||||
void on_tbStartTransmit_clicked();
|
||||
@ -50,6 +51,14 @@ private slots:
|
||||
void on_tbClearAll_clicked();
|
||||
|
||||
void on_tbFilter_clicked();
|
||||
|
||||
private:
|
||||
QModelIndexList selectedColumns();
|
||||
|
||||
PortGroupList *pgl;
|
||||
PortStatsModel *model;
|
||||
QSortFilterProxyModel *proxyStatsModel;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user