Skip to content

Commit

Permalink
core: Create device config page.
Browse files Browse the repository at this point in the history
The device configuration page is a tab widget that contains
configuration pages for all its compatible plugins, with each tab
representing a plugin's configuration page. This device configuration
page is added into the ScopyMainWindow tool stack and can be
accessed by clicking the 'Device' button in the tool menu.

Signed-off-by: andreidanila1 <[email protected]>
  • Loading branch information
andreidanila1 committed Nov 28, 2024
1 parent 3177de5 commit e37a2f3
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions core/include/core/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class SCOPY_CORE_EXPORT Device
virtual QPixmap iconPixmap() = 0;

virtual QWidget *page() = 0;
virtual QWidget *configPage() = 0;

virtual QList<ToolMenuEntry *> toolList() = 0;
virtual void init() = 0;
Expand Down
4 changes: 4 additions & 0 deletions core/include/core/deviceimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QCheckBox>
#include <QObject>
#include <QPushButton>
#include <QTabWidget>

namespace scopy {

Expand All @@ -50,6 +51,7 @@ class SCOPY_CORE_EXPORT DeviceImpl : public QObject, public Device
QWidget *icon() override;
QPixmap iconPixmap() override;
QWidget *page() override;
QWidget *configPage() override;
QList<ToolMenuEntry *> toolList() override;
virtual void init() override;
virtual void preload() override;
Expand Down Expand Up @@ -85,6 +87,7 @@ public Q_SLOTS:
void loadName();
void loadIcons();
void loadPages();
void loadConfigPage();
void loadToolList();
void loadBadges();
void setPingPlugin(Plugin *plugin);
Expand All @@ -103,6 +106,7 @@ public Q_SLOTS:
QString m_param;
QWidget *m_icon;
QWidget *m_page;
QTabWidget *m_configPage;
QPushButton *connbtn, *discbtn;
Plugin *m_pingPlugin = nullptr;
};
Expand Down
1 change: 0 additions & 1 deletion core/include/core/scopymainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public Q_SLOTS:
void handleScanner();
void enableScanner();
void deviceAutoconnect();
void showDevicePage(QString id, ToolStack *ts);

protected:
void closeEvent(QCloseEvent *event) override;
Expand Down
1 change: 0 additions & 1 deletion core/include/core/toolmenumanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public Q_SLOTS:

Q_SIGNALS:
void requestToolSelect(QString id);
void requestDevicePage(QString id);
void connState(QString id, bool isConnected);

private Q_SLOTS:
Expand Down
15 changes: 15 additions & 0 deletions core/src/deviceimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void DeviceImpl::loadPlugins()
loadIcons();
loadBadges();
loadPages();
loadConfigPage();
loadToolList();
if(m_plugins.isEmpty()) {
connbtn->hide();
Expand Down Expand Up @@ -215,6 +216,18 @@ void DeviceImpl::loadPages()
}
}

void DeviceImpl::loadConfigPage()
{
m_configPage = new QTabWidget();
m_configPage->setTabPosition(QTabWidget::South);

for(auto &&p : plugins()) {
if(p->loadConfigPage()) {
m_configPage->addTab(p->configPage(), p->name());
}
}
}

void DeviceImpl::loadToolList()
{
for(auto &&p : m_plugins) {
Expand Down Expand Up @@ -449,6 +462,8 @@ QPixmap DeviceImpl::iconPixmap()
return pixmap;
}

QWidget *DeviceImpl::configPage() { return m_configPage; }

QWidget *DeviceImpl::page() { return m_page; }

QList<ToolMenuEntry *> DeviceImpl::toolList()
Expand Down
13 changes: 4 additions & 9 deletions core/src/scopymainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ ScopyMainWindow::ScopyMainWindow(QWidget *parent)
connect(dm, &DeviceManager::requestTool, m_toolMenuManager, &ToolMenuManager::showMenuItem);
connect(m_toolMenuManager, &ToolMenuManager::requestToolSelect, ts, &ToolStack::show);
connect(m_toolMenuManager, &ToolMenuManager::requestToolSelect, dtm, &DetachedToolWindowManager::show);
connect(m_toolMenuManager, &ToolMenuManager::requestDevicePage, this,
[this, ts](QString id) { showDevicePage(id, ts); });
connect(hp, &ScopyHomePage::displayNameChanged, m_toolMenuManager, &ToolMenuManager::onDisplayNameChanged);

connect(hp, &ScopyHomePage::newDeviceAvailable, dm, &DeviceManager::addDevice);
Expand Down Expand Up @@ -255,13 +253,6 @@ void ScopyMainWindow::deviceAutoconnect()
}
}

void ScopyMainWindow::showDevicePage(QString id, ToolStack *ts)
{
QString hpKey = ts->getKey(hp);
ts->show(hpKey);
hp->viewDevice(id);
}

void ScopyMainWindow::save()
{
QString selectedFilter;
Expand Down Expand Up @@ -614,12 +605,16 @@ void ScopyMainWindow::addDeviceToUi(QString id, Device *d)
DeviceInfo dInfo = {id, d->displayName(), d->param(), d->iconPixmap(), d->toolList()};
m_toolMenuManager->addMenuItem(dInfo);
hp->addDevice(id, d);
auto ts = ui->wsToolStack;
ts->add(id, d->configPage());
}

void ScopyMainWindow::removeDeviceFromUi(QString id)
{
m_toolMenuManager->removeMenuItem(id);
hp->removeDevice(id);
auto ts = ui->wsToolStack;
ts->remove(id);
}

void ScopyMainWindow::receiveVersionDocument(QJsonDocument document)
Expand Down
2 changes: 1 addition & 1 deletion core/src/toolmenumanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void ToolMenuManager::initToolMenuHeaderWidget(MenuCollapseHeader *header, const
connect(thw->deviceBtn(), &QPushButton::toggled, this, [=](bool en) {
if(en) {
Style::setStyle(header, style::properties::widget::deviceHeaderWidget, "selected");
Q_EMIT requestDevicePage(dInfo.id);
Q_EMIT requestToolSelect(dInfo.id);
} else {
Style::setStyle(header, style::properties::widget::deviceHeaderWidget, "idle");
}
Expand Down

0 comments on commit e37a2f3

Please sign in to comment.