Skip to content
Permalink
Browse files

Possitility to set start and end arrow marker from svg files

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12257 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 25, 2009
1 parent a933fe1 commit 11d80a36d8501eba35771c5b72ac1b6674e74a71
@@ -19,10 +19,20 @@
#include "qgscomposerarrow.h"
#include "qgscomposeritemwidget.h"
#include <QColorDialog>
#include <QFileDialog>
#include <QFileInfo>

QgsComposerArrowWidget::QgsComposerArrowWidget( QgsComposerArrow* arrow ): QWidget( 0 ), mArrow( arrow )
{
setupUi( this );
mRadioButtonGroup = new QButtonGroup( this );
mRadioButtonGroup->addButton( mDefaultMarkerRadioButton );
mRadioButtonGroup->addButton( mNoMarkerRadioButton );
mRadioButtonGroup->addButton( mSvgMarkerRadioButton );
mRadioButtonGroup->setExclusive( true );

//disable the svg related gui elements by default
on_mSvgMarkerRadioButton_toggled( false );

//add widget for general composer item properties
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, mArrow );
@@ -38,88 +48,175 @@ QgsComposerArrowWidget::~QgsComposerArrowWidget()

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

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

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

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

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

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

void QgsComposerArrowWidget::on_mShowArrowHeadCheckBox_stateChanged ( int state )
void QgsComposerArrowWidget::blockAllSignals( bool block )
{
if(!mArrow)
{
return;
}
mArrowColorButton->blockSignals( block );
mOutlineWidthSpinBox->blockSignals( block );
mArrowHeadWidthSpinBox->blockSignals( block );
mDefaultMarkerRadioButton->blockSignals( block );
mNoMarkerRadioButton->blockSignals( block );
mSvgMarkerRadioButton->blockSignals( block );
mStartMarkerLineEdit->blockSignals( block );
mStartMarkerToolButton->blockSignals( block );
mEndMarkerLineEdit->blockSignals( block );
mEndMarkerToolButton->blockSignals( block );
}

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

blockAllSignals( true );
mOutlineWidthSpinBox->setValue( mArrow->outlineWidth() );
mArrowHeadWidthSpinBox->setValue( mArrow->arrowHeadWidth() );

QgsComposerArrow::MarkerMode mode = mArrow->markerMode();
if ( mode == QgsComposerArrow::DefaultMarker )
{
mDefaultMarkerRadioButton->setChecked( true );
}
else if ( mode == QgsComposerArrow::NoMarker )
{
mNoMarkerRadioButton->setChecked( true );
}
else //svg marker
{
mSvgMarkerRadioButton->setChecked( true );
enableSvgInputElements( true );
}
mStartMarkerLineEdit->setText( mArrow->startMarker() );
mEndMarkerLineEdit->setText( mArrow->endMarker() );
blockAllSignals( false );
}

void QgsComposerArrowWidget::enableSvgInputElements( bool enable )
{
mStartMarkerLineEdit->setEnabled( enable );
mStartMarkerToolButton->setEnabled( enable );
mEndMarkerLineEdit->setEnabled( enable );
mEndMarkerToolButton->setEnabled( enable );
}

void QgsComposerArrowWidget::on_mDefaultMarkerRadioButton_toggled( bool toggled )
{
if ( mArrow && toggled )
{
mArrow->setMarkerMode( QgsComposerArrow::DefaultMarker );
mArrow->update();
}
}

void QgsComposerArrowWidget::on_mNoMarkerRadioButton_toggled( bool toggled )
{
if ( mArrow && toggled )
{
mArrow->setMarkerMode( QgsComposerArrow::NoMarker );
mArrow->update();
}
}

void QgsComposerArrowWidget::on_mSvgMarkerRadioButton_toggled( bool toggled )
{
enableSvgInputElements( toggled );
if ( mArrow && toggled )
{
mArrow->setMarkerMode( QgsComposerArrow::SVGMarker );
mArrow->update();
}
}

if(state == Qt::Checked)
void QgsComposerArrowWidget::on_mStartMarkerLineEdit_textChanged( const QString & text )
{
if ( mArrow )
{
QFileInfo fi( text );
if ( fi.exists() )
{
mArrow->setShowArrowMarker(true);
mArrow->setStartMarker( text );
}
else
{
mArrow->setShowArrowMarker(false);
mArrow->setStartMarker( "" );
}
mArrow->update();
}
}

void QgsComposerArrowWidget::on_mArrowColorButton_clicked()
void QgsComposerArrowWidget::on_mEndMarkerLineEdit_textChanged( const QString & text )
{
if(!mArrow)
if ( mArrow )
{
QFileInfo fi( text );
if ( fi.exists() )
{
return;
mArrow->setEndMarker( text );
}

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

void QgsComposerArrowWidget::blockAllSignals(bool block)
void QgsComposerArrowWidget::on_mStartMarkerToolButton_clicked()
{
mArrowColorButton->blockSignals(block);
mShowArrowHeadCheckBox->blockSignals(block);
mOutlineWidthSpinBox->blockSignals(block);
mArrowHeadWidthSpinBox->blockSignals(block);
QFileInfo fi( mStartMarkerLineEdit->text() );
QString svgFileName = QFileDialog::getOpenFileName( 0, tr( "Start marker svg file" ), fi.dir().absolutePath() );
if ( !svgFileName.isNull() )
{
mStartMarkerLineEdit->setText( svgFileName );
}
}

void QgsComposerArrowWidget::setGuiElementValues()
void QgsComposerArrowWidget::on_mEndMarkerToolButton_clicked()
{
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);
QFileInfo fi( mEndMarkerLineEdit->text() );
QString svgFileName = QFileDialog::getOpenFileName( 0, tr( "End marker svg file" ), fi.dir().absolutePath() );
if ( !svgFileName.isNull() )
{
mEndMarkerLineEdit ->setText( svgFileName );
}
}
@@ -34,12 +34,22 @@ class QgsComposerArrowWidget: public QWidget, private Ui::QgsComposerArrowWidget

void blockAllSignals( bool block );
void setGuiElementValues();
QButtonGroup* mRadioButtonGroup;

/**Enables / disables the SVG line inputs*/
void enableSvgInputElements( bool enable );

private slots:
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_mArrowHeadWidthSpinBox_valueChanged( double d );
void on_mShowArrowHeadCheckBox_stateChanged( int state );
void on_mArrowColorButton_clicked();
void on_mDefaultMarkerRadioButton_toggled( bool toggled );
void on_mNoMarkerRadioButton_toggled( bool toggled );
void on_mSvgMarkerRadioButton_toggled( bool toggled );
void on_mStartMarkerLineEdit_textChanged( const QString & text );
void on_mEndMarkerLineEdit_textChanged( const QString & text );
void on_mStartMarkerToolButton_clicked();
void on_mEndMarkerToolButton_clicked();
};

#endif // QGSCOMPOSERARROWWIDGET_H

0 comments on commit 11d80a3

Please sign in to comment.