example for interacting with widgets
This commit is contained in:
parent
5d7f169692
commit
7fa3bde8b3
|
@ -1 +1,3 @@
|
||||||
add_subdirectory("sACN Explorer")
|
add_subdirectory("sACN Explorer")
|
||||||
|
|
||||||
|
add_subdirectory("widgetExplorer")
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
project(widgetExplorer VERSION ${PROJECT_VERSION})
|
||||||
|
|
||||||
|
find_package(Qt6 COMPONENTS Gui Network SerialPort Widgets REQUIRED)
|
||||||
|
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME})
|
||||||
|
|
||||||
|
target_sources(${PROJECT_NAME}
|
||||||
|
PRIVATE
|
||||||
|
devicewindow.cpp
|
||||||
|
devicewindow.h
|
||||||
|
devicewindow.ui
|
||||||
|
main.cpp
|
||||||
|
widgetexplorer.cpp
|
||||||
|
widgetexplorer.h
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
PRIVATE
|
||||||
|
LCP::Qt::sACN
|
||||||
|
LCP::Qt::DmxWidget
|
||||||
|
Qt::Gui
|
||||||
|
Qt::Network
|
||||||
|
Qt::SerialPort
|
||||||
|
Qt::Widgets
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
|
MACOSX_BUNDLE_GUI_IDENTIFIER ${PROJECT_NAME}.company235.com
|
||||||
|
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||||
|
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||||
|
)
|
|
@ -0,0 +1,56 @@
|
||||||
|
#include "devicewindow.h"
|
||||||
|
#include "ui_devicewindow.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QStringBuilder>
|
||||||
|
|
||||||
|
DeviceWindow::DeviceWindow(QWidget *parent)
|
||||||
|
: QMainWindow(parent)
|
||||||
|
, ui(new Ui::DeviceWindow)
|
||||||
|
, model(new WidgetModel(this))
|
||||||
|
, sortProxy(new QSortFilterProxyModel(this))
|
||||||
|
{
|
||||||
|
// build the UI
|
||||||
|
ui->setupUi(this);
|
||||||
|
ui->menubar->setNativeMenuBar(false); // workaround for poor Qt6 support in KDE 5
|
||||||
|
|
||||||
|
// setup the model
|
||||||
|
sortProxy->setSourceModel(model);
|
||||||
|
ui->widgetView->setModel(sortProxy);
|
||||||
|
ui->widgetView->setSortingEnabled(true);
|
||||||
|
ui->widgetView->sortByColumn(WidgetModel::Column::PortName, Qt::SortOrder::AscendingOrder);
|
||||||
|
|
||||||
|
// action connections
|
||||||
|
connect(ui->actionAbout, &QAction::triggered,
|
||||||
|
this, [this](){
|
||||||
|
QString title = tr("About") % " " % qAppName();
|
||||||
|
QString text = QApplication::organizationName() % "\n"
|
||||||
|
% "https://" % QApplication::organizationDomain() % "\n\n"
|
||||||
|
% QApplication::applicationName() % " is a demonstration of the capabilities "
|
||||||
|
% "of the DMX-USB-Pro driver implimentation in the OpenLCP protocol library."
|
||||||
|
% "\n\n" % "© 2023 Kevin Matz" % "\n\n"
|
||||||
|
% "Permission is hereby granted, free of charge, to any person obtaining a copy"
|
||||||
|
% "of this software and associated documentation files (the \"Software\"), "
|
||||||
|
% "to deal in the Software without restriction, including without limitation "
|
||||||
|
% "the rights to use, copy, modify, merge, publish, distribute, sublicense, "
|
||||||
|
% "and/or sell copies of the Software, and to permit persons to whom the "
|
||||||
|
% "Software is furnished to do so, subject to the following conditions:" % "\n\n"
|
||||||
|
% "The above copyright notice and this permission notice shall be included in "
|
||||||
|
% "all copies or substantial portions of the Software." % "\n\n"
|
||||||
|
% "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR "
|
||||||
|
% "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
|
||||||
|
% "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
|
||||||
|
% "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
|
||||||
|
% "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING "
|
||||||
|
% "FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER "
|
||||||
|
% "DEALINGS IN THE SOFTWARE.";
|
||||||
|
QMessageBox::about(this, title, text);
|
||||||
|
});
|
||||||
|
connect(ui->actionAbout_Qt, &QAction::triggered,
|
||||||
|
this, [this](){QMessageBox::aboutQt(this);});
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceWindow::~DeviceWindow()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <widgetmodel.h>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class DeviceWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
class DeviceWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DeviceWindow(QWidget *parent = nullptr);
|
||||||
|
~DeviceWindow();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::DeviceWindow *ui;
|
||||||
|
WidgetModel *model;
|
||||||
|
QSortFilterProxyModel *sortProxy;
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,292 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>DeviceWindow</class>
|
||||||
|
<widget class="QMainWindow" name="DeviceWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>600</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTableView" name="widgetView"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuHelp">
|
||||||
|
<property name="title">
|
||||||
|
<string>Help</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionAbout"/>
|
||||||
|
<addaction name="actionAbout_Qt"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuPort">
|
||||||
|
<property name="title">
|
||||||
|
<string>Port</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionOpen"/>
|
||||||
|
<addaction name="actionClose"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionRefresh_List"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuWidget">
|
||||||
|
<property name="title">
|
||||||
|
<string>Widget</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionDMX"/>
|
||||||
|
<addaction name="actionRDM"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionParameter"/>
|
||||||
|
<addaction name="actionUserData"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionFirmware"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuView">
|
||||||
|
<property name="title">
|
||||||
|
<string>View</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuToolbars">
|
||||||
|
<property name="title">
|
||||||
|
<string>Toolbars</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionPortToolbar"/>
|
||||||
|
<addaction name="actionWidgetToolbar"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuToolbars"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuPort"/>
|
||||||
|
<addaction name="menuWidget"/>
|
||||||
|
<addaction name="menuView"/>
|
||||||
|
<addaction name="menuHelp"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<widget class="QToolBar" name="toolBarPort">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>toolBar</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<addaction name="actionRefresh_List"/>
|
||||||
|
<addaction name="actionOpen"/>
|
||||||
|
<addaction name="actionClose"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QToolBar" name="toolBarWidget">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>toolBar_2</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<addaction name="actionDMX"/>
|
||||||
|
<addaction name="actionRDM"/>
|
||||||
|
<addaction name="actionParameter"/>
|
||||||
|
</widget>
|
||||||
|
<action name="actionAbout">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="help-about">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>About</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionAbout_Qt">
|
||||||
|
<property name="text">
|
||||||
|
<string>About Qt</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRefresh_List">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="view-refresh">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Refresh List</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionOpen">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="call-start">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Open</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionClose">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="call-stop">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Close</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionParameter">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="preferences-other">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Parameters</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Tx Parameters</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionUserData">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="document-properties">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>User Data</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFirmware">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="system-run">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Upload Firmware</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionDMX">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="edit-find">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>DMX Universe</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRDM">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="computer">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>RDM Devices</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionPortToolbar">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="drive-removable-media">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Port</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Show Port Toolbar</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionWidgetToolbar">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="media-flash">
|
||||||
|
<normaloff>.</normaloff>.</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Widget</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Show Widget Toolbar</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>actionWidgetToolbar</sender>
|
||||||
|
<signal>triggered(bool)</signal>
|
||||||
|
<receiver>toolBarWidget</receiver>
|
||||||
|
<slot>setVisible(bool)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>-1</x>
|
||||||
|
<y>-1</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>498</x>
|
||||||
|
<y>53</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>actionPortToolbar</sender>
|
||||||
|
<signal>triggered(bool)</signal>
|
||||||
|
<receiver>toolBarPort</receiver>
|
||||||
|
<slot>setVisible(bool)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>-1</x>
|
||||||
|
<y>-1</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>98</x>
|
||||||
|
<y>53</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "widgetexplorer.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
WidgetExplorer a(argc, argv);
|
||||||
|
return a.exec();
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
#include <QDebug>
|
||||||
|
#include "widgetexplorer.h"
|
||||||
|
|
||||||
|
|
||||||
|
WidgetExplorer::WidgetExplorer(int argc, char *argv[])
|
||||||
|
: QApplication(argc, argv)
|
||||||
|
, window_(nullptr)
|
||||||
|
{
|
||||||
|
setOrganizationName("Company235");
|
||||||
|
setOrganizationDomain("company235.com");
|
||||||
|
setApplicationName(tr("widgetExplorer"));
|
||||||
|
settings_ = new QSettings(this);
|
||||||
|
|
||||||
|
// Persistant configuration
|
||||||
|
qDebug() << "Loaded application settings from" << settings_->fileName();
|
||||||
|
|
||||||
|
// Device list
|
||||||
|
window_ = new DeviceWindow();
|
||||||
|
window_->setWindowTitle(QApplication::applicationName());
|
||||||
|
window_->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WidgetExplorer::~WidgetExplorer()
|
||||||
|
{
|
||||||
|
saveSettings();
|
||||||
|
delete window_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SacnExplorer::saveSettings
|
||||||
|
*/
|
||||||
|
void WidgetExplorer::saveSettings()
|
||||||
|
{
|
||||||
|
qDebug() << "Saving application settings to" << settings_->fileName();
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "devicewindow.h"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
class WidgetExplorer
|
||||||
|
: public QApplication
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit WidgetExplorer(int argc, char *argv[]);
|
||||||
|
virtual ~WidgetExplorer();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void saveSettings();
|
||||||
|
|
||||||
|
QSettings *settings_;
|
||||||
|
DeviceWindow *window_;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue