| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| /*************************************************************************** | ||
| qgsdecorationgrid.h | ||
| ---------------------- | ||
| begin : May 10, 2012 | ||
| copyright : (C) 2012 by Etienne Tourigny | ||
| email : etourigny.dev at gmail dot com | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * 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 QGSDECORATIONGRID_H | ||
| #define QGSDECORATIONGRID_H | ||
|
|
||
| #include "qgsdecorationitem.h" | ||
| #include <qgis.h> | ||
|
|
||
| class QPainter; | ||
| class QgsLineSymbolV2; | ||
| class QgsMarkerSymbolV2; | ||
|
|
||
| #include <QColor> | ||
| #include <QPen> | ||
| #include <QFont> | ||
|
|
||
| class QgsDecorationGrid: public QgsDecorationItem | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| //! Constructor | ||
| QgsDecorationGrid( QObject* parent = NULL ); | ||
| //! Destructor | ||
| virtual ~ QgsDecorationGrid(); | ||
|
|
||
| enum GridStyle | ||
| { | ||
| Line = 0, //solid lines | ||
| // Cross = 1, //only draw line crossings | ||
| Marker = 1 //user-defined marker | ||
| }; | ||
|
|
||
| enum GridAnnotationPosition | ||
| { | ||
| InsideMapFrame = 0, | ||
| OutsideMapFrame | ||
| }; | ||
|
|
||
| enum GridAnnotationDirection | ||
| { | ||
| Horizontal = 0, | ||
| Vertical, | ||
| HorizontalAndVertical, | ||
| BoundaryDirection | ||
| }; | ||
|
|
||
| /**Sets coordinate grid style. | ||
| @note this function (and all others) was added in version 2.0 */ | ||
| void setGridStyle( GridStyle style ) {mGridStyle = style;} | ||
| GridStyle gridStyle() const { return mGridStyle; } | ||
|
|
||
| /**Sets coordinate interval in x-direction for composergrid. */ | ||
| void setGridIntervalX( double interval ) { mGridIntervalX = interval;} | ||
| double gridIntervalX() const { return mGridIntervalX; } | ||
|
|
||
| /**Sets coordinate interval in y-direction for composergrid. */ | ||
| void setGridIntervalY( double interval ) { mGridIntervalY = interval;} | ||
| double gridIntervalY() const { return mGridIntervalY; } | ||
|
|
||
| /**Sets x-coordinate offset for composer grid */ | ||
| void setGridOffsetX( double offset ) { mGridOffsetX = offset; } | ||
| double gridOffsetX() const { return mGridOffsetX; } | ||
|
|
||
| /**Sets y-coordinate offset for composer grid */ | ||
| void setGridOffsetY( double offset ) { mGridOffsetY = offset; } | ||
| double gridOffsetY() const { return mGridOffsetY; } | ||
|
|
||
| /**Sets the pen to draw composer grid */ | ||
| void setGridPen( const QPen& p ) { mGridPen = p; } | ||
| QPen gridPen() const { return mGridPen; } | ||
| /**Sets with of grid pen */ | ||
| void setGridPenWidth( double w ) { mGridPen.setWidthF( w ); } | ||
| /**Sets the color of the grid pen */ | ||
| void setGridPenColor( const QColor& c ) { mGridPen.setColor( c ); } | ||
|
|
||
| /**Sets font for grid annotations */ | ||
| void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; } | ||
| QFont gridAnnotationFont() const { return mGridAnnotationFont; } | ||
|
|
||
| /**Sets coordinate precision for grid annotations */ | ||
| void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;} | ||
| int gridAnnotationPrecision() const {return mGridAnnotationPrecision;} | ||
|
|
||
| /**Sets flag if grid annotation should be shown */ | ||
| void setShowGridAnnotation( bool show ) {mShowGridAnnotation = show;} | ||
| bool showGridAnnotation() const {return mShowGridAnnotation;} | ||
|
|
||
| /**Sets position of grid annotations. Possibilities are inside or outside of the map frame */ | ||
| void setGridAnnotationPosition( GridAnnotationPosition p ) {mGridAnnotationPosition = p;} | ||
| GridAnnotationPosition gridAnnotationPosition() const {return mGridAnnotationPosition;} | ||
|
|
||
| /**Sets distance between map frame and annotations */ | ||
| void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;} | ||
| double annotationFrameDistance() const {return mAnnotationFrameDistance;} | ||
|
|
||
| /**Sets grid annotation direction. Can be horizontal, vertical, direction of axis and horizontal and vertical */ | ||
| void setGridAnnotationDirection( GridAnnotationDirection d ) {mGridAnnotationDirection = d;} | ||
| GridAnnotationDirection gridAnnotationDirection() const {return mGridAnnotationDirection;} | ||
|
|
||
| /**Sets length of the cros segments (if grid style is cross) */ | ||
| /* void setCrossLength( double l ) {mCrossLength = l;} */ | ||
| /* double crossLength() {return mCrossLength;} */ | ||
|
|
||
| /**Set symbol that is used to draw grid lines. Takes ownership*/ | ||
| void setLineSymbol( QgsLineSymbolV2* symbol ); | ||
| const QgsLineSymbolV2* lineSymbol() const { return mLineSymbol; } | ||
|
|
||
| /**Set symbol that is used to draw markers. Takes ownership*/ | ||
| void setMarkerSymbol( QgsMarkerSymbolV2* symbol ); | ||
| const QgsMarkerSymbolV2* markerSymbol() const { return mMarkerSymbol; } | ||
|
|
||
| /**Sets map unit type */ | ||
| void setMapUnits( QGis::UnitType t ) { mMapUnits = t; } | ||
| QGis::UnitType mapUnits() { return mMapUnits; } | ||
|
|
||
| /**Set mapUnits value */ | ||
| void setDirty( bool dirty = true ); | ||
| bool isDirty(); | ||
|
|
||
| /**Computes interval that is approx. 1/5 of canvas extent */ | ||
| bool getIntervalFromExtent( double* values, bool useXAxis = true ); | ||
| /**Computes interval from current raster layer */ | ||
| bool getIntervalFromCurrentLayer( double* values ); | ||
|
|
||
| double getDefaultInterval( bool useXAxis = true ); | ||
|
|
||
| public slots: | ||
| //! set values on the gui when a project is read or the gui first loaded | ||
| void projectRead(); | ||
| //! save values to the project | ||
| void saveToProject(); | ||
|
|
||
| //! this does the meaty bit of the work | ||
| void render( QPainter * ); | ||
| //! Show the dialog box | ||
| void run(); | ||
|
|
||
| //! check that map units changed and disable if necessary | ||
| void checkMapUnitsChanged(); | ||
|
|
||
| private: | ||
|
|
||
| /**Enum for different frame borders*/ | ||
| enum Border | ||
| { | ||
| Left, | ||
| Right, | ||
| Bottom, | ||
| Top | ||
| }; | ||
|
|
||
| /** Line or Symbol */ | ||
| GridStyle mGridStyle; | ||
| /**Grid line interval in x-direction (map units)*/ | ||
| double mGridIntervalX; | ||
| /**Grid line interval in y-direction (map units)*/ | ||
| double mGridIntervalY; | ||
| /**Grid line offset in x-direction*/ | ||
| double mGridOffsetX; | ||
| /**Grid line offset in y-direction*/ | ||
| double mGridOffsetY; | ||
| /**Grid line pen*/ | ||
| QPen mGridPen; | ||
| /**Font for grid line annotation*/ | ||
| QFont mGridAnnotationFont; | ||
| /**Digits after the dot*/ | ||
| int mGridAnnotationPrecision; | ||
| /**True if coordinate values should be drawn*/ | ||
| bool mShowGridAnnotation; | ||
| /**Annotation position inside or outside of map frame*/ | ||
| GridAnnotationPosition mGridAnnotationPosition; | ||
| /**Distance between map frame and annotation*/ | ||
| double mAnnotationFrameDistance; | ||
| /**Annotation can be horizontal / vertical or different for axes*/ | ||
| GridAnnotationDirection mGridAnnotationDirection; | ||
| /**The length of the cross sides for mGridStyle Cross*/ | ||
| /* double mCrossLength; */ | ||
|
|
||
| QgsLineSymbolV2* mLineSymbol; | ||
| QgsMarkerSymbolV2* mMarkerSymbol; | ||
|
|
||
| QGis::UnitType mMapUnits; | ||
|
|
||
| /**Draw coordinates for mGridAnnotationType Coordinate | ||
| @param p drawing painter | ||
| @param hLines horizontal coordinate lines in item coordinates | ||
| @param vLines vertical coordinate lines in item coordinates*/ | ||
| void drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ); | ||
| void drawCoordinateAnnotation( QPainter* p, const QPointF& pos, QString annotationString ); | ||
| /**Draws a single annotation | ||
| @param p drawing painter | ||
| @param pos item coordinates where to draw | ||
| @param rotation text rotation | ||
| @param annotationText the text to draw*/ | ||
| void drawAnnotation( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText ); | ||
| /**Returns the grid lines with associated coordinate value | ||
| @return 0 in case of success*/ | ||
| int xGridLines( QList< QPair< double, QLineF > >& lines, QPainter* p ) const; | ||
| /**Returns the grid lines for the y-coordinates. Not vertical in case of rotation | ||
| @return 0 in case of success*/ | ||
| int yGridLines( QList< QPair< double, QLineF > >& lines, QPainter* p ) const; | ||
| /**Returns the item border of a point (in item coordinates)*/ | ||
| Border borderForLineCoord( const QPointF& point, QPainter* p ) const; | ||
|
|
||
| /**Draws Text. Takes care about all the composer specific issues (calculation to pixel, scaling of font and painter | ||
| to work around the Qt font bug)*/ | ||
| void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const; | ||
| /**Like the above, but with a rectangle for multiline text*/ | ||
| void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignement = Qt::AlignLeft, Qt::AlignmentFlag valignement = Qt::AlignTop ) const; | ||
| /**Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/ | ||
| double textWidthMillimeters( const QFont& font, const QString& text ) const; | ||
| /**Returns the font height of a character in millimeters. */ | ||
| double fontHeightCharacterMM( const QFont& font, const QChar& c ) const; | ||
| /**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/ | ||
| double fontAscentMillimeters( const QFont& font ) const; | ||
| /**Calculates font to from point size to pixel size*/ | ||
| double pixelFontSize( double pointSize ) const; | ||
| /**Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE*/ | ||
| QFont scaledFontPixelSize( const QFont& font ) const; | ||
|
|
||
| /* friend class QgsDecorationGridDialog; */ | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,311 @@ | ||
| /*************************************************************************** | ||
| qgsdecorationgriddialog.cpp | ||
| ---------------------- | ||
| begin : May 10, 2012 | ||
| copyright : (C) 2012 by Etienne Tourigny | ||
| email : etourigny.dev at gmail dot com | ||
| ***************************************************************************/ | ||
| /*************************************************************************** | ||
| * * | ||
| * 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 "qgsdecorationgriddialog.h" | ||
|
|
||
| #include "qgsdecorationgrid.h" | ||
|
|
||
| #include "qgslogger.h" | ||
| #include "qgscontexthelp.h" | ||
| #include "qgsstylev2.h" | ||
| #include "qgssymbolv2.h" | ||
| #include "qgssymbolv2selectordialog.h" | ||
| #include "qgssymbolv2propertiesdialog.h" | ||
| #include "qgisapp.h" | ||
|
|
||
| #include <QFontDialog> | ||
| #include <QColorDialog> | ||
| #include <QSettings> | ||
|
|
||
| QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid& deco, QWidget* parent ) | ||
| : QDialog( parent ), mDeco( deco ), mLineSymbol( 0 ), mMarkerSymbol( 0 ) | ||
| { | ||
| setupUi( this ); | ||
|
|
||
| QSettings settings; | ||
| // restoreGeometry( settings.value( "/Windows/DecorationGrid/geometry" ).toByteArray() ); | ||
|
|
||
| chkEnable->setChecked( mDeco.enabled() ); | ||
|
|
||
| // mXMinLineEdit->setValidator( new QDoubleValidator( mXMinLineEdit ) ); | ||
|
|
||
| mGridTypeComboBox->insertItem( QgsDecorationGrid::Line, tr( "Line" ) ); | ||
| // mGridTypeComboBox->insertItem( QgsDecorationGrid::Cross, tr( "Cross" ) ); | ||
| mGridTypeComboBox->insertItem( QgsDecorationGrid::Marker, tr( "Marker" ) ); | ||
|
|
||
| // mAnnotationPositionComboBox->insertItem( QgsDecorationGrid::InsideMapFrame, tr( "Inside frame" ) ); | ||
| // mAnnotationPositionComboBox->insertItem( QgsDecorationGrid::OutsideMapFrame, tr( "Outside frame" ) ); | ||
|
|
||
| mAnnotationDirectionComboBox->insertItem( QgsDecorationGrid::Horizontal, | ||
| tr( "Horizontal" ) ); | ||
| mAnnotationDirectionComboBox->insertItem( QgsDecorationGrid::Vertical, | ||
| tr( "Vertical" ) ); | ||
| mAnnotationDirectionComboBox->insertItem( QgsDecorationGrid::HorizontalAndVertical, | ||
| tr( "Horizontal and vertical" ) ); | ||
| mAnnotationDirectionComboBox->insertItem( QgsDecorationGrid::BoundaryDirection, | ||
| tr( "Boundary direction" ) ); | ||
|
|
||
| updateGuiElements(); | ||
|
|
||
| connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); | ||
|
|
||
| } | ||
|
|
||
| void QgsDecorationGridDialog::updateGuiElements() | ||
| { | ||
| // blockAllSignals( true ); | ||
|
|
||
| chkEnable->setChecked( mDeco.enabled() ); | ||
|
|
||
| mIntervalXEdit->setText( QString::number( mDeco.gridIntervalX() ) ); | ||
| mIntervalYEdit->setText( QString::number( mDeco.gridIntervalY() ) ); | ||
| mOffsetXEdit->setText( QString::number( mDeco.gridOffsetX() ) ); | ||
| mOffsetYEdit->setText( QString::number( mDeco.gridOffsetY() ) ); | ||
|
|
||
| mGridTypeComboBox->setCurrentIndex(( int ) mDeco.gridStyle() ); | ||
| mDrawAnnotationCheckBox->setChecked( mDeco.showGridAnnotation() ); | ||
| mAnnotationDirectionComboBox->setCurrentIndex(( int ) mDeco.gridAnnotationDirection() ); | ||
| mCoordinatePrecisionSpinBox->setValue( mDeco.gridAnnotationPrecision() ); | ||
|
|
||
| // QPen gridPen = mDeco.gridPen(); | ||
| // mLineWidthSpinBox->setValue( gridPen.widthF() ); | ||
| // mLineColorButton->setColor( gridPen.color() ); | ||
|
|
||
| if ( mLineSymbol ) | ||
| delete mLineSymbol; | ||
| if ( mDeco.lineSymbol() ) | ||
| { | ||
| mLineSymbol = dynamic_cast<QgsLineSymbolV2*>( mDeco.lineSymbol()->clone() ); | ||
| QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mLineSymbol, mLineSymbolButton->iconSize() ); | ||
| mLineSymbolButton->setIcon( icon ); | ||
| } | ||
| if ( mMarkerSymbol ) | ||
| delete mMarkerSymbol; | ||
| if ( mDeco.markerSymbol() ) | ||
| { | ||
| mMarkerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( mDeco.markerSymbol()->clone() ); | ||
| QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mMarkerSymbol, mMarkerSymbolButton->iconSize() ); | ||
| mMarkerSymbolButton->setIcon( icon ); | ||
| } | ||
|
|
||
| updateInterval( false ); | ||
|
|
||
| // blockAllSignals( false ); | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::updateDecoFromGui() | ||
| { | ||
| mDeco.setDirty( false ); | ||
| mDeco.setEnabled( chkEnable->isChecked() ); | ||
|
|
||
| mDeco.setGridIntervalX( mIntervalXEdit->text().toDouble() ); | ||
| mDeco.setGridIntervalY( mIntervalYEdit->text().toDouble() ); | ||
| mDeco.setGridOffsetX( mOffsetXEdit->text().toDouble() ); | ||
| mDeco.setGridOffsetY( mOffsetYEdit->text().toDouble() ); | ||
| if ( mGridTypeComboBox->currentText() == tr( "Marker" ) ) | ||
| { | ||
| mDeco.setGridStyle( QgsDecorationGrid::Marker ); | ||
| } | ||
| else if ( mGridTypeComboBox->currentText() == tr( "Line" ) ) | ||
| { | ||
| mDeco.setGridStyle( QgsDecorationGrid::Line ); | ||
| } | ||
| mDeco.setAnnotationFrameDistance( mDistanceToMapFrameSpinBox->value() ); | ||
| // if ( mAnnotationPositionComboBox->currentText() == tr( "Inside frame" ) ) | ||
| // { | ||
| // mDeco.setGridAnnotationPosition( QgsDecorationGrid::InsideMapFrame ); | ||
| // } | ||
| // else | ||
| // { | ||
| // mDeco.setGridAnnotationPosition( QgsDecorationGrid::OutsideMapFrame ); | ||
| // } | ||
| mDeco.setShowGridAnnotation( mDrawAnnotationCheckBox->isChecked() ); | ||
| QString text = mAnnotationDirectionComboBox->currentText(); | ||
| if ( text == tr( "Horizontal" ) ) | ||
| { | ||
| mDeco.setGridAnnotationDirection( QgsDecorationGrid::Horizontal ); | ||
| } | ||
| else if ( text == tr( "Vertical" ) ) | ||
| { | ||
| mDeco.setGridAnnotationDirection( QgsDecorationGrid::Vertical ); | ||
| } | ||
| else if ( text == tr( "Horizontal and Vertical" ) ) | ||
| { | ||
| mDeco.setGridAnnotationDirection( QgsDecorationGrid::HorizontalAndVertical ); | ||
| } | ||
| else //BoundaryDirection | ||
| { | ||
| mDeco.setGridAnnotationDirection( QgsDecorationGrid::BoundaryDirection ); | ||
| } | ||
| mDeco.setGridAnnotationPrecision( mCoordinatePrecisionSpinBox->value() ); | ||
| if ( mLineSymbol ) | ||
| { | ||
| mDeco.setLineSymbol( mLineSymbol ); | ||
| mLineSymbol = dynamic_cast<QgsLineSymbolV2*>( mDeco.lineSymbol()->clone() ); | ||
| } | ||
| if ( mMarkerSymbol ) | ||
| { | ||
| mDeco.setMarkerSymbol( mMarkerSymbol ); | ||
| mMarkerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( mDeco.markerSymbol()->clone() ); | ||
| } | ||
| } | ||
|
|
||
| QgsDecorationGridDialog::~QgsDecorationGridDialog() | ||
| { | ||
| QSettings settings; | ||
| settings.setValue( "/Windows/DecorationGrid/geometry", saveGeometry() ); | ||
| if ( mLineSymbol ) | ||
| delete mLineSymbol; | ||
| if ( mMarkerSymbol ) | ||
| delete mMarkerSymbol; | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::on_buttonBox_helpRequested() | ||
| { | ||
| QgsContextHelp::run( metaObject()->className() ); | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::on_buttonBox_accepted() | ||
| { | ||
| updateDecoFromGui(); | ||
| // mDeco.update(); | ||
| accept(); | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::apply() | ||
| { | ||
| updateDecoFromGui(); | ||
| mDeco.update(); | ||
| //accept(); | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::on_buttonBox_rejected() | ||
| { | ||
| reject(); | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::on_mGridTypeComboBox_currentIndexChanged( int index ) | ||
| { | ||
| mLineSymbolButton->setEnabled( index == QgsDecorationGrid::Line ); | ||
| // mCrossWidthSpinBox->setEnabled( index == QgsDecorationGrid::Cross ); | ||
| mMarkerSymbolButton->setEnabled( index == QgsDecorationGrid::Marker ); | ||
| } | ||
|
|
||
|
|
||
| void QgsDecorationGridDialog::on_mLineSymbolButton_clicked() | ||
| { | ||
| if ( ! mLineSymbol ) | ||
| return; | ||
|
|
||
| QgsLineSymbolV2* lineSymbol = dynamic_cast<QgsLineSymbolV2*>( mLineSymbol->clone() ); | ||
| QgsSymbolV2PropertiesDialog dlg( lineSymbol, 0, this ); | ||
| if ( dlg.exec() == QDialog::Rejected ) | ||
| { | ||
| delete lineSymbol; | ||
| } | ||
| else | ||
| { | ||
| delete mLineSymbol; | ||
| mLineSymbol = lineSymbol; | ||
| if ( mLineSymbol ) | ||
| { | ||
| QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mLineSymbol, mLineSymbolButton->iconSize() ); | ||
| mLineSymbolButton->setIcon( icon ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::on_mMarkerSymbolButton_clicked() | ||
| { | ||
| if ( ! mMarkerSymbol ) | ||
| return; | ||
|
|
||
| QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( mMarkerSymbol->clone() ); | ||
| QgsSymbolV2PropertiesDialog dlg( markerSymbol, 0, this ); | ||
| if ( dlg.exec() == QDialog::Rejected ) | ||
| { | ||
| delete markerSymbol; | ||
| } | ||
| else | ||
| { | ||
| delete mMarkerSymbol; | ||
| mMarkerSymbol = markerSymbol; | ||
| if ( mMarkerSymbol ) | ||
| { | ||
| QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mMarkerSymbol, mMarkerSymbolButton->iconSize() ); | ||
| mMarkerSymbolButton->setIcon( icon ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::on_mPbtnUpdateFromExtents_clicked() | ||
| { | ||
| updateInterval( true ); | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::on_mPbtnUpdateFromLayer_clicked() | ||
| { | ||
| double values[4]; | ||
| if ( mDeco.getIntervalFromCurrentLayer( values ) ) | ||
| { | ||
| mIntervalXEdit->setText( QString::number( values[0] ) ); | ||
| mIntervalYEdit->setText( QString::number( values[1] ) ); | ||
| mOffsetXEdit->setText( QString::number( values[2] ) ); | ||
| mOffsetYEdit->setText( QString::number( values[3] ) ); | ||
| if ( values[0] >= 1 ) | ||
| mCoordinatePrecisionSpinBox->setValue( 0 ); | ||
| else | ||
| mCoordinatePrecisionSpinBox->setValue( 3 ); | ||
| } | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::on_mAnnotationFontButton_clicked() | ||
| { | ||
| bool ok; | ||
| #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA) | ||
| // Native Mac dialog works only for Qt Carbon | ||
| QFont newFont = QFontDialog::getFont( &ok, mDeco.gridAnnotationFont(), this, QString(), QFontDialog::DontUseNativeDialog ); | ||
| #else | ||
| QFont newFont = QFontDialog::getFont( &ok, mDeco.gridAnnotationFont() ); | ||
| #endif | ||
| if ( ok ) | ||
| { | ||
| mDeco.setGridAnnotationFont( newFont ); | ||
| } | ||
| } | ||
|
|
||
| void QgsDecorationGridDialog::updateInterval( bool force ) | ||
| { | ||
| if ( force || mDeco.isDirty() ) | ||
| { | ||
| double values[4]; | ||
| if ( mDeco.getIntervalFromExtent( values, true ) ) | ||
| { | ||
| mIntervalXEdit->setText( QString::number( values[0] ) ); | ||
| mIntervalYEdit->setText( QString::number( values[1] ) ); | ||
| mOffsetXEdit->setText( QString::number( values[2] ) ); | ||
| mOffsetYEdit->setText( QString::number( values[3] ) ); | ||
| // also update coord. precision | ||
| // if interval >= 1, set precision=0 because we have a rounded value | ||
| // else set it to previous default of 3 | ||
| if ( values[0] >= 1 ) | ||
| mCoordinatePrecisionSpinBox->setValue( 0 ); | ||
| else | ||
| mCoordinatePrecisionSpinBox->setValue( 3 ); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /*************************************************************************** | ||
| qgsdecorationgriddialog.h | ||
| ---------------------- | ||
| begin : May 10, 2012 | ||
| copyright : (C) 2012 by Etienne Tourigny | ||
| email : etourigny.dev at gmail dot com | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * 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 QGSDECORATIONGRIDDIALOG_H | ||
| #define QGSDECORATIONGRIDDIALOG_H | ||
|
|
||
| #include "ui_qgsdecorationgriddialog.h" | ||
| #include <QDialog> | ||
|
|
||
| class QgsDecorationGrid; | ||
| class QgsLineSymbolV2; | ||
| class QgsMarkerSymbolV2; | ||
|
|
||
| /** | ||
| @author Etienne Tourigny | ||
| */ | ||
| class QgsDecorationGridDialog : public QDialog, private Ui::QgsDecorationGridDialog | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| QgsDecorationGridDialog( QgsDecorationGrid& decoGrid, QWidget* parent = 0 ); | ||
| ~QgsDecorationGridDialog(); | ||
|
|
||
| private slots: | ||
| void apply(); | ||
| void on_buttonBox_accepted(); | ||
| void on_buttonBox_rejected(); | ||
| void on_buttonBox_helpRequested(); | ||
| void on_mGridTypeComboBox_currentIndexChanged( int index ); | ||
| void on_mLineSymbolButton_clicked(); | ||
| void on_mMarkerSymbolButton_clicked(); | ||
| void on_mPbtnUpdateFromExtents_clicked(); | ||
| void on_mPbtnUpdateFromLayer_clicked(); | ||
|
|
||
| // from composer map | ||
| /* void on_mLineColorButton_clicked(); */ | ||
| void on_mAnnotationFontButton_clicked(); | ||
|
|
||
| private: | ||
| QgsDecorationGrid& mDeco; | ||
| QgsLineSymbolV2* mLineSymbol; | ||
| QgsMarkerSymbolV2* mMarkerSymbol; | ||
|
|
||
| void updateGuiElements(); | ||
| void updateDecoFromGui(); | ||
| void updateInterval( bool force = false ); | ||
|
|
||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /*************************************************************************** | ||
| qgsdecorationitem.cpp | ||
| ---------------------- | ||
| begin : May 10, 2012 | ||
| copyright : (C) 2012 by Etienne Tourigny | ||
| email : etourigny.dev at gmail dot com | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * 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 "qgsdecorationitem.h" | ||
|
|
||
| #include "qgisapp.h" | ||
| #include "qgslogger.h" | ||
| #include "qgsmapcanvas.h" | ||
| #include "qgsmaplayer.h" | ||
| #include "qgsmaptopixel.h" | ||
| #include "qgspoint.h" | ||
| #include "qgsproject.h" | ||
| #include "qgssymbollayerv2utils.h" //for pointOnLineWithDistance | ||
|
|
||
| #include <QPainter> | ||
| #include <QAction> | ||
| #include <QPen> | ||
| #include <QPolygon> | ||
| #include <QString> | ||
| #include <QFontMetrics> | ||
| #include <QFont> | ||
| #include <QColor> | ||
| #include <QMenu> | ||
| #include <QFile> | ||
| #include <QLocale> | ||
|
|
||
| //non qt includes | ||
| #include <cmath> | ||
|
|
||
| QgsDecorationItem::QgsDecorationItem( QObject* parent ) | ||
| : QObject( parent ) | ||
| { | ||
| mEnabled = false; | ||
| } | ||
|
|
||
| QgsDecorationItem::~QgsDecorationItem() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| void QgsDecorationItem::update() | ||
| { | ||
| saveToProject(); | ||
| QgisApp::instance()->mapCanvas()->refresh(); | ||
| } | ||
|
|
||
| void QgsDecorationItem::projectRead() | ||
| { | ||
| QgsDebugMsg( "Entered" ); | ||
| mEnabled = QgsProject::instance()->readBoolEntry( mNameConfig, "/Enabled", false ); | ||
| } | ||
|
|
||
| void QgsDecorationItem::saveToProject() | ||
| { | ||
| QgsDebugMsg( "Entered" ); | ||
| QgsProject::instance()->writeEntry( mNameConfig, "/Enabled", mEnabled ); | ||
| } | ||
| void QgsDecorationItem::setName( const char *name ) | ||
| { | ||
| mName = name; | ||
| mNameConfig = name; | ||
| mNameConfig.remove( " " ); | ||
| mNameTranslated = tr( name ); | ||
| QgsDebugMsg( QString( "name=%1 nameconfig=%2 nametrans=%3").arg(mName).arg(mNameConfig).arg(mNameTranslated) ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /*************************************************************************** | ||
| qgsdecorationitem.h | ||
| ---------------------- | ||
| begin : May 10, 2012 | ||
| copyright : (C) 2012 by Etienne Tourigny | ||
| email : etourigny.dev at gmail dot com | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * 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 QGSDECORATIONITEM_H | ||
| #define QGSDECORATIONITEM_H | ||
|
|
||
| #include <QObject> | ||
| #include "qgslogger.h" | ||
|
|
||
| class QPainter; | ||
|
|
||
| class QgsDecorationItem: public QObject | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| //! Constructor | ||
| QgsDecorationItem( QObject* parent = NULL ); | ||
| //! Destructor | ||
| virtual ~ QgsDecorationItem(); | ||
|
|
||
| void setEnabled( bool enabled ) { mEnabled = enabled; } | ||
| bool enabled() const { return mEnabled; } | ||
|
|
||
| void update(); | ||
|
|
||
| signals: | ||
| void toggled( bool t ); | ||
|
|
||
| public slots: | ||
| //! set values on the gui when a project is read or the gui first loaded | ||
| virtual void projectRead(); | ||
| //! save values to the project | ||
| virtual void saveToProject(); | ||
|
|
||
| //! this does the meaty bit of the work | ||
| virtual void render( QPainter * ) {} | ||
| //! Show the dialog box | ||
| virtual void run() {} | ||
|
|
||
| virtual void setName( const char *name ); | ||
| virtual QString name() { return mName; } | ||
|
|
||
| protected: | ||
|
|
||
| /**True if decoration item has to be displayed*/ | ||
| bool mEnabled; | ||
|
|
||
| QString mName; | ||
| QString mNameConfig; | ||
| QString mNameTranslated; | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,322 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <ui version="4.0"> | ||
| <class>QgsDecorationGridDialog</class> | ||
| <widget class="QDialog" name="QgsDecorationGridDialog"> | ||
| <property name="geometry"> | ||
| <rect> | ||
| <x>0</x> | ||
| <y>0</y> | ||
| <width>603</width> | ||
| <height>335</height> | ||
| </rect> | ||
| </property> | ||
| <property name="windowTitle"> | ||
| <string>Dialog</string> | ||
| </property> | ||
| <layout class="QVBoxLayout" name="verticalLayout"> | ||
| <property name="sizeConstraint"> | ||
| <enum>QLayout::SetMinimumSize</enum> | ||
| </property> | ||
| <item> | ||
| <layout class="QGridLayout" name="gridLayout_3" columnstretch="0,0,0,0,0" columnminimumwidth="125,100,0,0,0"> | ||
| <item row="0" column="0"> | ||
| <widget class="QCheckBox" name="chkEnable"> | ||
| <property name="sizePolicy"> | ||
| <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> | ||
| <horstretch>0</horstretch> | ||
| <verstretch>0</verstretch> | ||
| </sizepolicy> | ||
| </property> | ||
| <property name="layoutDirection"> | ||
| <enum>Qt::LeftToRight</enum> | ||
| </property> | ||
| <property name="text"> | ||
| <string>Enable grid</string> | ||
| </property> | ||
| <property name="checked"> | ||
| <bool>true</bool> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="1" column="0"> | ||
| <widget class="QLabel" name="mIntervalXLabel"> | ||
| <property name="text"> | ||
| <string>Interval X</string> | ||
| </property> | ||
| <property name="wordWrap"> | ||
| <bool>true</bool> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="2" column="0"> | ||
| <widget class="QLabel" name="mIntervalYLabel"> | ||
| <property name="text"> | ||
| <string>Interval Y</string> | ||
| </property> | ||
| <property name="wordWrap"> | ||
| <bool>true</bool> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="3" column="0" colspan="2"> | ||
| <widget class="Line" name="line_2"> | ||
| <property name="orientation"> | ||
| <enum>Qt::Horizontal</enum> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="4" column="0"> | ||
| <widget class="QLabel" name="mGridTypeLabel"> | ||
| <property name="accessibleName"> | ||
| <string extracomment="Hello translotor"/> | ||
| </property> | ||
| <property name="text"> | ||
| <string>Grid type</string> | ||
| </property> | ||
| <property name="wordWrap"> | ||
| <bool>true</bool> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="5" column="0"> | ||
| <widget class="QLabel" name="mLineSymbolLabel"> | ||
| <property name="text"> | ||
| <string>Line symbol</string> | ||
| </property> | ||
| <property name="wordWrap"> | ||
| <bool>true</bool> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="4" column="1"> | ||
| <widget class="QComboBox" name="mGridTypeComboBox"> | ||
| <property name="sizePolicy"> | ||
| <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> | ||
| <horstretch>0</horstretch> | ||
| <verstretch>0</verstretch> | ||
| </sizepolicy> | ||
| </property> | ||
| <property name="minimumSize"> | ||
| <size> | ||
| <width>100</width> | ||
| <height>0</height> | ||
| </size> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="5" column="1"> | ||
| <widget class="QPushButton" name="mLineSymbolButton"> | ||
| <property name="enabled"> | ||
| <bool>false</bool> | ||
| </property> | ||
| <property name="sizePolicy"> | ||
| <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> | ||
| <horstretch>0</horstretch> | ||
| <verstretch>0</verstretch> | ||
| </sizepolicy> | ||
| </property> | ||
| <property name="minimumSize"> | ||
| <size> | ||
| <width>100</width> | ||
| <height>0</height> | ||
| </size> | ||
| </property> | ||
| <property name="text"> | ||
| <string/> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="1" column="2"> | ||
| <spacer name="horizontalSpacer"> | ||
| <property name="orientation"> | ||
| <enum>Qt::Horizontal</enum> | ||
| </property> | ||
| <property name="sizeType"> | ||
| <enum>QSizePolicy::Fixed</enum> | ||
| </property> | ||
| <property name="sizeHint" stdset="0"> | ||
| <size> | ||
| <width>10</width> | ||
| <height>20</height> | ||
| </size> | ||
| </property> | ||
| </spacer> | ||
| </item> | ||
| <item row="0" column="3" rowspan="8" colspan="2"> | ||
| <widget class="QGroupBox" name="mDrawAnnotationCheckBox"> | ||
| <property name="title"> | ||
| <string>Draw annotation</string> | ||
| </property> | ||
| <property name="flat"> | ||
| <bool>false</bool> | ||
| </property> | ||
| <property name="checkable"> | ||
| <bool>true</bool> | ||
| </property> | ||
| <property name="checked"> | ||
| <bool>false</bool> | ||
| </property> | ||
| <layout class="QGridLayout" name="gridLayout"> | ||
| <property name="sizeConstraint"> | ||
| <enum>QLayout::SetMinimumSize</enum> | ||
| </property> | ||
| <item row="0" column="0"> | ||
| <widget class="QLabel" name="mAnnotationDirectionLabel"> | ||
| <property name="frameShape"> | ||
| <enum>QFrame::NoFrame</enum> | ||
| </property> | ||
| <property name="text"> | ||
| <string>Annotation direction</string> | ||
| </property> | ||
| <property name="wordWrap"> | ||
| <bool>true</bool> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="0" column="1"> | ||
| <widget class="QComboBox" name="mAnnotationDirectionComboBox"/> | ||
| </item> | ||
| <item row="1" column="0" colspan="2"> | ||
| <widget class="QPushButton" name="mAnnotationFontButton"> | ||
| <property name="text"> | ||
| <string>Font...</string> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="2" column="0"> | ||
| <widget class="QLabel" name="mDistanceToFrameLabel"> | ||
| <property name="text"> | ||
| <string>Distance to map frame</string> | ||
| </property> | ||
| <property name="wordWrap"> | ||
| <bool>true</bool> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="2" column="1"> | ||
| <widget class="QDoubleSpinBox" name="mDistanceToMapFrameSpinBox"/> | ||
| </item> | ||
| <item row="3" column="0"> | ||
| <widget class="QLabel" name="mCoordinatePrecisionLabel"> | ||
| <property name="text"> | ||
| <string>Coordinate precision</string> | ||
| </property> | ||
| <property name="wordWrap"> | ||
| <bool>true</bool> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="3" column="1"> | ||
| <widget class="QSpinBox" name="mCoordinatePrecisionSpinBox"/> | ||
| </item> | ||
| </layout> | ||
| </widget> | ||
| </item> | ||
| <item row="6" column="0"> | ||
| <widget class="QLabel" name="mMarkerSymbolLabel"> | ||
| <property name="text"> | ||
| <string>Marker symbol</string> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="6" column="1"> | ||
| <widget class="QPushButton" name="mMarkerSymbolButton"> | ||
| <property name="enabled"> | ||
| <bool>false</bool> | ||
| </property> | ||
| <property name="sizePolicy"> | ||
| <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> | ||
| <horstretch>0</horstretch> | ||
| <verstretch>0</verstretch> | ||
| </sizepolicy> | ||
| </property> | ||
| <property name="minimumSize"> | ||
| <size> | ||
| <width>100</width> | ||
| <height>0</height> | ||
| </size> | ||
| </property> | ||
| <property name="text"> | ||
| <string/> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="7" column="0" colspan="2"> | ||
| <widget class="Line" name="line_3"> | ||
| <property name="orientation"> | ||
| <enum>Qt::Horizontal</enum> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="8" column="0"> | ||
| <widget class="QLabel" name="mOffsetXLabel"> | ||
| <property name="text"> | ||
| <string>Offset X</string> | ||
| </property> | ||
| <property name="wordWrap"> | ||
| <bool>true</bool> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="9" column="0"> | ||
| <widget class="QLabel" name="mOffsetYLabel"> | ||
| <property name="text"> | ||
| <string>Offset Y</string> | ||
| </property> | ||
| <property name="wordWrap"> | ||
| <bool>true</bool> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="8" column="3" rowspan="2" colspan="2"> | ||
| <widget class="QGroupBox" name="groupBox"> | ||
| <property name="title"> | ||
| <string>Update Interval / Offset from</string> | ||
| </property> | ||
| <layout class="QGridLayout" name="gridLayout_2"> | ||
| <item row="0" column="0"> | ||
| <widget class="QPushButton" name="mPbtnUpdateFromExtents"> | ||
| <property name="text"> | ||
| <string>Canvas Extents</string> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="0" column="1"> | ||
| <widget class="QPushButton" name="mPbtnUpdateFromLayer"> | ||
| <property name="text"> | ||
| <string>Active Raster Layer</string> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| </layout> | ||
| </widget> | ||
| </item> | ||
| <item row="1" column="1"> | ||
| <widget class="QLineEdit" name="mIntervalXEdit"/> | ||
| </item> | ||
| <item row="2" column="1"> | ||
| <widget class="QLineEdit" name="mIntervalYEdit"/> | ||
| </item> | ||
| <item row="8" column="1"> | ||
| <widget class="QLineEdit" name="mOffsetXEdit"/> | ||
| </item> | ||
| <item row="9" column="1"> | ||
| <widget class="QLineEdit" name="mOffsetYEdit"/> | ||
| </item> | ||
| </layout> | ||
| </item> | ||
| <item> | ||
| <widget class="QDialogButtonBox" name="buttonBox"> | ||
| <property name="orientation"> | ||
| <enum>Qt::Horizontal</enum> | ||
| </property> | ||
| <property name="standardButtons"> | ||
| <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| </layout> | ||
| </widget> | ||
| <resources/> | ||
| <connections/> | ||
| </ui> |