-
Notifications
You must be signed in to change notification settings - Fork 50
tests: update dss-network-plugin test example #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // SPDX-FileCopyrightText: 2011 - 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #include "dssscreenmanager.h" | ||
|
|
||
| #include "dsstestwidget.h" | ||
| #include "networkmodule.h" | ||
|
|
||
| #include <QGuiApplication> | ||
| #include <QScreen> | ||
|
|
||
| DssScreenManager::DssScreenManager(QObject *parent) | ||
| : QObject(parent) | ||
| , m_netModule(new dde::network::NetworkPlugin(this)) | ||
| { | ||
| m_netModule->init(); | ||
| initConnection(); | ||
| initScreen(); | ||
| } | ||
|
|
||
| DssScreenManager::~DssScreenManager() | ||
| { | ||
| qDeleteAll(m_screenWidget); | ||
| m_screenWidget.clear(); | ||
| } | ||
|
|
||
| void DssScreenManager::showWindow() | ||
| { | ||
| for (auto it = m_screenWidget.constBegin(); it != m_screenWidget.constEnd(); it++) { | ||
| showWindow(it.key(), it.value()); | ||
| } | ||
| } | ||
|
|
||
| void DssScreenManager::initConnection() | ||
| { | ||
| connect(qApp, &QGuiApplication::screenAdded, this, &DssScreenManager::onScreenAdded); | ||
| connect(qApp, &QGuiApplication::screenRemoved, this, &DssScreenManager::onScreenRemoved); | ||
| } | ||
|
|
||
| void DssScreenManager::initScreen() | ||
| { | ||
| QList<QScreen *> screens = QGuiApplication::screens(); | ||
| for (QScreen *screen : screens) { | ||
| DssTestWidget *testWidget = new DssTestWidget(m_netModule); | ||
| m_screenWidget[screen] = testWidget; | ||
| } | ||
| } | ||
|
|
||
| void DssScreenManager::showWindow(QScreen *screen, DssTestWidget *testWidget) | ||
| { | ||
| const QRect screenGeometry = screen->geometry(); | ||
| testWidget->resize(330, 800); | ||
| testWidget->move(screenGeometry.x() + (screenGeometry.width() - testWidget->width()) / 2, (screenGeometry.height() - testWidget->height()) / 2); | ||
| testWidget->show(); | ||
| } | ||
|
|
||
| void DssScreenManager::onScreenAdded(QScreen *screen) | ||
| { | ||
| DssTestWidget *testWidget = new DssTestWidget(m_netModule); | ||
| m_screenWidget[screen] = testWidget; | ||
| showWindow(screen, testWidget); | ||
| } | ||
|
|
||
| void DssScreenManager::onScreenRemoved(QScreen *screen) | ||
| { | ||
| if (m_screenWidget.contains(screen)) { | ||
| DssTestWidget *testWidget = m_screenWidget[screen]; | ||
| m_screenWidget.remove(screen); | ||
| testWidget->deleteLater(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // SPDX-FileCopyrightText: 2011 - 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #ifndef DSSSCREENMANAGER_H | ||
| #define DSSSCREENMANAGER_H | ||
|
|
||
| #include <QMap> | ||
| #include <QObject> | ||
|
|
||
| class DssTestWidget; | ||
| class QScreen; | ||
|
|
||
| namespace dde { | ||
| namespace network { | ||
| class NetworkPlugin; | ||
| } // namespace network | ||
| } // namespace dde | ||
|
|
||
| class DssScreenManager : public QObject | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| explicit DssScreenManager(QObject *parent = nullptr); | ||
| ~DssScreenManager(); | ||
| void showWindow(); | ||
|
|
||
| private: | ||
| void initConnection(); | ||
| void initScreen(); | ||
| void showWindow(QScreen *screen, DssTestWidget *testWidget); | ||
|
|
||
| protected: | ||
| void onScreenAdded(QScreen *screen); | ||
| void onScreenRemoved(QScreen *screen); | ||
|
|
||
| private: | ||
| QMap<QScreen *, DssTestWidget *> m_screenWidget; | ||
| dde::network::NetworkPlugin *m_netModule; | ||
| }; | ||
|
|
||
| #endif // DSSSCREENMANAGER_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,46 @@ | ||
| // SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #ifndef DSSTESTWIDGET_H | ||
| #define DSSTESTWIDGET_H | ||
|
|
||
| #include <DFloatingButton> | ||
|
|
||
| #include <QWidget> | ||
|
|
||
| namespace Dtk { | ||
| namespace Widget { | ||
| class DFloatingButton; | ||
| } | ||
| } | ||
| class PopupWindow; | ||
|
|
||
| namespace dde { | ||
| namespace network { | ||
| class NetworkPlugin; | ||
| } // namespace network | ||
| } // namespace dde | ||
|
|
||
| class QPushButton; | ||
| using namespace Dtk::Widget; | ||
|
|
||
| class DssTestWidget : public QWidget | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| DssTestWidget(QWidget *parent = Q_NULLPTR); | ||
| ~DssTestWidget(); | ||
| explicit DssTestWidget(dde::network::NetworkPlugin *networkPlugin, QWidget *parent = Q_NULLPTR); | ||
| ~DssTestWidget() override; | ||
|
|
||
| private: | ||
| bool eventFilter(QObject *watched, QEvent *event); | ||
| protected: | ||
| bool eventFilter(QObject *watched, QEvent *event) override; | ||
| void resizeEvent(QResizeEvent *event) override; | ||
| void mousePressEvent(QMouseEvent *event) override; | ||
|
|
||
| protected slots: | ||
| void onClickButton(); | ||
|
|
||
| private: | ||
| Dtk::Widget::DFloatingButton *m_button; | ||
| dde::network::NetworkPlugin *m_pModule; | ||
| DFloatingButton *m_iconButton; | ||
| PopupWindow *m_container; | ||
| PopupWindow *m_tipContainer; | ||
| }; | ||
|
|
||
| #endif // DSSTESTWIDGET_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential null dereference when hiding m_tipContainer on Leave event
In the
QEvent::Leavecase you callm_tipContainer->hide()even thoughm_tipContaineris only set up in theEnterpath. IfLeaveoccurs before the popup is constructed, this will dereference a null pointer. Add a null check (e.g.if (m_tipContainer) m_tipContainer->hide();) to avoid a crash.