Browse Source

Workspace GUI: Add ability to start all features and all devices & features in all workspaces

chirpmodem-v8.1.0
Jon Beniston 3 months ago
parent
commit
2b9cda833a
  1. 28
      sdrbase/feature/featurewebapiutils.cpp
  2. 1
      sdrbase/feature/featurewebapiutils.h
  3. 120
      sdrgui/gui/workspace.cpp
  4. 17
      sdrgui/gui/workspace.h
  5. 50
      sdrgui/mainwindow.cpp
  6. 1
      sdrgui/mainwindow.h

28
sdrbase/feature/featurewebapiutils.cpp

@ -56,6 +56,34 @@ bool FeatureWebAPIUtils::run(int featureSetIndex, int featureIndex) @@ -56,6 +56,34 @@ bool FeatureWebAPIUtils::run(int featureSetIndex, int featureIndex)
}
}
// Stop feature
bool FeatureWebAPIUtils::stop(int featureSetIndex, int featureIndex)
{
Feature *feature = FeatureWebAPIUtils::getFeature(featureSetIndex, featureIndex, "");
if (feature != nullptr)
{
SWGSDRangel::SWGDeviceState runResponse;
QString errorResponse;
runResponse.setState(new QString());
const int httpRC = feature->webapiRun(false, runResponse, errorResponse);
if (httpRC/100 != 2)
{
qWarning("FeatureWebAPIUtils::stop: stop error %d: %s",
httpRC, qPrintable(errorResponse));
return false;
}
return true;
}
else
{
qWarning("FeatureWebAPIUtils::stop: no feature F%d:%d", featureSetIndex, featureIndex);
return false;
}
}
// Find the specified target on the map
bool FeatureWebAPIUtils::mapFind(const QString& target, int featureSetIndex, int featureIndex)
{

1
sdrbase/feature/featurewebapiutils.h

@ -48,6 +48,7 @@ class SDRBASE_API FeatureWebAPIUtils @@ -48,6 +48,7 @@ class SDRBASE_API FeatureWebAPIUtils
{
public:
static bool run(int featureSetIndex, int featureIndex);
static bool stop(int featureSetIndex, int featureIndex);
static bool mapFind(const QString& target, int featureSetIndex=-1, int featureIndex=-1);
static bool mapSetDateTime(const QDateTime& dateTime, int featureSetIndex=-1, int featureIndex=-1);
static bool skyMapFind(const QString& target, int featureSetIndex=-1, int featureIndex=-1);

120
sdrgui/gui/workspace.cpp

@ -30,12 +30,15 @@ @@ -30,12 +30,15 @@
#include <QApplication>
#include <QMenu>
#include <QAction>
#include <QActionGroup>
#include "gui/samplingdevicedialog.h"
#include "gui/rollupcontents.h"
#include "gui/buttonswitch.h"
#include "gui/crightclickenabler.h"
#include "channel/channelgui.h"
#include "feature/feature.h"
#include "feature/featureset.h"
#include "feature/featuregui.h"
#include "device/devicegui.h"
#include "device/deviceset.h"
@ -47,6 +50,8 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) : @@ -47,6 +50,8 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) :
QDockWidget(parent, flags),
m_index(index),
m_menuButton(nullptr),
m_startStopMenu(nullptr),
m_startStopMode(StartStopCurrentWorkspaceDevices),
m_featureAddDialog(this),
m_stacking(false),
m_autoStack(false),
@ -88,8 +93,28 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) : @@ -88,8 +93,28 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) :
m_startStopButton = new ButtonSwitch();
m_startStopButton->setCheckable(true);
m_startStopMenu = new QMenu(m_startStopButton);
QActionGroup *startStopActionGroup = new QActionGroup(m_startStopMenu);
startStopActionGroup->setExclusive(true);
const QStringList startStopModes {
tr("Start/stop devices in current workspace"),
tr("Start/stop devices and features in current workspace"),
tr("Start/stop devices in all workspaces"),
tr("Start/stop devices and features in all workspaces")
};
for (int i = 0; i < startStopModes.size(); i++)
{
QAction *action = m_startStopMenu->addAction(startStopModes[i]);
action->setCheckable(true);
action->setData(i);
action->setActionGroup(startStopActionGroup);
action->setChecked(i == static_cast<int>(m_startStopMode));
}
connect(startStopActionGroup, &QActionGroup::triggered, this, &Workspace::startStopModeChanged);
m_startStopButton->setMenu(m_startStopMenu);
m_startStopButton->setPopupMode(QToolButton::MenuButtonPopup);
updateStartStopButton(false);
m_startStopButton->setFixedSize(20, 20);
m_startStopButton->setFixedSize(34, 20);
m_startStopButton->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
m_vline1 = new QFrame();
@ -921,59 +946,99 @@ void Workspace::layoutSubWindows() @@ -921,59 +946,99 @@ void Workspace::layoutSubWindows()
}
}
// Start/stop all devices in workspace
// Start/stop the devices and features selected in the button menu
void Workspace::startStopClicked(bool checked)
{
if (!checked) {
emit stopAllDevices(this);
} else {
emit startAllDevices(this);
}
const bool includeFeatures = (m_startStopMode == StartStopCurrentWorkspaceDevicesAndFeatures)
|| (m_startStopMode == StartStopAllWorkspacesDevicesAndFeatures);
const bool allWorkspaces = (m_startStopMode == StartStopAllWorkspacesDevices)
|| (m_startStopMode == StartStopAllWorkspacesDevicesAndFeatures);
emit startStopRequested(this, checked, includeFeatures, allWorkspaces);
updateStartStopButton(checked);
}
void Workspace::startStopModeChanged(QAction *action)
{
m_startStopMode = static_cast<StartStopMode>(action->data().toInt());
updateStartStopButtonState();
}
void Workspace::updateStartStopButton(bool checked)
{
const bool includeFeatures = (m_startStopMode == StartStopCurrentWorkspaceDevicesAndFeatures)
|| (m_startStopMode == StartStopAllWorkspacesDevicesAndFeatures);
const bool allWorkspaces = (m_startStopMode == StartStopAllWorkspacesDevices)
|| (m_startStopMode == StartStopAllWorkspacesDevicesAndFeatures);
const QString targets = includeFeatures ? tr("devices and features") : tr("devices");
const QString scope = allWorkspaces ? tr("all workspaces") : tr("current workspace");
if (!checked)
{
QIcon startIcon(":/play.png");
m_startStopButton->setIcon(startIcon);
m_startStopButton->setStyleSheet("QToolButton { background-color : blue; }");
m_startStopButton->setToolTip("Start all devices in workspace");
m_startStopButton->setToolTip(tr("Start %1 in %2").arg(targets, scope));
}
else
{
QIcon stopIcon(":/stop.png");
m_startStopButton->setIcon(stopIcon);
m_startStopButton->setStyleSheet("QToolButton { background-color : green; }");
m_startStopButton->setToolTip("Stop all devices in workspace");
m_startStopButton->setToolTip(tr("Stop %1 in %2").arg(targets, scope));
}
}
void Workspace::deviceStateChanged(int, DeviceAPI *deviceAPI)
void Workspace::updateStartStopButtonState()
{
if (deviceAPI->getWorkspaceIndex() == m_index)
const bool includeFeatures = (m_startStopMode == StartStopCurrentWorkspaceDevicesAndFeatures)
|| (m_startStopMode == StartStopAllWorkspacesDevicesAndFeatures);
const bool allWorkspaces = (m_startStopMode == StartStopAllWorkspacesDevices)
|| (m_startStopMode == StartStopAllWorkspacesDevicesAndFeatures);
bool running = false;
bool error = false;
const std::vector<DeviceSet*>& deviceSets = MainCore::instance()->getDeviceSets();
for (const auto *deviceSet : deviceSets)
{
// Check state of all devices in workspace, to see if any are running or have errors
bool running = false;
bool error = false;
std::vector<DeviceSet*> deviceSets = MainCore::instance()->getDeviceSets();
for (auto deviceSet : deviceSets)
if (allWorkspaces || (deviceSet->m_deviceAPI->getWorkspaceIndex() == m_index))
{
DeviceAPI::EngineState state = deviceSet->m_deviceAPI->state();
if (state == DeviceAPI::StRunning) {
running = true;
} else if (state == DeviceAPI::StError) {
error = true;
}
const DeviceAPI::EngineState state = deviceSet->m_deviceAPI->state();
running |= state == DeviceAPI::StRunning;
error |= state == DeviceAPI::StError;
}
// Update start/stop button to reflect current state of devices
updateStartStopButton(running);
m_startStopButton->setChecked(running);
if (error) {
m_startStopButton->setStyleSheet("QToolButton { background-color : red; }");
}
if (includeFeatures)
{
const std::vector<FeatureSet*>& featureSets = MainCore::instance()->getFeatureeSets();
for (const auto *featureSet : featureSets)
{
for (int i = 0; i < featureSet->getNumberOfFeatures(); i++)
{
const Feature *feature = featureSet->getFeatureAt(i);
if (allWorkspaces || (feature->getWorkspaceIndex() == m_index))
{
running |= feature->getState() == Feature::StRunning;
error |= feature->getState() == Feature::StError;
}
}
}
}
updateStartStopButton(running);
m_startStopButton->setChecked(running);
if (error) {
m_startStopButton->setStyleSheet("QToolButton { background-color : red; }");
}
}
void Workspace::deviceStateChanged(int, DeviceAPI *deviceAPI)
{
const bool allWorkspaces = (m_startStopMode == StartStopAllWorkspacesDevices)
|| (m_startStopMode == StartStopAllWorkspacesDevicesAndFeatures);
if (allWorkspaces || (deviceAPI->getWorkspaceIndex() == m_index)) {
updateStartStopButtonState();
}
}
void Workspace::resizeEvent(QResizeEvent *event)
@ -1138,4 +1203,3 @@ void Workspace::adjustSubWindowsAfterRestore() @@ -1138,4 +1203,3 @@ void Workspace::adjustSubWindowsAfterRestore()
}
}
}

