Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
0d69f523
Commit
0d69f523
authored
Jul 18, 2011
by
LM
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on user-loadable custom widgets
parent
0f28dcbf
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
182 additions
and
71 deletions
+182
-71
MainWindow.cc
src/ui/MainWindow.cc
+31
-2
MainWindow.h
src/ui/MainWindow.h
+3
-0
MainWindow.ui
src/ui/MainWindow.ui
+10
-0
QGCToolWidget.cc
src/ui/designer/QGCToolWidget.cc
+123
-64
QGCToolWidget.h
src/ui/designer/QGCToolWidget.h
+13
-4
LinechartWidget.cc
src/ui/linechart/LinechartWidget.cc
+1
-1
MAV2DIcon.cc
src/ui/map/MAV2DIcon.cc
+1
-0
No files found.
src/ui/MainWindow.cc
View file @
0d69f523
...
...
@@ -938,17 +938,45 @@ void MainWindow::connectCommonWidgets()
void
MainWindow
::
createCustomWidget
()
{
QGCToolWidget
*
tool
=
new
QGCToolWidget
(
"Unnamed Tool"
,
this
);
QDockWidget
*
dock
=
new
QDockWidget
(
"Unnamed Tool"
,
this
);
QGCToolWidget
*
tool
=
new
QGCToolWidget
(
"Unnamed Tool"
,
dock
);
if
(
QGCToolWidget
::
instances
()
->
size
()
<
2
)
{
// This is the first widget
ui
.
menuTools
->
addSeparator
();
}
QDockWidget
*
dock
=
new
QDockWidget
(
"Unnamed Tool"
,
this
);
connect
(
tool
,
SIGNAL
(
destroyed
()),
dock
,
SLOT
(
deleteLater
()));
dock
->
setWidget
(
tool
);
QAction
*
showAction
=
new
QAction
(
tool
->
getTitle
(),
this
);
showAction
->
setCheckable
(
true
);
connect
(
dock
,
SIGNAL
(
visibilityChanged
(
bool
)),
showAction
,
SLOT
(
setChecked
(
bool
)));
connect
(
showAction
,
SIGNAL
(
triggered
(
bool
)),
dock
,
SLOT
(
setVisible
(
bool
)));
tool
->
setMainMenuAction
(
showAction
);
ui
.
menuTools
->
addAction
(
showAction
);
this
->
addDockWidget
(
Qt
::
BottomDockWidgetArea
,
dock
);
dock
->
setVisible
(
true
);
}
void
MainWindow
::
loadCustomWidget
()
{
QString
widgetFileExtension
(
".qgw"
);
QString
fileName
=
QFileDialog
::
getOpenFileName
(
this
,
tr
(
"Specify Widget File Name"
),
QDesktopServices
::
storageLocation
(
QDesktopServices
::
DesktopLocation
),
tr
(
"QGroundControl Widget (*%1);;"
).
arg
(
widgetFileExtension
));
QGCToolWidget
*
tool
=
new
QGCToolWidget
(
""
,
this
);
tool
->
loadSettings
(
fileName
);
if
(
QGCToolWidget
::
instances
()
->
size
()
<
2
)
{
// This is the first widget
ui
.
menuTools
->
addSeparator
();
}
// Add widget to UI
QDockWidget
*
dock
=
new
QDockWidget
(
tool
->
getTitle
(),
this
);
connect
(
tool
,
SIGNAL
(
destroyed
()),
dock
,
SLOT
(
deleteLater
()));
dock
->
setWidget
(
tool
);
tool
->
setParent
(
dock
);
QAction
*
showAction
=
new
QAction
(
"Show Unnamed Tool"
,
this
);
showAction
->
setCheckable
(
true
);
connect
(
dock
,
SIGNAL
(
visibilityChanged
(
bool
)),
showAction
,
SLOT
(
setChecked
(
bool
)));
...
...
@@ -1333,6 +1361,7 @@ void MainWindow::connectCommonActions()
// Custom widget actions
connect
(
ui
.
actionNewCustomWidget
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
createCustomWidget
()));
connect
(
ui
.
actionLoadCustomWidgetFile
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
loadCustomWidget
()));
// Audio output
ui
.
actionMuteAudioOutput
->
setChecked
(
GAudioOutput
::
instance
()
->
isMuted
());
...
...
src/ui/MainWindow.h
View file @
0d69f523
...
...
@@ -181,6 +181,9 @@ public slots:
/** @brief Add a custom tool widget */
void
createCustomWidget
();
/** @brief Load a custom tool widget from a file */
void
loadCustomWidget
();
void
closeEvent
(
QCloseEvent
*
event
);
/** @brief Load data view, allowing to plot flight data */
...
...
src/ui/MainWindow.ui
View file @
0d69f523
...
...
@@ -111,6 +111,7 @@
<string>
Widgets
</string>
</property>
<addaction
name=
"actionNewCustomWidget"
/>
<addaction
name=
"actionLoadCustomWidgetFile"
/>
</widget>
<widget
class=
"QMenu"
name=
"menuHelp"
>
<property
name=
"title"
>
...
...
@@ -456,6 +457,15 @@
<string>
Esc
</string>
</property>
</action>
<action
name=
"actionLoadCustomWidgetFile"
>
<property
name=
"icon"
>
<iconset
resource=
"../../mavground.qrc"
>
<normaloff>
:/images/status/folder-drag-accept.svg
</normaloff>
:/images/status/folder-drag-accept.svg
</iconset>
</property>
<property
name=
"text"
>
<string>
Load Custom Widget File
</string>
</property>
</action>
</widget>
<layoutdefault
spacing=
"6"
margin=
"11"
/>
<resources>
...
...
src/ui/designer/QGCToolWidget.cc
View file @
0d69f523
...
...
@@ -7,6 +7,8 @@
#include <QDockWidget>
#include <QContextMenuEvent>
#include <QSettings>
#include <QFileDialog>
#include <QDesktopServices>
#include "QGCParamSlider.h"
#include "QGCActionButton.h"
...
...
@@ -61,96 +63,144 @@ QGCToolWidget::~QGCToolWidget()
* @param parent Object later holding these widgets, usually the main window
* @return List of all widgets
*/
QList
<
QGCToolWidget
*>
QGCToolWidget
::
createWidgetsFromSettings
(
QWidget
*
parent
)
QList
<
QGCToolWidget
*>
QGCToolWidget
::
createWidgetsFromSettings
(
QWidget
*
parent
,
QString
settingsFile
)
{
// Store list of widgets
QSettings
settings
;
// Load widgets from application settings
QSettings
*
settings
;
// Or load them from a settings file
if
(
!
settingsFile
.
isEmpty
())
{
settings
=
new
QSettings
(
settingsFile
,
QSettings
::
IniFormat
);
qDebug
()
<<
"LOADING SETTINGS FROM"
<<
settingsFile
;
}
else
{
settings
=
new
QSettings
();
}
QList
<
QGCToolWidget
*>
newWidgets
;
int
size
=
settings
.
beginReadArray
(
"QGC_TOOL_WIDGET_NAMES"
);
int
size
=
settings
->
beginReadArray
(
"QGC_TOOL_WIDGET_NAMES"
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
settings
.
setArrayIndex
(
i
);
QString
name
=
settings
.
value
(
"TITLE"
,
tr
(
"UNKNOWN WIDGET %1"
).
arg
(
i
)).
toString
();
settings
->
setArrayIndex
(
i
);
QString
name
=
settings
->
value
(
"TITLE"
,
tr
(
"UNKNOWN WIDGET %1"
).
arg
(
i
)).
toString
();
if
(
!
instances
()
->
contains
(
name
))
{
QGCToolWidget
*
tool
=
new
QGCToolWidget
(
name
,
parent
);
instances
()
->
insert
(
name
,
tool
);
newWidgets
.
append
(
tool
);
}
else
{
qDebug
()
<<
"WIDGET DID ALREADY EXIST, REJECTING"
;
}
}
settings
.
endArray
();
settings
->
endArray
();
qDebug
()
<<
"NEW WIDGETS: "
<<
newWidgets
.
size
();
// Load individual widget items
for
(
int
i
=
0
;
i
<
newWidgets
.
size
();
i
++
)
{
QString
widgetName
=
newWidgets
.
at
(
i
)
->
getTitle
();
qDebug
()
<<
"READING: "
<<
widgetName
;
settings
.
beginGroup
(
widgetName
);
int
size
=
settings
.
beginReadArray
(
"QGC_TOOL_WIDGET_ITEMS"
);
qDebug
()
<<
"CHILDREN SIZE:"
<<
size
;
for
(
int
j
=
0
;
j
<
size
;
j
++
)
{
settings
.
setArrayIndex
(
j
);
QString
type
=
settings
.
value
(
"TYPE"
,
"UNKNOWN"
).
toString
();
if
(
type
!=
"UNKNOWN"
)
{
QGCToolWidgetItem
*
item
=
NULL
;
if
(
type
==
"BUTTON"
)
{
item
=
new
QGCActionButton
(
newWidgets
.
at
(
i
));
qDebug
()
<<
"CREATED BUTTON"
;
}
else
if
(
type
==
"COMMANDBUTTON"
)
{
item
=
new
QGCCommandButton
(
newWidgets
.
at
(
i
));
qDebug
()
<<
"CREATED COMMANDBUTTON"
;
}
else
if
(
type
==
"SLIDER"
)
{
item
=
new
QGCParamSlider
(
newWidgets
.
at
(
i
));
qDebug
()
<<
"CREATED PARAM SLIDER"
;
}
if
(
item
)
{
// Configure and add to layout
newWidgets
.
at
(
i
)
->
addToolWidget
(
item
);
item
->
readSettings
(
settings
);
qDebug
()
<<
"Created tool widget"
;
}
}
else
{
qDebug
()
<<
"UNKNOWN TOOL WIDGET TYPE"
;
}
}
settings
.
endArray
();
settings
.
endGroup
();
newWidgets
.
at
(
i
)
->
loadSettings
(
*
settings
);
}
delete
settings
;
return
instances
()
->
values
();
}
void
QGCToolWidget
::
storeWidgetsToSettings
()
void
QGCToolWidget
::
loadSettings
(
const
QString
&
settings
)
{
QSettings
(
settings
,
QSettings
::
IniFormat
);
loadSettings
(
settings
);
}
void
QGCToolWidget
::
loadSettings
(
QSettings
&
settings
)
{
QString
widgetName
=
getTitle
();
settings
.
beginGroup
(
widgetName
);
int
size
=
settings
.
beginReadArray
(
"QGC_TOOL_WIDGET_ITEMS"
);
qDebug
()
<<
"CHILDREN SIZE:"
<<
size
;
for
(
int
j
=
0
;
j
<
size
;
j
++
)
{
settings
.
setArrayIndex
(
j
);
QString
type
=
settings
.
value
(
"TYPE"
,
"UNKNOWN"
).
toString
();
if
(
type
!=
"UNKNOWN"
)
{
QGCToolWidgetItem
*
item
=
NULL
;
if
(
type
==
"BUTTON"
)
{
item
=
new
QGCActionButton
(
this
);
qDebug
()
<<
"CREATED BUTTON"
;
}
else
if
(
type
==
"COMMANDBUTTON"
)
{
item
=
new
QGCCommandButton
(
this
);
qDebug
()
<<
"CREATED COMMANDBUTTON"
;
}
else
if
(
type
==
"SLIDER"
)
{
item
=
new
QGCParamSlider
(
this
);
qDebug
()
<<
"CREATED PARAM SLIDER"
;
}
if
(
item
)
{
// Configure and add to layout
addToolWidget
(
item
);
item
->
readSettings
(
settings
);
qDebug
()
<<
"Created tool widget"
;
}
}
else
{
qDebug
()
<<
"UNKNOWN TOOL WIDGET TYPE"
;
}
}
settings
.
endArray
();
settings
.
endGroup
();
}
void
QGCToolWidget
::
storeWidgetsToSettings
(
QString
settingsFile
)
{
// Store list of widgets
QSettings
settings
;
settings
.
beginWriteArray
(
"QGC_TOOL_WIDGET_NAMES"
);
QSettings
*
settings
;
if
(
!
settingsFile
.
isEmpty
())
{
settings
=
new
QSettings
(
settingsFile
,
QSettings
::
IniFormat
);
}
else
{
settings
=
new
QSettings
();
}
settings
->
beginWriteArray
(
"QGC_TOOL_WIDGET_NAMES"
);
for
(
int
i
=
0
;
i
<
instances
()
->
size
();
++
i
)
{
settings
.
setArrayIndex
(
i
);
settings
.
setValue
(
"TITLE"
,
instances
()
->
values
().
at
(
i
)
->
getTitle
());
settings
->
setArrayIndex
(
i
);
settings
->
setValue
(
"TITLE"
,
instances
()
->
values
().
at
(
i
)
->
getTitle
());
}
settings
.
endArray
();
settings
->
endArray
();
// Store individual widget items
for
(
int
i
=
0
;
i
<
instances
()
->
size
();
++
i
)
{
QString
widgetName
=
instances
()
->
values
().
at
(
i
)
->
getTitle
();
settings
.
beginGroup
(
widgetName
);
settings
.
beginWriteArray
(
"QGC_TOOL_WIDGET_ITEMS"
);
int
k
=
0
;
// QGCToolItem counter
for
(
int
j
=
0
;
j
<
instances
()
->
values
().
at
(
i
)
->
children
().
size
();
++
j
)
{
// Store only QGCToolWidgetItems
QGCToolWidgetItem
*
item
=
dynamic_cast
<
QGCToolWidgetItem
*>
(
instances
()
->
values
().
at
(
i
)
->
children
().
at
(
j
));
if
(
item
)
{
settings
.
setArrayIndex
(
k
++
);
// Store the ToolWidgetItem
item
->
writeSettings
(
settings
);
}
instances
()
->
values
().
at
(
i
)
->
storeSettings
(
*
settings
);
}
delete
settings
;
}
void
QGCToolWidget
::
storeSettings
(
const
QString
&
settingsFile
)
{
QSettings
settings
(
settingsFile
,
QSettings
::
IniFormat
);
storeSettings
(
settings
);
}
void
QGCToolWidget
::
storeSettings
(
QSettings
&
settings
)
{
QString
widgetName
=
getTitle
();
settings
.
beginGroup
(
widgetName
);
settings
.
beginWriteArray
(
"QGC_TOOL_WIDGET_ITEMS"
);
int
k
=
0
;
// QGCToolItem counter
for
(
int
j
=
0
;
j
<
children
().
size
();
++
j
)
{
// Store only QGCToolWidgetItems
QGCToolWidgetItem
*
item
=
dynamic_cast
<
QGCToolWidgetItem
*>
(
children
().
at
(
j
));
if
(
item
)
{
settings
.
setArrayIndex
(
k
++
);
// Store the ToolWidgetItem
item
->
writeSettings
(
settings
);
}
settings
.
endArray
();
settings
.
endGroup
();
}
settings
.
endArray
();
settings
.
endGroup
();
}
void
QGCToolWidget
::
addUAS
(
UASInterface
*
uas
)
...
...
@@ -168,6 +218,7 @@ void QGCToolWidget::contextMenuEvent (QContextMenuEvent* event)
menu
.
addAction
(
addParamAction
);
menu
.
addAction
(
addCommandAction
);
menu
.
addAction
(
setTitleAction
);
menu
.
addAction
(
exportAction
);
menu
.
addAction
(
deleteAction
);
menu
.
addSeparator
();
menu
.
addAction
(
addButtonAction
);
...
...
@@ -281,12 +332,20 @@ void QGCToolWidget::addToolWidget(QGCToolWidgetItem* widget)
void
QGCToolWidget
::
exportWidget
()
{
const
QString
widgetFileExtension
(
".qgw"
);
QString
fileName
=
QFileDialog
::
getSaveFileName
(
this
,
tr
(
"Specify File Name"
),
QDesktopServices
::
storageLocation
(
QDesktopServices
::
DesktopLocation
),
tr
(
"QGroundControl Widget (*%1);;"
).
arg
(
widgetFileExtension
));
if
(
!
fileName
.
endsWith
(
widgetFileExtension
))
{
fileName
=
fileName
.
append
(
widgetFileExtension
);
}
storeSettings
(
fileName
);
}
void
QGCToolWidget
::
importWidget
(
const
QString
&
fileName
)
void
QGCToolWidget
::
importWidget
()
{
const
QString
widgetFileExtension
(
".qgw"
);
QString
fileName
=
QFileDialog
::
getOpenFileName
(
this
,
tr
(
"Specify File Name"
),
QDesktopServices
::
storageLocation
(
QDesktopServices
::
DesktopLocation
),
tr
(
"QGroundControl Widget (*%1);;"
).
arg
(
widgetFileExtension
));
loadSettings
(
fileName
);
}
const
QString
QGCToolWidget
::
getTitle
()
...
...
src/ui/designer/QGCToolWidget.h
View file @
0d69f523
...
...
@@ -23,11 +23,13 @@ public:
~
QGCToolWidget
();
/** @brief Factory method to instantiate all tool widgets */
static
QList
<
QGCToolWidget
*>
createWidgetsFromSettings
(
QWidget
*
parent
);
static
QList
<
QGCToolWidget
*>
createWidgetsFromSettings
(
QWidget
*
parent
,
QString
settingsFile
=
QString
()
);
/** @Give the tool widget a reference to its action in the main menu */
void
setMainMenuAction
(
QAction
*
action
);
/** @brief All instances of this class */
static
QMap
<
QString
,
QGCToolWidget
*>*
instances
();
/** @brief Get title of widget */
const
QString
getTitle
();
int
isVisible
(
int
view
)
{
return
viewVisible
.
value
(
view
,
false
);
}
Qt
::
DockWidgetArea
getDockWidgetArea
(
int
view
)
{
return
dockWidgetArea
.
value
(
view
,
Qt
::
BottomDockWidgetArea
);
}
...
...
@@ -39,9 +41,17 @@ public slots:
/** @brief Export this widget to a file */
void
exportWidget
();
/** @brief Import settings for this widget from a file */
void
importWidget
(
const
QString
&
fileName
);
void
importWidget
();
/** @brief Store all widgets of this type to QSettings */
static
void
storeWidgetsToSettings
();
static
void
storeWidgetsToSettings
(
QString
settingsFile
=
QString
());
/** @brief Load this widget from a QSettings object */
void
loadSettings
(
QSettings
&
settings
);
/** @brief Load this widget from a settings file */
void
loadSettings
(
const
QString
&
settings
);
/** @brief Store this widget to a QSettings object */
void
storeSettings
(
QSettings
&
settings
);
/** @brief Store this widget to a settings file */
void
storeSettings
(
const
QString
&
settingsFile
);
/** @brief Store the view id and dock widget area */
void
setViewVisibilityAndDockWidgetArea
(
int
view
,
bool
visible
,
Qt
::
DockWidgetArea
area
);
...
...
@@ -65,7 +75,6 @@ protected:
void
contextMenuEvent
(
QContextMenuEvent
*
event
);
void
createActions
();
QList
<
QGCToolWidgetItem
*
>*
itemList
();
const
QString
getTitle
();
/** @brief Add an existing tool widget */
void
addToolWidget
(
QGCToolWidgetItem
*
widget
);
...
...
src/ui/linechart/LinechartWidget.cc
View file @
0d69f523
...
...
@@ -449,7 +449,7 @@ void LinechartWidget::startLogging()
}
// Let user select the log file name
QDate
date
(
QDate
::
currentDate
());
//
QDate date(QDate::currentDate());
// QString("./pixhawk-log-" + date.toString("yyyy-MM-dd") + "-" + QString::number(logindex) + ".log")
QString
fileName
=
QFileDialog
::
getSaveFileName
(
this
,
tr
(
"Specify log file name"
),
QDesktopServices
::
storageLocation
(
QDesktopServices
::
DesktopLocation
),
tr
(
"Logfile (*.csv *.txt);;"
));
...
...
src/ui/map/MAV2DIcon.cc
View file @
0d69f523
...
...
@@ -40,6 +40,7 @@ MAV2DIcon::MAV2DIcon(mapcontrol::MapGraphicItem* map, mapcontrol::OPMapWidget* p
drawIcon
(
pen
);
}
size
=
QSize
(
radius
,
radius
);
SetUAVPos
(
internals
::
PointLatLng
(
lat
,
lon
),
alt
);
}
MAV2DIcon
::~
MAV2DIcon
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment