16
16
***************************************************************************/
17
17
18
18
#include " qgslayoutdesignerdialog.h"
19
+ #include " qgslayoutitemregistry.h"
19
20
#include " qgssettings.h"
20
21
#include " qgisapp.h"
21
22
#include " qgslogger.h"
@@ -39,6 +40,7 @@ void QgsAppLayoutDesignerInterface::close()
39
40
QgsLayoutDesignerDialog::QgsLayoutDesignerDialog ( QWidget *parent, Qt::WindowFlags flags )
40
41
: QMainWindow( parent, flags )
41
42
, mInterface( new QgsAppLayoutDesignerInterface( this ) )
43
+ , mToolsActionGroup( new QActionGroup( this ) )
42
44
{
43
45
QgsSettings settings;
44
46
int size = settings.value ( QStringLiteral ( " IconSize" ), QGIS_ICON_SIZE ).toInt ();
@@ -55,6 +57,16 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
55
57
56
58
connect ( mActionClose , &QAction::triggered, this , &QWidget::close );
57
59
60
+ // populate with initial items...
61
+ QMap< int , QString> types = QgsApplication::layoutItemRegistry ()->itemTypes ();
62
+ QMap< int , QString>::const_iterator typeIt = types.constBegin ();
63
+ for ( ; typeIt != types.constEnd (); ++typeIt )
64
+ {
65
+ itemTypeAdded ( typeIt.key (), typeIt.value () );
66
+ }
67
+ // ..and listen out for new item types
68
+ connect ( QgsApplication::layoutItemRegistry (), &QgsLayoutItemRegistry::typeAdded, this , &QgsLayoutDesignerDialog::itemTypeAdded );
69
+
58
70
restoreWindowState ();
59
71
}
60
72
@@ -122,6 +134,23 @@ void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
122
134
saveWindowState ();
123
135
}
124
136
137
+ void QgsLayoutDesignerDialog::itemTypeAdded ( int type, const QString &name )
138
+ {
139
+ // update UI for new item type
140
+ QAction *action = new QAction ( tr ( " Add %1" ).arg ( name ), this );
141
+ action->setToolTip ( tr ( " Adds a new %1 to the layout" ).arg ( name ) );
142
+ action->setCheckable ( true );
143
+ action->setData ( type );
144
+ action->setIcon ( QgsApplication::layoutItemRegistry ()->itemMetadata ( type )->icon () );
145
+ mToolsActionGroup ->addAction ( action );
146
+ mItemMenu ->addAction ( action );
147
+ mItemToolbar ->addAction ( action );
148
+ connect ( action, &QAction::triggered, this , [this , type]()
149
+ {
150
+ activateNewItemCreationTool ( type );
151
+ } );
152
+ }
153
+
125
154
void QgsLayoutDesignerDialog::saveWindowState ()
126
155
{
127
156
QgsSettings settings;
@@ -147,4 +176,9 @@ void QgsLayoutDesignerDialog::restoreWindowState()
147
176
}
148
177
}
149
178
179
+ void QgsLayoutDesignerDialog::activateNewItemCreationTool ( int type )
180
+ {
181
+ QgsLogger::debug ( QStringLiteral ( " creating new %1 item " ).arg ( QgsApplication::layoutItemRegistry ()->itemMetadata ( type )->visibleName () ) );
182
+ }
183
+
150
184
0 commit comments