17
sdrgui/gui/workspace.h

@ -33,6 +33,8 @@ class QHBoxLayout; @@ -33,6 +33,8 @@ class QHBoxLayout;
class QLabel;
class QToolButton;
class QPushButton;
class QMenu;
class QAction;
class QMdiArea;
class QMdiSubWindow;
class QFrame;
@ -71,10 +73,20 @@ public: @@ -71,10 +73,20 @@ public:
QToolButton *getMenuButton() const { return m_menuButton; }
private:
enum StartStopMode
{
StartStopCurrentWorkspaceDevices,
StartStopCurrentWorkspaceDevicesAndFeatures,
StartStopAllWorkspacesDevices,
StartStopAllWorkspacesDevicesAndFeatures
};
int m_index;
QToolButton *m_menuButton;
QPushButton *m_configurationPresetsButton;
QMenu *m_startStopMenu;
ButtonSwitch *m_startStopButton;
StartStopMode m_startStopMode;
QFrame *m_vline1;
QPushButton *m_addRxDeviceButton;
QPushButton *m_addTxDeviceButton;
@ -101,6 +113,7 @@ private: @@ -101,6 +113,7 @@ private:
int m_autoStackChannelMinWidth; // Width of channel requested by stackSubWindows()
void unmaximizeSubWindows();
void updateStartStopButtonState();
protected:
void resizeEvent(QResizeEvent *event) override;
@ -120,6 +133,7 @@ private slots: @@ -120,6 +133,7 @@ private slots:
void autoStackSubWindows(const QPoint&);
void tabSubWindows();
void startStopClicked(bool checked = false);
void startStopModeChanged(QAction *action);
void addFeatureEmitted(int featureIndex);
void toggleFloating();
void deviceStateChanged(int, DeviceAPI *deviceAPI);
@ -134,8 +148,7 @@ signals: @@ -134,8 +148,7 @@ signals:
void addFeature(Workspace*, int);
void featurePresetsDialogRequested(QPoint, Workspace*);
void configurationPresetsDialogRequested();
void startAllDevices(Workspace *inWorkspace);
void stopAllDevices(Workspace *inWorkspace);
void startStopRequested(Workspace *inWorkspace, bool start, bool includeFeatures, bool allWorkspaces);
};

