Skip to content

Commit 62be975

Browse files
author
mhugent
committed
[FEATURE]: arrow item for composer. Custom arrow heads from svg files are planned for the near future
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12248 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 51f6a45 commit 62be975

12 files changed

+774
-6
lines changed
537 Bytes
Loading

src/app/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ SET(QGIS_APP_SRCS
7373
qgsquerybuilder.cpp
7474

7575
composer/qgscomposer.cpp
76+
composer/qgscomposerarrowwidget.cpp
7677
composer/qgscomposeritemwidget.cpp
7778
composer/qgscomposerlabelwidget.cpp
7879
composer/qgscomposerpicturewidget.cpp
@@ -171,6 +172,7 @@ SET (QGIS_APP_MOC_HDRS
171172
qgsquerybuilder.h
172173

173174
composer/qgscomposer.h
175+
composer/qgscomposerarrowwidget.h
174176
composer/qgscomposeritemwidget.h
175177
composer/qgscomposerlabelwidget.h
176178
composer/qgscomposerlegendwidget.h

src/app/composer/qgscomposer.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "qgscomposerview.h"
2222
#include "qgscomposition.h"
2323
#include "qgscompositionwidget.h"
24+
#include "qgscomposerarrow.h"
25+
#include "qgscomposerarrowwidget.h"
2426
#include "qgscomposerlabel.h"
2527
#include "qgscomposerlabelwidget.h"
2628
#include "qgscomposerlegend.h"
@@ -109,6 +111,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
109111
toggleActionGroup->addAction( mActionAddImage );
110112
toggleActionGroup->addAction( mActionSelectMoveItem );
111113
toggleActionGroup->addAction( mActionAddBasicShape );
114+
toggleActionGroup->addAction( mActionAddArrow );
112115
toggleActionGroup->setExclusive( true );
113116

114117
mActionAddNewMap->setCheckable( true );
@@ -119,6 +122,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
119122
mActionAddImage->setCheckable( true );
120123
mActionMoveItemContent->setCheckable( true );
121124
mActionAddBasicShape->setCheckable( true );
125+
mActionAddArrow->setCheckable( true );
122126

123127
#ifdef Q_WS_MAC
124128
QMenu *appMenu = menuBar()->addMenu( tr( "QGIS" ) );
@@ -155,6 +159,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
155159
layoutMenu->addAction( mActionSelectMoveItem );
156160
layoutMenu->addAction( mActionMoveItemContent );
157161
layoutMenu->addAction( mActionAddBasicShape );
162+
layoutMenu->addAction( mActionAddArrow );
158163
layoutMenu->addSeparator();
159164
layoutMenu->addAction( mActionGroupItems );
160165
layoutMenu->addAction( mActionUngroupItems );
@@ -249,6 +254,7 @@ void QgsComposer::setupTheme()
249254
mActionAddNewLegend->setIcon( QgisApp::getThemeIcon( "/mActionAddLegend.png" ) );
250255
mActionAddNewScalebar->setIcon( QgisApp::getThemeIcon( "/mActionScaleBar.png" ) );
251256
mActionAddBasicShape->setIcon( QgisApp::getThemeIcon( "/mActionAddBasicShape.png" ) );
257+
mActionAddArrow->setIcon( QgisApp::getThemeIcon( "/mActionAddArrow.png" ) );
252258
mActionSelectMoveItem->setIcon( QgisApp::getThemeIcon( "/mActionSelectPan.png" ) );
253259
mActionMoveItemContent->setIcon( QgisApp::getThemeIcon( "/mActionMoveItemContent.png" ) );
254260
mActionGroupItems->setIcon( QgisApp::getThemeIcon( "/mActionGroupItems.png" ) );
@@ -275,6 +281,7 @@ void QgsComposer::connectSlots()
275281
connect( mView, SIGNAL( composerLegendAdded( QgsComposerLegend* ) ), this, SLOT( addComposerLegend( QgsComposerLegend* ) ) );
276282
connect( mView, SIGNAL( composerPictureAdded( QgsComposerPicture* ) ), this, SLOT( addComposerPicture( QgsComposerPicture* ) ) );
277283
connect( mView, SIGNAL( composerShapeAdded( QgsComposerShape* ) ), this, SLOT( addComposerShape( QgsComposerShape* ) ) );
284+
connect( mView, SIGNAL( composerArrowAdded( QgsComposerArrow* ) ), this, SLOT( addComposerArrow( QgsComposerArrow* ) ) );
278285
connect( mView, SIGNAL( actionFinished() ), this, SLOT( setSelectionTool() ) );
279286
}
280287

@@ -805,6 +812,14 @@ void QgsComposer::on_mActionAddBasicShape_triggered()
805812
}
806813
}
807814

