Skip to content

Commit 37598bd

Browse files
committed
add custom widget for QgsDockWidget
1 parent 8394b57 commit 37598bd

File tree

4 files changed

+156
-1
lines changed

4 files changed

+156
-1
lines changed

src/customwidgets/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ SET (QGIS_CUSTOMWIDGETS_SRCS
2828
qgscolorbuttonv2plugin.cpp
2929
qgsdatetimeeditplugin.cpp
3030
qgsdatadefinedbuttonplugin.cpp
31+
qgsdockwidgetplugin.cpp
3132
qgsdoublespinboxplugin.cpp
3233
qgsexpressionbuilderwidgetplugin.cpp
3334
qgsextentgroupboxplugin.cpp
@@ -52,6 +53,7 @@ SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
5253
qgscolorbuttonv2plugin.h
5354
qgsdatetimeeditplugin.h
5455
qgsdatadefinedbuttonplugin.h
56+
qgsdockwidgetplugin.h
5557
qgsdoublespinboxplugin.h
5658
qgsexpressionbuilderwidgetplugin.h
5759
qgsextentgroupboxplugin.h
@@ -82,6 +84,7 @@ SET(QGIS_CUSTOMWIDGETS_HDRS
8284
qgscolorbuttonv2plugin.h
8385
qgsdatetimeeditplugin.h
8486
qgsdatadefinedbuttonplugin.h
87+
qgsdockwidgetplugin.h
8588
qgsdoublespinboxplugin.h
8689
qgsexpressionbuilderwidgetplugin.h
8790
qgsextentgroupboxplugin.h

src/customwidgets/qgiscustomwidgets.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
#include "qplugin.h"
1717

1818
#include "qgiscustomwidgets.h"
19-
2019
#include "qgscollapsiblegroupboxplugin.h"
2120
#include "qgscolorbuttonplugin.h"
2221
#include "qgscolorbuttonv2plugin.h"
2322
#include "qgsdatadefinedbuttonplugin.h"
2423
#include "qgsdatetimeeditplugin.h"
24+
#include "qgsdockwidgetplugin.h"
2525
#include "qgsdoublespinboxplugin.h"
2626
#include "qgsexpressionbuilderwidgetplugin.h"
2727
#include "qgsextentgroupboxplugin.h"
@@ -45,6 +45,7 @@ QgisCustomWidgets::QgisCustomWidgets( QObject *parent )
4545
mWidgets.append( new QgsColorButtonV2Plugin( this ) );
4646
mWidgets.append( new QgsDataDefinedButtonPlugin( this ) );
4747
mWidgets.append( new QgsDateTimeEditPlugin( this ) );
48+
mWidgets.append( new QgsDockWidgetPlugin( this ) );
4849
mWidgets.append( new QgsDoubleSpinBoxPlugin( this ) );
4950
mWidgets.append( new QgsExpressionBuilderWidgetPlugin( this ) );
5051
mWidgets.append( new QgsExtentGroupBoxPlugin( this ) );
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/***************************************************************************
2+
qgsdockwidgetplugin.cpp
3+
--------------------------------------
4+
Date : 10.06.2016
5+
Copyright : (C) 2016 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgiscustomwidgets.h"
17+
#include "qgsdockwidget.h"
18+
#include "qgsdockwidgetplugin.h"
19+
20+
21+
QgsDockWidgetPlugin::QgsDockWidgetPlugin( QObject *parent )
22+
: QObject( parent )
23+
, mInitialized( false )
24+
{
25+
}
26+
27+
28+
QString QgsDockWidgetPlugin::name() const
29+
{
30+
return "QgsDockWidget";
31+
}
32+
33+
QString QgsDockWidgetPlugin::group() const
34+
{
35+
return QgisCustomWidgets::groupName();
36+
}
37+
38+
QString QgsDockWidgetPlugin::includeFile() const
39+
{
40+
return "qgsdockwidget.h";
41+
}
42+
43+
QIcon QgsDockWidgetPlugin::icon() const
44+
{
45+
return QIcon( ":/images/icons/qgis-icon-60x60.png" );
46+
}
47+
48+
bool QgsDockWidgetPlugin::isContainer() const
49+
{
50+
return true;
51+
}
52+
53+
QWidget *QgsDockWidgetPlugin::createWidget( QWidget *parent )
54+
{
55+
return new QgsDockWidget( parent );
56+
}
57+
58+
bool QgsDockWidgetPlugin::isInitialized() const
59+
{
60+
return mInitialized;
61+
}
62+
63+
void QgsDockWidgetPlugin::initialize( QDesignerFormEditorInterface *core )
64+
{
65+
Q_UNUSED( core );
66+
if ( mInitialized )
67+
return;
68+
mInitialized = true;
69+
}
70+
71+
72+
QString QgsDockWidgetPlugin::toolTip() const
73+
{
74+
return tr( "A dock widget" );
75+
}
76+
77+
QString QgsDockWidgetPlugin::whatsThis() const
78+
{
79+
return tr( "A dock widget" );
80+
}
81+
82+
QString QgsDockWidgetPlugin::domXml() const
83+
{
84+
return QString( "<ui language=\"c++\">\n"
85+
" <widget class=\"%1\" name=\"mDockWidget\">\n"
86+
" <property name=\"geometry\">\n"
87+
" <rect>\n"
88+
" <x>0</x>\n"
89+
" <y>0</y>\n"
90+
" <width>300</width>\n"
91+
" <height>500</height>\n"
92+
" </rect>\n"
93+
" </property>\n"
94+
" </widget>\n"
95+
"</ui>\n" )
96+
.arg( name() );
97+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/***************************************************************************
2+
qgsdockwidgetplugin.h
3+
--------------------------------------
4+
Date : 10.06.2016
5+
Copyright : (C) 2016 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSDOCKWIDGETPLUGIN_H
17+
#define QGSDOCKWIDGETPLUGIN_H
18+
19+
20+
#include <QtGlobal>
21+
#if QT_VERSION < 0x050000
22+
#include <QDesignerCustomWidgetCollectionInterface>
23+
#include <QDesignerExportWidget>
24+
#else
25+
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
26+
#include <QtUiPlugin/QDesignerExportWidget>
27+
#endif
28+
29+
class CUSTOMWIDGETS_EXPORT QgsDockWidgetPlugin : public QObject, public QDesignerCustomWidgetInterface
30+
{
31+
Q_OBJECT
32+
Q_INTERFACES( QDesignerCustomWidgetInterface )
33+
34+
public:
35+
explicit QgsDockWidgetPlugin( QObject *parent = 0 );
36+
37+
private:
38+
bool mInitialized;
39+
40+
// QDesignerCustomWidgetInterface interface
41+
public:
42+
QString name() const override;
43+
QString group() const override;
44+
QString includeFile() const override;
45+
QIcon icon() const override;
46+
bool isContainer() const override;
47+
QWidget *createWidget( QWidget *parent ) override;
48+
bool isInitialized() const override;
49+
void initialize( QDesignerFormEditorInterface *core ) override;
50+
QString toolTip() const override;
51+
QString whatsThis() const override;
52+
QString domXml() const override;
53+
};
54+
#endif // QGSDOCKWIDGETPLUGIN_H

0 commit comments

Comments
 (0)