Feature: Show My Reserved Ports Only
This commit is contained in:
parent
7dc7a840f1
commit
05b73a5390
@ -93,6 +93,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
connect(actionFileExit, SIGNAL(triggered()), this, SLOT(close()));
|
connect(actionFileExit, SIGNAL(triggered()), this, SLOT(close()));
|
||||||
connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
||||||
|
|
||||||
|
connect(actionViewShowMyReservedPortsOnly, SIGNAL(toggled(bool)),
|
||||||
|
portsWindow, SLOT(showMyReservedPortsOnly(bool)));
|
||||||
|
|
||||||
connect(updater, SIGNAL(newVersionAvailable(QString)),
|
connect(updater, SIGNAL(newVersionAvailable(QString)),
|
||||||
this, SLOT(onNewVersion(QString)));
|
this, SLOT(onNewVersion(QString)));
|
||||||
updater->checkForNewVersion();
|
updater->checkForNewVersion();
|
||||||
|
@ -40,7 +40,14 @@
|
|||||||
<addaction name="actionHelpAbout" />
|
<addaction name="actionHelpAbout" />
|
||||||
<addaction name="actionAboutQt" />
|
<addaction name="actionAboutQt" />
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuView" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>&View</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionViewShowMyReservedPortsOnly" />
|
||||||
|
</widget>
|
||||||
<addaction name="menuFile" />
|
<addaction name="menuFile" />
|
||||||
|
<addaction name="menuView" />
|
||||||
<addaction name="menuHelp" />
|
<addaction name="menuHelp" />
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar" />
|
<widget class="QStatusBar" name="statusbar" />
|
||||||
@ -76,6 +83,14 @@
|
|||||||
<string>About Qt</string>
|
<string>About Qt</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionViewShowMyReservedPortsOnly" >
|
||||||
|
<property name="checkable" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Show My &Reserved Ports Only</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="ostinato.qrc" />
|
<include location="ostinato.qrc" />
|
||||||
|
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include "abstractfileformat.h"
|
#include "abstractfileformat.h"
|
||||||
#include "portconfigdialog.h"
|
#include "portconfigdialog.h"
|
||||||
|
#include "settings.h"
|
||||||
#include "streamconfigdialog.h"
|
#include "streamconfigdialog.h"
|
||||||
#include "streamlistdelegate.h"
|
#include "streamlistdelegate.h"
|
||||||
|
|
||||||
@ -28,13 +29,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QItemSelectionModel>
|
#include <QItemSelectionModel>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
|
PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent), proxyPortModel(NULL)
|
||||||
{
|
{
|
||||||
QAction *sep;
|
QAction *sep;
|
||||||
|
|
||||||
delegate = new StreamListDelegate;
|
delegate = new StreamListDelegate;
|
||||||
|
proxyPortModel = new QSortFilterProxyModel(this);
|
||||||
|
|
||||||
//slm = new StreamListModel();
|
//slm = new StreamListModel();
|
||||||
//plm = new PortGroupList();
|
//plm = new PortGroupList();
|
||||||
plm = pgl;
|
plm = pgl;
|
||||||
@ -78,6 +82,22 @@ PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
|
|||||||
addActions(tvStreamList->actions());
|
addActions(tvStreamList->actions());
|
||||||
|
|
||||||
tvStreamList->setModel(plm->getStreamModel());
|
tvStreamList->setModel(plm->getStreamModel());
|
||||||
|
|
||||||
|
// XXX: It would be ideal if we only needed to do the below to
|
||||||
|
// get the proxy model to do its magic. However, the QModelIndex
|
||||||
|
// used by the source model and the proxy model are different
|
||||||
|
// i.e. the row, column, internalId/internalPtr used by both
|
||||||
|
// will be different. Since our domain objects - PortGroupList,
|
||||||
|
// PortGroup, Port etc. use these attributes, we need to map the
|
||||||
|
// proxy's index to the source's index before invoking any domain
|
||||||
|
// object methods
|
||||||
|
// TODO: research if we can skip the mapping when the domain
|
||||||
|
// objects' design is reviewed
|
||||||
|
if (proxyPortModel) {
|
||||||
|
proxyPortModel->setSourceModel(plm->getPortModel());
|
||||||
|
tvPortList->setModel(proxyPortModel);
|
||||||
|
}
|
||||||
|
else
|
||||||
tvPortList->setModel(plm->getPortModel());
|
tvPortList->setModel(plm->getPortModel());
|
||||||
|
|
||||||
connect( plm->getPortModel(),
|
connect( plm->getPortModel(),
|
||||||
@ -122,41 +142,74 @@ PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
|
|||||||
|
|
||||||
void PortsWindow::streamModelDataChanged()
|
void PortsWindow::streamModelDataChanged()
|
||||||
{
|
{
|
||||||
if (plm->isPort(tvPortList->currentIndex()))
|
QModelIndex current = tvPortList->currentIndex();
|
||||||
plm->port(tvPortList->currentIndex()).recalculateAverageRates();
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
|
if (plm->isPort(current))
|
||||||
|
plm->port(current).recalculateAverageRates();
|
||||||
}
|
}
|
||||||
|
|
||||||
PortsWindow::~PortsWindow()
|
PortsWindow::~PortsWindow()
|
||||||
{
|
{
|
||||||
delete delegate;
|
delete delegate;
|
||||||
|
delete proxyPortModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PortsWindow::showMyReservedPortsOnly(bool enabled)
|
||||||
|
{
|
||||||
|
if (!proxyPortModel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (enabled) {
|
||||||
|
QString rx = "Port Group|\\[xxx\\]";
|
||||||
|
rx.replace("xxx",
|
||||||
|
appSettings->value(kUserKey, kUserDefaultValue).toString());
|
||||||
|
qDebug("%s: regexp: <%s>", __FUNCTION__, qPrintable(rx));
|
||||||
|
proxyPortModel->setFilterRegExp(QRegExp(rx));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
proxyPortModel->setFilterRegExp(QRegExp(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortsWindow::on_tvStreamList_activated(const QModelIndex & index)
|
void PortsWindow::on_tvStreamList_activated(const QModelIndex & index)
|
||||||
{
|
{
|
||||||
|
QModelIndex currentPort = tvPortList->currentIndex();
|
||||||
StreamConfigDialog *scd;
|
StreamConfigDialog *scd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
currentPort = proxyPortModel->mapToSource(currentPort);
|
||||||
|
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
{
|
{
|
||||||
qDebug("%s: invalid index", __FUNCTION__);
|
qDebug("%s: invalid index", __FUNCTION__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scd = new StreamConfigDialog(plm->port(tvPortList->currentIndex()),
|
scd = new StreamConfigDialog(plm->port(currentPort), index.row(), this);
|
||||||
index.row(), this);
|
|
||||||
qDebug("stream list activated\n");
|
qDebug("stream list activated\n");
|
||||||
ret = scd->exec();
|
ret = scd->exec();
|
||||||
|
|
||||||
if (ret == QDialog::Accepted)
|
if (ret == QDialog::Accepted)
|
||||||
plm->port(tvPortList->currentIndex()).recalculateAverageRates();
|
plm->port(currentPort).recalculateAverageRates();
|
||||||
|
|
||||||
delete scd;
|
delete scd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortsWindow::when_portView_currentChanged(const QModelIndex& current,
|
void PortsWindow::when_portView_currentChanged(const QModelIndex& currentIndex,
|
||||||
const QModelIndex& previous)
|
const QModelIndex& previousIndex)
|
||||||
{
|
{
|
||||||
|
QModelIndex current = currentIndex;
|
||||||
|
QModelIndex previous = previousIndex;
|
||||||
|
|
||||||
|
if (proxyPortModel) {
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
previous = proxyPortModel->mapToSource(previous);
|
||||||
|
}
|
||||||
|
|
||||||
plm->getStreamModel()->setCurrentPortIndex(current);
|
plm->getStreamModel()->setCurrentPortIndex(current);
|
||||||
updatePortViewActions(current);
|
updatePortViewActions(currentIndex);
|
||||||
updateStreamViewActions();
|
updateStreamViewActions();
|
||||||
|
|
||||||
qDebug("In %s", __FUNCTION__);
|
qDebug("In %s", __FUNCTION__);
|
||||||
@ -217,6 +270,9 @@ void PortsWindow::on_averagePacketsPerSec_editingFinished()
|
|||||||
{
|
{
|
||||||
QModelIndex current = tvPortList->currentIndex();
|
QModelIndex current = tvPortList->currentIndex();
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
Q_ASSERT(plm->isPort(current));
|
Q_ASSERT(plm->isPort(current));
|
||||||
|
|
||||||
bool isOk;
|
bool isOk;
|
||||||
@ -229,6 +285,9 @@ void PortsWindow::on_averageBitsPerSec_editingFinished()
|
|||||||
{
|
{
|
||||||
QModelIndex current = tvPortList->currentIndex();
|
QModelIndex current = tvPortList->currentIndex();
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
Q_ASSERT(plm->isPort(current));
|
Q_ASSERT(plm->isPort(current));
|
||||||
|
|
||||||
bool isOk;
|
bool isOk;
|
||||||
@ -241,6 +300,9 @@ void PortsWindow::updatePortRates()
|
|||||||
{
|
{
|
||||||
QModelIndex current = tvPortList->currentIndex();
|
QModelIndex current = tvPortList->currentIndex();
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
if (!current.isValid())
|
if (!current.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -255,6 +317,11 @@ void PortsWindow::updatePortRates()
|
|||||||
|
|
||||||
void PortsWindow::updateStreamViewActions()
|
void PortsWindow::updateStreamViewActions()
|
||||||
{
|
{
|
||||||
|
QModelIndex current = tvPortList->currentIndex();
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
// For some reason hasSelection() returns true even if selection size is 0
|
// For some reason hasSelection() returns true even if selection size is 0
|
||||||
// so additional check for size introduced
|
// so additional check for size introduced
|
||||||
if (tvStreamList->selectionModel()->hasSelection() &&
|
if (tvStreamList->selectionModel()->hasSelection() &&
|
||||||
@ -288,7 +355,7 @@ void PortsWindow::updateStreamViewActions()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug("No selection");
|
qDebug("No selection");
|
||||||
if (plm->isPort(tvPortList->currentIndex()))
|
if (plm->isPort(current))
|
||||||
actionNew_Stream->setEnabled(true);
|
actionNew_Stream->setEnabled(true);
|
||||||
else
|
else
|
||||||
actionNew_Stream->setDisabled(true);
|
actionNew_Stream->setDisabled(true);
|
||||||
@ -296,13 +363,17 @@ void PortsWindow::updateStreamViewActions()
|
|||||||
actionDuplicate_Stream->setDisabled(true);
|
actionDuplicate_Stream->setDisabled(true);
|
||||||
actionDelete_Stream->setDisabled(true);
|
actionDelete_Stream->setDisabled(true);
|
||||||
}
|
}
|
||||||
actionOpen_Streams->setEnabled(plm->isPort(
|
actionOpen_Streams->setEnabled(plm->isPort(current));
|
||||||
tvPortList->selectionModel()->currentIndex()));
|
|
||||||
actionSave_Streams->setEnabled(tvStreamList->model()->rowCount() > 0);
|
actionSave_Streams->setEnabled(tvStreamList->model()->rowCount() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortsWindow::updatePortViewActions(const QModelIndex& current)
|
void PortsWindow::updatePortViewActions(const QModelIndex& currentIndex)
|
||||||
{
|
{
|
||||||
|
QModelIndex current = currentIndex;
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
if (!current.isValid())
|
if (!current.isValid())
|
||||||
{
|
{
|
||||||
qDebug("current is now invalid");
|
qDebug("current is now invalid");
|
||||||
@ -375,6 +446,8 @@ void PortsWindow::on_pbApply_clicked()
|
|||||||
QModelIndex curPortGroup;
|
QModelIndex curPortGroup;
|
||||||
|
|
||||||
curPort = tvPortList->selectionModel()->currentIndex();
|
curPort = tvPortList->selectionModel()->currentIndex();
|
||||||
|
if (proxyPortModel)
|
||||||
|
curPort = proxyPortModel->mapToSource(curPort);
|
||||||
if (!curPort.isValid())
|
if (!curPort.isValid())
|
||||||
{
|
{
|
||||||
qDebug("%s: curPort is invalid", __FUNCTION__);
|
qDebug("%s: curPort is invalid", __FUNCTION__);
|
||||||
@ -395,6 +468,8 @@ void PortsWindow::on_pbApply_clicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
curPortGroup = plm->getPortModel()->parent(curPort);
|
curPortGroup = plm->getPortModel()->parent(curPort);
|
||||||
|
if (proxyPortModel)
|
||||||
|
curPortGroup = proxyPortModel->mapToSource(curPortGroup);
|
||||||
if (!curPortGroup.isValid())
|
if (!curPortGroup.isValid())
|
||||||
{
|
{
|
||||||
qDebug("%s: curPortGroup is invalid", __FUNCTION__);
|
qDebug("%s: curPortGroup is invalid", __FUNCTION__);
|
||||||
@ -447,6 +522,9 @@ void PortsWindow::on_actionDelete_Port_Group_triggered()
|
|||||||
{
|
{
|
||||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
if (current.isValid())
|
if (current.isValid())
|
||||||
plm->removePortGroup(plm->portGroup(current));
|
plm->removePortGroup(plm->portGroup(current));
|
||||||
}
|
}
|
||||||
@ -455,6 +533,9 @@ void PortsWindow::on_actionConnect_Port_Group_triggered()
|
|||||||
{
|
{
|
||||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
if (current.isValid())
|
if (current.isValid())
|
||||||
plm->portGroup(current).connectToHost();
|
plm->portGroup(current).connectToHost();
|
||||||
}
|
}
|
||||||
@ -463,6 +544,9 @@ void PortsWindow::on_actionDisconnect_Port_Group_triggered()
|
|||||||
{
|
{
|
||||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
if (current.isValid())
|
if (current.isValid())
|
||||||
plm->portGroup(current).disconnectFromHost();
|
plm->portGroup(current).disconnectFromHost();
|
||||||
}
|
}
|
||||||
@ -471,6 +555,9 @@ void PortsWindow::on_actionExclusive_Control_triggered(bool checked)
|
|||||||
{
|
{
|
||||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
if (plm->isPort(current))
|
if (plm->isPort(current))
|
||||||
{
|
{
|
||||||
OstProto::Port config;
|
OstProto::Port config;
|
||||||
@ -484,6 +571,9 @@ void PortsWindow::on_actionPort_Configuration_triggered()
|
|||||||
{
|
{
|
||||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
if (!plm->isPort(current))
|
if (!plm->isPort(current))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -533,8 +623,12 @@ void PortsWindow::on_actionDuplicate_Stream_triggered()
|
|||||||
{
|
{
|
||||||
QItemSelectionModel* model = tvStreamList->selectionModel();
|
QItemSelectionModel* model = tvStreamList->selectionModel();
|
||||||
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
||||||
|
|
||||||
qDebug("Duplicate Stream Action");
|
qDebug("Duplicate Stream Action");
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
if (model->hasSelection())
|
if (model->hasSelection())
|
||||||
{
|
{
|
||||||
bool isOk;
|
bool isOk;
|
||||||
@ -584,6 +678,9 @@ void PortsWindow::on_actionOpen_Streams_triggered()
|
|||||||
bool append = true;
|
bool append = true;
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
Q_ASSERT(plm->isPort(current));
|
Q_ASSERT(plm->isPort(current));
|
||||||
|
|
||||||
fileName = QFileDialog::getOpenFileName(this, tr("Open Streams"), dirName);
|
fileName = QFileDialog::getOpenFileName(this, tr("Open Streams"), dirName);
|
||||||
@ -645,6 +742,9 @@ void PortsWindow::on_actionSave_Streams_triggered()
|
|||||||
QString errorStr;
|
QString errorStr;
|
||||||
QFileDialog::Options options;
|
QFileDialog::Options options;
|
||||||
|
|
||||||
|
if (proxyPortModel)
|
||||||
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
// On Mac OS with Native Dialog, getSaveFileName() ignores fileType
|
// On Mac OS with Native Dialog, getSaveFileName() ignores fileType
|
||||||
// which we need.On some Linux distros the native dialog can't
|
// which we need.On some Linux distros the native dialog can't
|
||||||
// distinguish between Ostinato(*) and PCAP(*)
|
// distinguish between Ostinato(*) and PCAP(*)
|
||||||
|
@ -32,6 +32,7 @@ LOW
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class QAbstractItemDelegate;
|
class QAbstractItemDelegate;
|
||||||
|
class QSortFilterProxyModel;
|
||||||
|
|
||||||
class PortsWindow : public QWidget, private Ui::PortsWindow
|
class PortsWindow : public QWidget, private Ui::PortsWindow
|
||||||
{
|
{
|
||||||
@ -47,17 +48,21 @@ public:
|
|||||||
private:
|
private:
|
||||||
QString lastNewPortGroup;
|
QString lastNewPortGroup;
|
||||||
QAbstractItemDelegate *delegate;
|
QAbstractItemDelegate *delegate;
|
||||||
|
QSortFilterProxyModel *proxyPortModel;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void showMyReservedPortsOnly(bool enabled);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updatePortViewActions(const QModelIndex& current);
|
void updatePortViewActions(const QModelIndex& currentIndex);
|
||||||
void updateStreamViewActions();
|
void updateStreamViewActions();
|
||||||
|
|
||||||
void on_averagePacketsPerSec_editingFinished();
|
void on_averagePacketsPerSec_editingFinished();
|
||||||
void on_averageBitsPerSec_editingFinished();
|
void on_averageBitsPerSec_editingFinished();
|
||||||
void updatePortRates();
|
void updatePortRates();
|
||||||
void on_tvStreamList_activated(const QModelIndex & index);
|
void on_tvStreamList_activated(const QModelIndex & index);
|
||||||
void when_portView_currentChanged(const QModelIndex& current,
|
void when_portView_currentChanged(const QModelIndex& currentIndex,
|
||||||
const QModelIndex& previous);
|
const QModelIndex& previousIndex);
|
||||||
void when_portModel_dataChanged(const QModelIndex& topLeft,
|
void when_portModel_dataChanged(const QModelIndex& topLeft,
|
||||||
const QModelIndex& bottomRight);
|
const QModelIndex& bottomRight);
|
||||||
void when_portModel_reset();
|
void when_portModel_reset();
|
||||||
|
Loading…
Reference in New Issue
Block a user