Quantum GIS API Documentation
1.8
|
00001 /*************************************************************************** 00002 qgscomposition.h 00003 ------------------- 00004 begin : January 2005 00005 copyright : (C) 2005 by Radim Blazek 00006 email : [email protected] 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 #include "qgsaddremoveitemcommand.h" 00026 00027 class QgsComposerItem; 00028 class QgsComposerMap; 00029 class QgsPaperItem; 00030 class QGraphicsRectItem; 00031 class QgsMapRenderer; 00032 class QDomElement; 00033 class QgsComposerArrow; 00034 class QgsComposerItem; 00035 class QgsComposerLabel; 00036 class QgsComposerLegend; 00037 class QgsComposerMap; 00038 class QgsComposerPicture; 00039 class QgsComposerScaleBar; 00040 class QgsComposerShape; 00041 class QgsComposerAttributeTable; 00042 00049 class CORE_EXPORT QgsComposition: public QGraphicsScene 00050 { 00051 Q_OBJECT 00052 public: 00053 00055 enum PlotStyle 00056 { 00057 Preview = 0, // Use cache etc 00058 Print, // Render well 00059 Postscript // Fonts need different scaling! 00060 }; 00061 00063 enum GridStyle 00064 { 00065 Solid, 00066 Dots, 00067 Crosses 00068 }; 00069 00070 QgsComposition( QgsMapRenderer* mapRenderer ); 00071 ~QgsComposition(); 00072 00074 void setPaperSize( double width, double height ); 00075 00077 double paperHeight() const; 00078 00080 double paperWidth() const; 00081 00082 void setSnapToGridEnabled( bool b ); 00083 bool snapToGridEnabled() const {return mSnapToGrid;} 00084 00085 void setSnapGridResolution( double r ); 00086 double snapGridResolution() const {return mSnapGridResolution;} 00087 00088 void setSnapGridOffsetX( double offset ); 00089 double snapGridOffsetX() const {return mSnapGridOffsetX;} 00090 00091 void setSnapGridOffsetY( double offset ); 00092 double snapGridOffsetY() const {return mSnapGridOffsetY;} 00093 00094 void setGridPen( const QPen& p ); 00095 const QPen& gridPen() const {return mGridPen;} 00096 00097 void setGridStyle( GridStyle s ); 00098 GridStyle gridStyle() const {return mGridStyle;} 00099 00101 QUndoStack* undoStack() { return &mUndoStack; } 00102 00104 QgsComposerItem* composerItemAt( const QPointF & position ); 00105 00106 QList<QgsComposerItem*> selectedComposerItems(); 00107 00109 QList<const QgsComposerMap*> composerMapItems() const; 00110 00113 const QgsComposerMap* getComposerMapById( int id ) const; 00114 00115 int printResolution() const {return mPrintResolution;} 00116 void setPrintResolution( int dpi ) {mPrintResolution = dpi;} 00117 00118 bool printAsRaster() const {return mPrintAsRaster;} 00119 void setPrintAsRaster( bool enabled ) { mPrintAsRaster = enabled; } 00120 00121 double selectionTolerance() const { return mSelectionTolerance; } 00122 void setSelectionTolerance( double tol ); 00123 00125 QgsMapRenderer* mapRenderer() {return mMapRenderer;} 00126 00127 QgsComposition::PlotStyle plotStyle() const {return mPlotStyle;} 00128 void setPlotStyle( QgsComposition::PlotStyle style ) {mPlotStyle = style;} 00129 00133 int pixelFontSize( double pointSize ) const; 00134 00136 double pointFontSize( int pixelSize ) const; 00137 00139 bool writeXML( QDomElement& composerElem, QDomDocument& doc ); 00140 00142 bool readXML( const QDomElement& compositionElem, const QDomDocument& doc ); 00143 00150 void addItemsFromXML( const QDomElement& elem, const QDomDocument& doc, QMap< QgsComposerMap*, int >* mapsToRestore = 0, 00151 bool addUndoCommands = false, QPointF* pos = 0 ); 00152 00154 void addItemToZList( QgsComposerItem* item ); 00156 void removeItemFromZList( QgsComposerItem* item ); 00157 00158 //functions to move selected items in hierarchy 00159 void raiseSelectedItems(); 00160 void raiseItem( QgsComposerItem* item ); 00161 void lowerSelectedItems(); 00162 void lowerItem( QgsComposerItem* item ); 00163 void moveSelectedItemsToTop(); 00164 void moveItemToTop( QgsComposerItem* item ); 00165 void moveSelectedItemsToBottom(); 00166 void moveItemToBottom( QgsComposerItem* item ); 00167 00168 //functions to align selected items 00169 void alignSelectedItemsLeft(); 00170 void alignSelectedItemsHCenter(); 00171 void alignSelectedItemsRight(); 00172 void alignSelectedItemsTop(); 00173 void alignSelectedItemsVCenter(); 00174 void alignSelectedItemsBottom(); 00175 00178 void sortZList(); 00179 00181 QPointF snapPointToGrid( const QPointF& scenePoint ) const; 00182 00187 void beginCommand( QgsComposerItem* item, const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown ); 00188 00190 void endCommand(); 00192 void cancelCommand(); 00193 00195 void addComposerArrow( QgsComposerArrow* arrow ); 00197 void addComposerLabel( QgsComposerLabel* label ); 00199 void addComposerMap( QgsComposerMap* map, bool setDefaultPreviewStyle = true ); 00201 void addComposerScaleBar( QgsComposerScaleBar* scaleBar ); 00203 void addComposerLegend( QgsComposerLegend* legend ); 00205 void addComposerPicture( QgsComposerPicture* picture ); 00207 void addComposerShape( QgsComposerShape* shape ); 00209 void addComposerTable( QgsComposerAttributeTable* table ); 00210 00212 void removeComposerItem( QgsComposerItem* item ); 00213 00215 void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state = QgsAddRemoveItemCommand::Added ); 00216 00217 public slots: 00219 void sendItemAddedSignal( QgsComposerItem* item ); 00220 00221 private: 00223 QgsMapRenderer* mMapRenderer; 00224 QgsComposition::PlotStyle mPlotStyle; 00225 QgsPaperItem* mPaperItem; 00226 00228 QLinkedList<QgsComposerItem*> mItemZList; 00229 00231 int mPrintResolution; 00232 00234 bool mPrintAsRaster; 00235 00237 double mSelectionTolerance; 00238 00240 bool mSnapToGrid; 00241 double mSnapGridResolution; 00242 double mSnapGridOffsetX; 00243 double mSnapGridOffsetY; 00244 QPen mGridPen; 00245 GridStyle mGridStyle; 00246 00247 QUndoStack mUndoStack; 00248 00249 QgsComposerItemCommand* mActiveCommand; 00250 00251 QgsComposition(); //default constructor is forbidden 00252 00254 void updateZValues(); 00255 00258 int boundingRectOfSelectedItems( QRectF& bRect ); 00259 00260 void loadSettings(); 00261 void saveSettings(); 00262 00263 void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c ); 00264 00265 signals: 00266 void paperSizeChanged(); 00267 00269 void selectedItemChanged( QgsComposerItem* selected ); 00271 void composerArrowAdded( QgsComposerArrow* arrow ); 00273 void composerLabelAdded( QgsComposerLabel* label ); 00275 void composerMapAdded( QgsComposerMap* map ); 00277 void composerScaleBarAdded( QgsComposerScaleBar* scalebar ); 00279 void composerLegendAdded( QgsComposerLegend* legend ); 00281 void composerPictureAdded( QgsComposerPicture* picture ); 00283 void composerShapeAdded( QgsComposerShape* shape ); 00285 void composerTableAdded( QgsComposerAttributeTable* table ); 00287 void itemRemoved( QgsComposerItem* ); 00288 }; 00289 00290 #endif 00291 00292 00293