815+
void QgsComposer::on_mActionAddArrow_triggered()
816+
{
817+
if ( mView )
818+
{
819+
mView->setCurrentTool( QgsComposerView::AddArrow );
820+
}
821+
}
822+
808823
void QgsComposer::on_mActionSaveAsTemplate_triggered()
809824
{
810825
//show file dialog
@@ -1217,6 +1232,21 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
12171232
showItemOptions( newShape );
12181233
}
12191234

1235+
//composer arrows
1236+
QDomNodeList composerArrowList = composerElem.elementsByTagName( "ComposerArrow" );
1237+
for ( int i = 0; i < composerArrowList.size(); ++i )
1238+
{
1239+
QDomElement currentArrowElem = composerArrowList.at( i ).toElement();
1240+
QgsComposerArrow* newArrow = new QgsComposerArrow( mComposition );
1241+
newArrow->readXML( currentArrowElem, doc );
1242+
addComposerArrow( newArrow );
1243+
mComposition->addItem( newArrow );
1244+
mComposition->update();
1245+
mComposition->clearSelection();
1246+
newArrow->setSelected( true );
1247+
showItemOptions( newArrow );
1248+
}
1249+
12201250
mComposition->sortZList();
12211251
mView->setComposition( mComposition );
12221252

@@ -1235,6 +1265,17 @@ void QgsComposer::deleteItems()
12351265
mItemWidgetMap.clear();
12361266
}
12371267

1268+
void QgsComposer::addComposerArrow( QgsComposerArrow* arrow )
1269+
{
1270+
if ( !arrow )
1271+
{
1272+
return;
1273+
}
1274+
1275+
QgsComposerArrowWidget* arrowWidget = new QgsComposerArrowWidget( arrow );
1276+
mItemWidgetMap.insert( arrow, arrowWidget );
1277+
}
1278+
12381279
void QgsComposer::addComposerMap( QgsComposerMap* map )
12391280
{
12401281
if ( !map )

src/app/composer/qgscomposer.h

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgscontexthelp.h"
2323

2424
class QgisApp;
25+
class QgsComposerArrow;
2526
class QgsComposerLabel;
2627
class QgsComposerLegend;
2728
class QgsComposerMap;
@@ -128,6 +129,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
128129
//! Select item
129130
void on_mActionSelectMoveItem_triggered();
130131

132+
//! Add arrow
133+
void on_mActionAddArrow_triggered();
134+
131135
//! Add new map
132136
void on_mActionAddNewMap_triggered();
133137

@@ -193,6 +197,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
193197
//! Save window state
194198
void saveWindowState();
195199

200+
/**Add a composer arrow to the item/widget map and crete a configuration widget for it*/
201+
void addComposerArrow( QgsComposerArrow* arrow );
202+
196203
/**Add a composer map to the item/widget map and creates a configuration widget for it*/
197204
void addComposerMap( QgsComposerMap* map );
198205

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/***************************************************************************
2+
qgscomposerarrowwidget.cpp
3+
--------------------------
4+
begin : November 2009
5+
copyright : (C) 2009 by Marco Hugentobler
6+
email : marco@hugis.net
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgscomposerarrowwidget.h"
19+
#include "qgscomposerarrow.h"
20+
#include "qgscomposeritemwidget.h"
21+
#include <QColorDialog>
22+
23+
QgsComposerArrowWidget::QgsComposerArrowWidget( QgsComposerArrow* arrow ): QWidget( 0 ), mArrow( arrow )
24+
{
25+
setupUi( this );
26+
27+
//add widget for general composer item properties
28+
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, mArrow );
29+
toolBox->addItem( itemPropertiesWidget, tr( "General options" ) );
30+
31+
setGuiElementValues();
32+
}
33+
34+
QgsComposerArrowWidget::~QgsComposerArrowWidget()
35+
{
36+
37+
}
38+
39+
void QgsComposerArrowWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
40+
{
41+
if ( !mArrow )
42+
{
43+
return;
44+
}
45+
46+
mArrow->setOutlineWidth( d );
47+
mArrow->update();
48+
}
49+
50+
void QgsComposerArrowWidget::on_mArrowHeadWidthSpinBox_valueChanged( double d )
51+
{
52+
if ( !mArrow )
53+
{
54+
return;
55+
}
56+
57+
mArrow->setArrowHeadWidth( d );
58+
mArrow->update();
59+
}
60+
61+
void QgsComposerArrowWidget::on_mShowArrowHeadCheckBox_stateChanged( int state )
62+
{
63+
if ( !mArrow )
64+
{
65+
return;
66+
}
67+
68+
if ( state == Qt::Checked )
69+
{
70+
mArrow->setShowArrowMarker( true );
71+
}
72+
else
73+
{
74+
mArrow->setShowArrowMarker( false );
75+
}
76+
mArrow->update();
77+
}
78+
79+
void QgsComposerArrowWidget::on_mArrowColorButton_clicked()
80+
{
81+
if ( !mArrow )
82+
{
83+
return;
84+
}
85+
86+
QColor newColor = QColorDialog::getColor( mArrow->arrowColor(), 0, tr( "Arrow color" ), QColorDialog::ShowAlphaChannel );
87+
if ( newColor.isValid() )
88+
{
89+
mArrow->setArrowColor( newColor );
90+
mArrow->update();
91+
}
92+
}
93+
94+
void QgsComposerArrowWidget::blockAllSignals( bool block )
95+
{
96+
mArrowColorButton->blockSignals( block );
97+
mShowArrowHeadCheckBox->blockSignals( block );
98+
mOutlineWidthSpinBox->blockSignals( block );
99+
mArrowHeadWidthSpinBox->blockSignals( block );
100+
}
101+
102+
void QgsComposerArrowWidget::setGuiElementValues()
103+
{
104+
if ( !mArrow )
105+
{
106+
return;
107+
}
108+
109+
blockAllSignals( true );
110+
mOutlineWidthSpinBox->setValue( mArrow->outlineWidth() );
111+
mArrowHeadWidthSpinBox->setValue( mArrow->arrowHeadWidth() );
112+
if ( mArrow->showArrowMarker() )
113+
{
114+
mShowArrowHeadCheckBox->setCheckState( Qt::Checked );
115+
}
116+
else
117+
{
118+
mShowArrowHeadCheckBox->setCheckState( Qt::Unchecked );
119+
}
120+
blockAllSignals( false );
121+
}
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/***************************************************************************
2+
qgscomposerarrowwidget.h
3+
------------------------
4+
begin : November 2009
5+
copyright : (C) 2009 by Marco Hugentobler
6+
email : marco@hugis.net
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSCOMPOSERARROWWIDGET_H
19+
#define QGSCOMPOSERARROWWIDGET_H
20+
21+
#include "ui_qgscomposerarrowwidgetbase.h"
22+
23+
class QgsComposerArrow;
24+
25+
class QgsComposerArrowWidget: public QWidget, private Ui::QgsComposerArrowWidgetBase
26+
{
27+
Q_OBJECT
28+
public:
29+
QgsComposerArrowWidget( QgsComposerArrow* arrow );
30+
~QgsComposerArrowWidget();
31+
32+
private:
33+
QgsComposerArrow* mArrow;
34+
35+
void blockAllSignals( bool block );
36+
void setGuiElementValues();
37+
38+
private slots:
39+
void on_mOutlineWidthSpinBox_valueChanged( double d );
40+
void on_mArrowHeadWidthSpinBox_valueChanged( double d );
41+
void on_mShowArrowHeadCheckBox_stateChanged( int state );
42+
void on_mArrowColorButton_clicked();
43+
};
44+
45+
#endif // QGSCOMPOSERARROWWIDGET_H

src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ SET(QGIS_CORE_SRCS
7070
qgsvectorlayerundocommand.cpp
7171
qgsvectoroverlay.cpp
7272

73+
composer/qgscomposerarrow.cpp
7374
composer/qgscomposeritem.cpp
7475
composer/qgscomposeritemgroup.cpp
7576
composer/qgscomposerlabel.cpp

0 commit comments

Comments
 (0)