Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgscomposition.h 00003 ------------------- 00004 begin : January 2005 00005 copyright : (C) 2005 by Radim Blazek 00006 email : blazek@itc.it 00007 ***************************************************************************/ 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 #ifndef QGSCOMPOSITION_H 00017 #define QGSCOMPOSITION_H 00018 00019 #include <QDomDocument> 00020 #include <QGraphicsScene> 00021 #include <QLinkedList> 00022 #include <QUndoStack> 00023 00024 #include "qgscomposeritemcommand.h" 00025 00026 class QgsComposerItem; 00027 class QgsComposerMap; 00028 class QgsPaperItem; 00029 class QGraphicsRectItem; 00030 class QgsMapRenderer; 00031 00032 class QDomElement; 00033 00040 class CORE_EXPORT QgsComposition: public QGraphicsScene 00041 { 00042 Q_OBJECT 00043 public: 00044 00046 enum PlotStyle 00047 { 00048 Preview = 0, // Use cache etc 00049 Print, // Render well 00050 Postscript // Fonts need different scaling! 00051 }; 00052 00054 enum GridStyle 00055 { 00056 Solid, 00057 Dots, 00058 Crosses 00059 }; 00060 00061 QgsComposition( QgsMapRenderer* mapRenderer ); 00062 ~QgsComposition(); 00063 00065 void setPaperSize( double width, double height ); 00066 00068 double paperHeight() const; 00069 00071 double paperWidth() const; 00072 00073 void setSnapToGridEnabled( bool b ); 00074 bool snapToGridEnabled() const {return mSnapToGrid;} 00075 00076 void setSnapGridResolution( double r ); 00077 double snapGridResolution() const {return mSnapGridResolution;} 00078 00079 void setSnapGridOffsetX( double offset ); 00080 double snapGridOffsetX() const {return mSnapGridOffsetX;} 00081 00082 void setSnapGridOffsetY( double offset ); 00083 double snapGridOffsetY() const {return mSnapGridOffsetY;} 00084 00085 void setGridPen( const QPen& p ); 00086 const QPen& gridPen() const {return mGridPen;} 00087 00088 void setGridStyle( GridStyle s ); 00089 GridStyle gridStyle() const {return mGridStyle;} 00090 00092 QUndoStack* undoStack() { return &mUndoStack; } 00093 00095 QgsComposerItem* composerItemAt( const QPointF & position ); 00096 00097 QList<QgsComposerItem*> selectedComposerItems(); 00098 00100 QList<const QgsComposerMap*> composerMapItems() const; 00101 00104 const QgsComposerMap* getComposerMapById( int id ) const; 00105 00106 int printResolution() const {return mPrintResolution;} 00107 void setPrintResolution( int dpi ) {mPrintResolution = dpi;} 00108 00109 bool printAsRaster() const {return mPrintAsRaster;} 00110 void setPrintAsRaster( bool enabled ) { mPrintAsRaster = enabled; } 00111 00113 QgsMapRenderer* mapRenderer() {return mMapRenderer;} 00114 00115 QgsComposition::PlotStyle plotStyle() const {return mPlotStyle;} 00116 void setPlotStyle( QgsComposition::PlotStyle style ) {mPlotStyle = style;} 00117 00121 int pixelFontSize( double pointSize ) const; 00122 00124 double pointFontSize( int pixelSize ) const; 00125 00127 bool writeXML( QDomElement& composerElem, QDomDocument& doc ); 00128 00130 bool readXML( const QDomElement& compositionElem, const QDomDocument& doc ); 00131 00133 void addItemToZList( QgsComposerItem* item ); 00135 void removeItemFromZList( QgsComposerItem* item ); 00136 00137 //functions to move selected items in hierarchy 00138 void raiseSelectedItems(); 00139 void raiseItem( QgsComposerItem* item ); 00140 void lowerSelectedItems(); 00141 void lowerItem( QgsComposerItem* item ); 00142 void moveSelectedItemsToTop(); 00143 void moveItemToTop( QgsComposerItem* item ); 00144 void moveSelectedItemsToBottom(); 00145 void moveItemToBottom( QgsComposerItem* item ); 00146 00147 //functions to align selected items 00148 void alignSelectedItemsLeft(); 00149 void alignSelectedItemsHCenter(); 00150 void alignSelectedItemsRight(); 00151 void alignSelectedItemsTop(); 00152 void alignSelectedItemsVCenter(); 00153 void alignSelectedItemsBottom(); 00154 00157 void sortZList(); 00158 00160 QPointF snapPointToGrid( const QPointF& scenePoint ) const; 00161 00166 void beginCommand( QgsComposerItem* item, const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown ); 00167 00169 void endCommand(); 00171 void cancelCommand(); 00172 00173 00174 private: 00176 QgsMapRenderer* mMapRenderer; 00177 QgsComposition::PlotStyle mPlotStyle; 00178 QgsPaperItem* mPaperItem; 00179 00181 QLinkedList<QgsComposerItem*> mItemZList; 00182 00184 int mPrintResolution; 00185 00187 bool mPrintAsRaster; 00188 00190 bool mSnapToGrid; 00191 double mSnapGridResolution; 00192 double mSnapGridOffsetX; 00193 double mSnapGridOffsetY; 00194 QPen mGridPen; 00195 GridStyle mGridStyle; 00196 00197 QUndoStack mUndoStack; 00198 00199 QgsComposerItemCommand* mActiveCommand; 00200 00201 QgsComposition(); //default constructor is forbidden 00202 00204 void updateZValues(); 00205 00208 int boundingRectOfSelectedItems( QRectF& bRect ); 00209 00210 void loadGridAppearanceSettings(); 00211 void saveGridAppearanceSettings(); 00212 00213 signals: 00214 void paperSizeChanged(); 00215 }; 00216 00217 #endif 00218 00219 00220