Skip to content
Permalink
Browse files
[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@12248 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 25, 2009
1 parent 9fceb43 commit af96cfd9fe04746903cf43533fd1340c4b9581fc
Binary file not shown.
@@ -73,6 +73,7 @@ SET(QGIS_APP_SRCS
qgsquerybuilder.cpp

composer/qgscomposer.cpp
composer/qgscomposerarrowwidget.cpp
composer/qgscomposeritemwidget.cpp
composer/qgscomposerlabelwidget.cpp
composer/qgscomposerpicturewidget.cpp
@@ -171,6 +172,7 @@ SET (QGIS_APP_MOC_HDRS
qgsquerybuilder.h

composer/qgscomposer.h
composer/qgscomposerarrowwidget.h
composer/qgscomposeritemwidget.h
composer/qgscomposerlabelwidget.h
composer/qgscomposerlegendwidget.h
@@ -21,6 +21,8 @@
#include "qgscomposerview.h"
#include "qgscomposition.h"
#include "qgscompositionwidget.h"
#include "qgscomposerarrow.h"
#include "qgscomposerarrowwidget.h"
#include "qgscomposerlabel.h"
#include "qgscomposerlabelwidget.h"
#include "qgscomposerlegend.h"
@@ -109,6 +111,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
toggleActionGroup->addAction( mActionAddImage );
toggleActionGroup->addAction( mActionSelectMoveItem );
toggleActionGroup->addAction( mActionAddBasicShape );
toggleActionGroup->addAction( mActionAddArrow );
toggleActionGroup->setExclusive( true );

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

#ifdef Q_WS_MAC
QMenu *appMenu = menuBar()->addMenu( tr( "QGIS" ) );
@@ -155,6 +159,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
layoutMenu->addAction( mActionSelectMoveItem );
layoutMenu->addAction( mActionMoveItemContent );
layoutMenu->addAction( mActionAddBasicShape );
layoutMenu->addAction( mActionAddArrow );
layoutMenu->addSeparator();
layoutMenu->addAction( mActionGroupItems );
layoutMenu->addAction( mActionUngroupItems );
@@ -249,6 +254,7 @@ void QgsComposer::setupTheme()
mActionAddNewLegend->setIcon( QgisApp::getThemeIcon( "/mActionAddLegend.png" ) );
mActionAddNewScalebar->setIcon( QgisApp::getThemeIcon( "/mActionScaleBar.png" ) );
mActionAddBasicShape->setIcon( QgisApp::getThemeIcon( "/mActionAddBasicShape.png" ) );
mActionAddArrow->setIcon( QgisApp::getThemeIcon( "/mActionAddArrow.png" ) );
mActionSelectMoveItem->setIcon( QgisApp::getThemeIcon( "/mActionSelectPan.png" ) );
mActionMoveItemContent->setIcon( QgisApp::getThemeIcon( "/mActionMoveItemContent.png" ) );
mActionGroupItems->setIcon( QgisApp::getThemeIcon( "/mActionGroupItems.png" ) );
@@ -275,6 +281,7 @@ void QgsComposer::connectSlots()
connect( mView, SIGNAL( composerLegendAdded( QgsComposerLegend* ) ), this, SLOT( addComposerLegend( QgsComposerLegend* ) ) );
connect( mView, SIGNAL( composerPictureAdded( QgsComposerPicture* ) ), this, SLOT( addComposerPicture( QgsComposerPicture* ) ) );
connect( mView, SIGNAL( composerShapeAdded( QgsComposerShape* ) ), this, SLOT( addComposerShape( QgsComposerShape* ) ) );
connect( mView, SIGNAL( composerArrowAdded( QgsComposerArrow* ) ), this, SLOT( addComposerArrow( QgsComposerArrow* ) ) );
connect( mView, SIGNAL( actionFinished() ), this, SLOT( setSelectionTool() ) );
}

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

void QgsComposer::on_mActionAddArrow_triggered()
{
if ( mView )
{
mView->setCurrentTool( QgsComposerView::AddArrow );
}
}

void QgsComposer::on_mActionSaveAsTemplate_triggered()
{
//show file dialog
@@ -1217,6 +1232,21 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
showItemOptions( newShape );
}

//composer arrows
QDomNodeList composerArrowList = composerElem.elementsByTagName( "ComposerArrow" );
for ( int i = 0; i < composerArrowList.size(); ++i )
{
QDomElement currentArrowElem = composerArrowList.at( i ).toElement();
QgsComposerArrow* newArrow = new QgsComposerArrow( mComposition );
newArrow->readXML( currentArrowElem, doc );
addComposerArrow( newArrow );
mComposition->addItem( newArrow );
mComposition->update();
mComposition->clearSelection();
newArrow->setSelected( true );
showItemOptions( newArrow );
}

mComposition->sortZList();
mView->setComposition( mComposition );

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

void QgsComposer::addComposerArrow( QgsComposerArrow* arrow )
{
if ( !arrow )
{
return;
}

QgsComposerArrowWidget* arrowWidget = new QgsComposerArrowWidget( arrow );
mItemWidgetMap.insert( arrow, arrowWidget );
}

void QgsComposer::addComposerMap( QgsComposerMap* map )
{
if ( !map )
@@ -22,6 +22,7 @@
#include "qgscontexthelp.h"

class QgisApp;
class QgsComposerArrow;
class QgsComposerLabel;
class QgsComposerLegend;
class QgsComposerMap;
@@ -128,6 +129,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Select item
void on_mActionSelectMoveItem_triggered();

//! Add arrow
void on_mActionAddArrow_triggered();

//! Add new map
void on_mActionAddNewMap_triggered();

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

/**Add a composer arrow to the item/widget map and crete a configuration widget for it*/
void addComposerArrow( QgsComposerArrow* arrow );

/**Add a composer map to the item/widget map and creates a configuration widget for it*/
void addComposerMap( QgsComposerMap* map );

@@ -0,0 +1,121 @@
/***************************************************************************
qgscomposerarrowwidget.cpp
--------------------------
begin : November 2009
copyright : (C) 2009 by Marco Hugentobler
email : marco@hugis.net
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgscomposerarrowwidget.h"
#include "qgscomposerarrow.h"
#include "qgscomposeritemwidget.h"
#include <QColorDialog>

QgsComposerArrowWidget::QgsComposerArrowWidget( QgsComposerArrow* arrow ): QWidget( 0 ), mArrow( arrow )
{
setupUi( this );

//add widget for general composer item properties
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, mArrow );
toolBox->addItem( itemPropertiesWidget, tr( "General options" ) );

setGuiElementValues();
}

QgsComposerArrowWidget::~QgsComposerArrowWidget()
{

}

void QgsComposerArrowWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
{
if ( !mArrow )
{
return;
}

mArrow->setOutlineWidth( d );
mArrow->update();
}

void QgsComposerArrowWidget::on_mArrowHeadWidthSpinBox_valueChanged( double d )
{
if ( !mArrow )
{
return;
}

mArrow->setArrowHeadWidth( d );
mArrow->update();
}

void QgsComposerArrowWidget::on_mShowArrowHeadCheckBox_stateChanged( int state )
{
if ( !mArrow )
{
return;
}

if ( state == Qt::Checked )
{
mArrow->setShowArrowMarker( true );
}
else
{
mArrow->setShowArrowMarker( false );
}
mArrow->update();
}

void QgsComposerArrowWidget::on_mArrowColorButton_clicked()
{
if ( !mArrow )
{
return;
}

QColor newColor = QColorDialog::getColor( mArrow->arrowColor(), 0, tr( "Arrow color" ), QColorDialog::ShowAlphaChannel );
if ( newColor.isValid() )
{
mArrow->setArrowColor( newColor );
mArrow->update();
}
}

void QgsComposerArrowWidget::blockAllSignals( bool block )
{
mArrowColorButton->blockSignals( block );
mShowArrowHeadCheckBox->blockSignals( block );
mOutlineWidthSpinBox->blockSignals( block );
mArrowHeadWidthSpinBox->blockSignals( block );
}

void QgsComposerArrowWidget::setGuiElementValues()
{
if ( !mArrow )
{
return;
}

blockAllSignals( true );
mOutlineWidthSpinBox->setValue( mArrow->outlineWidth() );
mArrowHeadWidthSpinBox->setValue( mArrow->arrowHeadWidth() );
if ( mArrow->showArrowMarker() )
{
mShowArrowHeadCheckBox->setCheckState( Qt::Checked );
}
else
{
mShowArrowHeadCheckBox->setCheckState( Qt::Unchecked );
}
blockAllSignals( false );
}
@@ -0,0 +1,45 @@
/***************************************************************************
qgscomposerarrowwidget.h
------------------------
begin : November 2009
copyright : (C) 2009 by Marco Hugentobler
email : marco@hugis.net
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSCOMPOSERARROWWIDGET_H
#define QGSCOMPOSERARROWWIDGET_H

#include "ui_qgscomposerarrowwidgetbase.h"

class QgsComposerArrow;

class QgsComposerArrowWidget: public QWidget, private Ui::QgsComposerArrowWidgetBase
{
Q_OBJECT
public:
QgsComposerArrowWidget( QgsComposerArrow* arrow );
~QgsComposerArrowWidget();

private:
QgsComposerArrow* mArrow;

void blockAllSignals( bool block );
void setGuiElementValues();

private slots:
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_mArrowHeadWidthSpinBox_valueChanged( double d );
void on_mShowArrowHeadCheckBox_stateChanged( int state );
void on_mArrowColorButton_clicked();
};

#endif // QGSCOMPOSERARROWWIDGET_H
@@ -70,6 +70,7 @@ SET(QGIS_CORE_SRCS
qgsvectorlayerundocommand.cpp
qgsvectoroverlay.cpp

composer/qgscomposerarrow.cpp
composer/qgscomposeritem.cpp
composer/qgscomposeritemgroup.cpp
composer/qgscomposerlabel.cpp

0 comments on commit af96cfd

Please sign in to comment.