50
sdrgui/mainwindow.cpp

@ -2519,16 +2519,9 @@ void MainWindow::addWorkspace() @@ -2519,16 +2519,9 @@ void MainWindow::addWorkspace()
QObject::connect(
m_workspaces.back(),
&Workspace::startAllDevices,
&Workspace::startStopRequested,
this,
&MainWindow::startAllDevices
);
QObject::connect(
m_workspaces.back(),
&Workspace::stopAllDevices,
this,
&MainWindow::stopAllDevices
&MainWindow::startStop
);
if (m_workspaces.size() > 1)
@ -3461,6 +3454,45 @@ void MainWindow::stopAllDevices(const Workspace *workspace) const @@ -3461,6 +3454,45 @@ void MainWindow::stopAllDevices(const Workspace *workspace) const
}
}
void MainWindow::startStop(const Workspace *workspace, bool start, bool includeFeatures, bool allWorkspaces) const
{
const int workspaceIndex = workspace->getIndex();
for (const auto *deviceUI : m_deviceUIs)
{
DeviceAPI *deviceAPI = deviceUI->m_deviceAPI;
if (allWorkspaces || (deviceAPI->getWorkspaceIndex() == workspaceIndex))
{
const int deviceIndex = deviceAPI->getDeviceSetIndex();
if (start) {
ChannelWebAPIUtils::run(deviceIndex);
} else {
ChannelWebAPIUtils::stop(deviceIndex);
}
}
}
if (includeFeatures)
{
for (std::size_t featureSetIndex = 0; featureSetIndex < m_featureUIs.size(); featureSetIndex++)
{
FeatureUISet *featureUISet = m_featureUIs[featureSetIndex];
for (int featureIndex = 0; featureIndex < featureUISet->getNumberOfFeatures(); featureIndex++)
{
Feature *feature = featureUISet->getFeatureAt(featureIndex);
if (allWorkspaces || (feature->getWorkspaceIndex() == workspaceIndex))
{
if (start) {
FeatureWebAPIUtils::run(featureSetIndex, featureIndex);
} else {
FeatureWebAPIUtils::stop(featureSetIndex, featureIndex);
}
}
}
}
}
}
void MainWindow::deviceStateChanged(DeviceAPI *deviceAPI)
{
emit m_mainCore->deviceStateChanged(deviceAPI->getDeviceSetIndex(), deviceAPI);

1
sdrgui/mainwindow.h

@ -465,6 +465,7 @@ private slots: @@ -465,6 +465,7 @@ private slots:
void startAll();
void startAllDevices(const Workspace *workspace) const;
void stopAllDevices(const Workspace *workspace) const;
void startStop(const Workspace *workspace, bool start, bool includeFeatures, bool allWorkspaces) const;
void deviceMove(DeviceGUI *gui, int wsIndexDestnation);
void mainSpectrumMove(MainSpectrumGUI *gui, int wsIndexDestnation);
void mainSpectrumShow(int deviceSetIndex);

Loading…
Cancel
Save