21
21
#include " qgscomposeritemwidget.h"
22
22
#include < QFontDialog>
23
23
24
+ #include " qgsapplegendinterface.h"
25
+ #include " qgisapp.h"
26
+ #include " qgsmapcanvas.h"
27
+ #include " qgsmaprenderer.h"
28
+
24
29
QgsComposerLegendWidget::QgsComposerLegendWidget ( QgsComposerLegend* legend ): mLegend( legend )
25
30
{
26
31
setupUi ( this );
@@ -34,6 +39,14 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): m
34
39
mItemTreeView ->setModel ( legend->model () );
35
40
}
36
41
42
+ updateLegend ();
43
+
44
+ mItemTreeView ->setDragEnabled ( true );
45
+ mItemTreeView ->setAcceptDrops ( true );
46
+ mItemTreeView ->setDropIndicatorShown ( true );
47
+ mItemTreeView ->setDefaultDropAction ( Qt::MoveAction );
48
+ mItemTreeView ->setDragDropMode ( QAbstractItemView::InternalMove );
49
+
37
50
setGuiElements ();
38
51
}
39
52
@@ -147,6 +160,26 @@ void QgsComposerLegendWidget::on_mTitleFontButton_clicked()
147
160
}
148
161
}
149
162
163
+ void QgsComposerLegendWidget::on_mGroupFontButton_clicked ()
164
+ {
165
+ if ( mLegend )
166
+ {
167
+ bool ok;
168
+ #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && !defined(__LP64__)
169
+ // Native Mac dialog works only for 64 bit Cocoa (observed in Qt 4.5.2, probably a Qt bug)
170
+ QFont newFont = QFontDialog::getFont ( &ok, mLegend ->groupFont (), this , QString (), QFontDialog::DontUseNativeDialog );
171
+ #else
172
+ QFont newFont = QFontDialog::getFont ( &ok, mLegend ->groupFont () );
173
+ #endif
174
+ if ( ok )
175
+ {
176
+ mLegend ->setGroupFont ( newFont );
177
+ mLegend ->adjustBoxSize ();
178
+ mLegend ->update ();
179
+ }
180
+ }
181
+ }
182
+
150
183
void QgsComposerLegendWidget::on_mLayerFontButton_clicked ()
151
184
{
152
185
if ( mLegend )
@@ -387,9 +420,44 @@ void QgsComposerLegendWidget::on_mUpdatePushButton_clicked()
387
420
}
388
421
389
422
void QgsComposerLegendWidget::on_mUpdateAllPushButton_clicked ()
423
+ {
424
+ updateLegend ();
425
+ }
426
+
427
+ void QgsComposerLegendWidget::on_mAddGroupButton_clicked ()
428
+ {
429
+ if ( mLegend && mLegend ->model () )
430
+ {
431
+ mLegend ->model ()->addGroup ();
432
+ mLegend ->update ();
433
+ }
434
+ }
435
+
436
+ void QgsComposerLegendWidget::updateLegend ()
390
437
{
391
438
if ( mLegend )
392
439
{
393
- mLegend ->updateLegend ();
440
+ QgisApp* app = QgisApp::instance ();
441
+ if ( !app )
442
+ {
443
+ return ;
444
+ }
445
+
446
+ // get layer id list
447
+ QStringList layerIdList;
448
+ QgsMapCanvas* canvas = app->mapCanvas ();
449
+ if ( canvas )
450
+ {
451
+ QgsMapRenderer* renderer = canvas->mapRenderer ();
452
+ if ( renderer )
453
+ {
454
+ layerIdList = renderer->layerSet ();
455
+ }
456
+ }
457
+
458
+ // and also group info
459
+ QgsAppLegendInterface legendIface ( app->legend () );
460
+ QList< GroupLayerInfo > groupInfo = legendIface.groupLayerRelationship ();
461
+ mLegend ->model ()->setLayerSetAndGroups ( layerIdList, groupInfo );
394
462
}
395
463
}
0 commit comments