[QGIS Commit] r8573 - in branches/advanced_printing_branch/src:
app/composer ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Jun 1 08:14:52 EDT 2008
Author: mhugent
Date: 2008-06-01 08:14:52 -0400 (Sun, 01 Jun 2008)
New Revision: 8573
Modified:
branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.h
branches/advanced_printing_branch/src/ui/qgscomposermapwidgetbase.ui
Log:
further improvements for composer map
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp 2008-06-01 12:10:56 UTC (rev 8572)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp 2008-06-01 12:14:52 UTC (rev 8573)
@@ -47,7 +47,7 @@
// Cache
mCacheUpdated = false;
- mCalculate = Scale;
+ //mCalculate = Scale;
setPlotStyle ( QgsComposition::Preview );
mDrawing = false;
@@ -258,11 +258,12 @@
QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM((int)QGraphicsRectItem::rect().width()) );
QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM((int)QGraphicsRectItem::rect().height()) );
+ /*
if ( mCalculate == Scale ) {
QgsProject::instance()->writeEntry( "Compositions", path+"calculate", QString("scale") );
} else {
QgsProject::instance()->writeEntry( "Compositions", path+"calculate", QString("extent") );
- }
+ }*/
QgsProject::instance()->writeEntry( "Compositions", path+"frame", mFrame );
@@ -287,10 +288,10 @@
QString calculate = QgsProject::instance()->readEntry("Compositions", path+"calculate", "scale", &ok);
if ( calculate == "extent" )
{
- mCalculate = Extent;
+ //mCalculate = Extent;
}else
{
- mCalculate = Scale;
+ //mCalculate = Scale;
}
mFrame = QgsProject::instance()->readBoolEntry("Compositions", path+"frame", true, &ok);
@@ -322,7 +323,7 @@
//setRect
QRectF currentRect = rect();
QRectF newSceneRect = QRectF(transform().dx(), transform().dy(), currentRect.width() + dx, currentRect.height() + dy);
- setSceneRect(newSceneRect);
+ setSceneRect(newSceneRect);
}
void QgsComposerMap::setSceneRect(const QRectF& rectangle)
@@ -336,12 +337,24 @@
QGraphicsRectItem::update();
double newHeight = mExtent.width() * h / w ;
mExtent = QgsRect(mExtent.xMin(), mExtent.yMin(), mExtent.xMax(), mExtent.yMin() + newHeight);
+ mCacheUpdated = false;
emit extentChanged();
}
void QgsComposerMap::setNewExtent(const QgsRect& extent)
{
- //soon...
+ if(mExtent == extent)
+ {
+ return;
+ }
+ mExtent = extent;
+
+ //adjust height
+ QRectF currentRect = rect();
+
+ double newHeight = currentRect.width() * extent.height() / extent.width();
+
+ setSceneRect(QRectF(transform().dx(), transform().dy(), currentRect.width(), newHeight));
}
void QgsComposerMap::setNewScale(double scaleDenominator)
@@ -361,6 +374,7 @@
QgsRect newExtent(mExtent.xMin(), mExtent.yMin(), newXMax, newYMax);
mExtent = newExtent;
mCacheUpdated = false;
+ emit extentChanged();
update();
}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.h 2008-06-01 12:10:56 UTC (rev 8572)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.h 2008-06-01 12:14:52 UTC (rev 8573)
@@ -46,12 +46,6 @@
QgsComposerMap( QgsComposition *composition, int id );
~QgsComposerMap();
- /** \brief Calculate scale/extent. */
- enum Calculate {
- Scale = 0, // calculate scale from extent
- Extent // calculate map extent from scale
- };
-
/** \brief Preview style */
enum PreviewMode {
Cache = 0, // Use raster cache
@@ -83,9 +77,6 @@
/** \brief Create cache image */
void cache ( void );
-
- /** \brief Set values in GUI to current values */
- //void setOptions ( void );
/** \brief Map name, used in legend combobox etc. */
QString name ( void );
@@ -102,14 +93,19 @@
/**Sets new scale and changes only mExtent*/
void setNewScale(double scaleDenominator);
- Calculate calculationMode() {return mCalculate;}
+ /**Sets new Extent and changes width, height (and implicitely also scale)*/
+ void setNewExtent(const QgsRect& extent);
+
PreviewMode previewMode() {return mPreviewMode;}
void setPreviewMode(PreviewMode m) {mPreviewMode = m;}
- void setCalculationMode(Calculate c) {mCalculate = c;}
// Set cache outdated
void setCacheUpdated ( bool u = false );
+ QgsRect extent() const {return mExtent;}
+
+ const QgsMapCanvas* mapCanvas() const {return mMapCanvas;}
+
public slots:
// Called if map canvas has changed
@@ -144,9 +140,6 @@
// Is cache up to date
bool mCacheUpdated;
- // Resize schema
- Calculate mCalculate;
-
/** \brief Preview style */
PreviewMode mPreviewMode;
@@ -159,9 +152,6 @@
/**Store last scale factor to avoid unnecessary repaints in case preview mode is 'Render'*/
double mLastScaleFactorX;
- /**Sets new Extent and changes only width and height*/
- void setNewExtent(const QgsRect& extent);
-
/**Returns the zoom factor of the graphics view. If no
graphics view exists, the default 1 is returned*/
double horizontalViewScaleFactor() const;
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp 2008-06-01 12:10:56 UTC (rev 8572)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp 2008-06-01 12:14:52 UTC (rev 8573)
@@ -17,6 +17,7 @@
#include "qgscomposermapwidget.h"
#include "qgscomposermap.h"
+#include "qgsmapcanvas.h"
QgsComposerMapWidget::QgsComposerMapWidget(QgsComposerMap* composerMap): QWidget(), mComposerMap(composerMap)
{
@@ -25,8 +26,10 @@
mHeightLineEdit->setValidator(new QDoubleValidator(0));
mScaleLineEdit->setValidator(new QDoubleValidator(0));
- mCalculateComboBox->insertItem( 0, tr("Extent (calculate scale)"));
- mCalculateComboBox->insertItem( 1, tr("Scale (calculate extent)"));
+ mXMinLineEdit->setValidator(new QDoubleValidator(0));
+ mXMaxLineEdit->setValidator(new QDoubleValidator(0));
+ mYMinLineEdit->setValidator(new QDoubleValidator(0));
+ mYMaxLineEdit->setValidator(new QDoubleValidator(0));
mPreviewModeComboBox->insertItem(0, tr("Cache"));
mPreviewModeComboBox->insertItem(1, tr("Render"));
@@ -58,8 +61,10 @@
return;
}
QRectF composerMapRect = mComposerMap->rect();
- QRectF newRect(composerMapRect.x(), composerMapRect.y(), newWidth, composerMapRect.height());
- mComposerMap->setRect(newRect);
+ QTransform composerMapTransform = mComposerMap->transform();
+
+ QRectF newRect(composerMapTransform.dx(), composerMapTransform.dy(), newWidth, composerMapRect.height());
+ mComposerMap->setSceneRect(newRect);
}
}
@@ -74,8 +79,10 @@
return;
}
QRectF composerMapRect = mComposerMap->rect();
- QRectF newRect(composerMapRect.x(), composerMapRect.y(), composerMapRect.width(), newHeight);
- mComposerMap->setRect(newRect);
+ QTransform composerMapTransform = mComposerMap->transform();
+
+ QRectF newRect(composerMapTransform.dx(), composerMapTransform.dy(), composerMapRect.width(), newHeight);
+ mComposerMap->setSceneRect(newRect);
}
}
@@ -101,30 +108,6 @@
}
}
-void QgsComposerMapWidget::on_mCalculateComboBox_activated(int i)
-{
- if(!mComposerMap)
- {
- return;
- }
-
- QString comboText = mCalculateComboBox->currentText();
- if(comboText == tr("Extent (calculate scale)"))
- {
- mComposerMap->setCalculationMode(QgsComposerMap::Scale);
- mHeightLineEdit->setEnabled(true);
- mWidthLineEdit->setEnabled(true);
- mScaleLineEdit->setEnabled(false);
- }
- else if(comboText == tr("Scale (calculate extent)"))
- {
- mComposerMap->setCalculationMode(QgsComposerMap::Extent);
- mHeightLineEdit->setEnabled(false);
- mWidthLineEdit->setEnabled(false);
- mScaleLineEdit->setEnabled(true);
- }
-}
-
void QgsComposerMapWidget::on_mFrameCheckBox_stateChanged(int state)
{
if(!mComposerMap)
@@ -169,12 +152,51 @@
mComposerMap->setNewScale(scaleDenominator);
}
+void QgsComposerMapWidget::on_mSetToMapCanvasExtentButton_clicked()
+{
+ if(mComposerMap)
+ {
+ const QgsMapCanvas* canvas = mComposerMap->mapCanvas();
+ if(canvas)
+ {
+ QgsRect canvasExtent = canvas->extent();
+
+ //fill text into line edits
+ mXMinLineEdit->setText(QString::number(canvasExtent.xMin()));
+ mXMaxLineEdit->setText(QString::number(canvasExtent.xMax()));
+ mYMinLineEdit->setText(QString::number(canvasExtent.yMin()));
+ mYMaxLineEdit->setText(QString::number(canvasExtent.yMax()));
+
+ mComposerMap->setNewExtent(canvasExtent);
+ }
+ }
+}
+
+void QgsComposerMapWidget::on_mXMinLineEdit_editingFinished()
+{
+ updateComposerExtentFromGui();
+}
+
+void QgsComposerMapWidget::on_mXMaxLineEdit_editingFinished()
+{
+ updateComposerExtentFromGui();
+}
+
+void QgsComposerMapWidget::on_mYMinLineEdit_editingFinished()
+{
+ updateComposerExtentFromGui();
+}
+
+void QgsComposerMapWidget::on_mYMaxLineEdit_editingFinished()
+{
+ updateComposerExtentFromGui();
+}
+
void QgsComposerMapWidget::updateSettingsNoSignals()
{
mHeightLineEdit->blockSignals(true);
mWidthLineEdit->blockSignals(true);
mScaleLineEdit->blockSignals(true);
- mCalculateComboBox->blockSignals(true);
mPreviewModeComboBox->blockSignals(true);
updateGuiElements();
@@ -182,7 +204,6 @@
mHeightLineEdit->blockSignals(false);
mWidthLineEdit->blockSignals(false);
mScaleLineEdit->blockSignals(false);
- mCalculateComboBox->blockSignals(false);
mPreviewModeComboBox->blockSignals(false);
}
@@ -196,31 +217,9 @@
mHeightLineEdit->setText(QString::number(composerMapRect.height()));
mScaleLineEdit->setText(QString::number(mComposerMap->scale()));
- //calculation mode
- QgsComposerMap::Calculate calculationMode = mComposerMap->calculationMode();
- int index = -1;
- if(calculationMode == QgsComposerMap::Scale)
- {
- index = mCalculateComboBox->findText(tr("Extent (calculate scale)"));
- mHeightLineEdit->setEnabled(true);
- mWidthLineEdit->setEnabled(true);
- mScaleLineEdit->setEnabled(false);
- }
- else if(calculationMode == QgsComposerMap::Extent)
- {
- index = mCalculateComboBox->findText(tr("Scale (calculate extent)"));
- mHeightLineEdit->setEnabled(true);
- mWidthLineEdit->setEnabled(true);
- mScaleLineEdit->setEnabled(false);
- }
- if(index != -1)
- {
- mCalculateComboBox->setCurrentIndex(index);
- }
-
//preview mode
QgsComposerMap::PreviewMode previewMode = mComposerMap->previewMode();
- index = -1;
+ int index = -1;
if(previewMode == QgsComposerMap::Cache)
{
index = mPreviewModeComboBox->findText(tr("Cache"));
@@ -237,7 +236,37 @@
{
mPreviewModeComboBox->setCurrentIndex(index);
}
+
+ //composer map extent
+ QgsRect composerMapExtent = mComposerMap->extent();
+ mXMinLineEdit->setText(QString::number(composerMapExtent.xMin()));
+ mXMaxLineEdit->setText(QString::number(composerMapExtent.xMax()));
+ mYMinLineEdit->setText(QString::number(composerMapExtent.yMin()));
+ mYMaxLineEdit->setText(QString::number(composerMapExtent.yMax()));
}
}
+void QgsComposerMapWidget::updateComposerExtentFromGui()
+{
+ if(!mComposerMap)
+ {
+ return;
+ }
+ double xmin, ymin, xmax, ymax;
+ bool conversionSuccess;
+
+ xmin = mXMinLineEdit->text().toDouble(&conversionSuccess);
+ if(!conversionSuccess){return;}
+ xmax = mXMaxLineEdit->text().toDouble(&conversionSuccess);
+ if(!conversionSuccess){return;}
+ ymin = mYMinLineEdit->text().toDouble(&conversionSuccess);
+ if(!conversionSuccess){return;}
+ ymax = mYMaxLineEdit->text().toDouble(&conversionSuccess);
+ if(!conversionSuccess){return;}
+
+ QgsRect newExtent(xmin, ymin, xmax, ymax);
+ mComposerMap->setNewExtent(newExtent);
+}
+
+
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.h 2008-06-01 12:10:56 UTC (rev 8572)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.h 2008-06-01 12:14:52 UTC (rev 8573)
@@ -36,10 +36,15 @@
void on_mWidthLineEdit_editingFinished();
void on_mHeightLineEdit_editingFinished();
void on_mPreviewModeComboBox_activated(int i);
- void on_mCalculateComboBox_activated(int i);
void on_mFrameCheckBox_stateChanged(int state);
void on_mScaleLineEdit_editingFinished();
+ void on_mSetToMapCanvasExtentButton_clicked();
+ void on_mXMinLineEdit_editingFinished();
+ void on_mXMaxLineEdit_editingFinished();
+ void on_mYMinLineEdit_editingFinished();
+ void on_mYMaxLineEdit_editingFinished();
+
/**Updates width and height without notify the composer map (to avoid infinite recursion)*/
void updateSettingsNoSignals();
@@ -48,6 +53,9 @@
/**Sets the current composer map values to the GUI elements*/
void updateGuiElements();
+
+ /**Sets extent of composer map from line edits*/
+ void updateComposerExtentFromGui();
};
#endif
Modified: branches/advanced_printing_branch/src/ui/qgscomposermapwidgetbase.ui
===================================================================
--- branches/advanced_printing_branch/src/ui/qgscomposermapwidgetbase.ui 2008-06-01 12:10:56 UTC (rev 8572)
+++ branches/advanced_printing_branch/src/ui/qgscomposermapwidgetbase.ui 2008-06-01 12:14:52 UTC (rev 8573)
@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>486</width>
- <height>347</height>
+ <width>546</width>
+ <height>488</height>
</rect>
</property>
<property name="sizePolicy" >
@@ -19,14 +19,14 @@
<string>Map options</string>
</property>
<layout class="QGridLayout" >
- <item row="0" column="0" colspan="4" >
+ <item row="0" column="0" colspan="3" >
<widget class="QLabel" name="mNameLabel" >
<property name="text" >
<string><b>Map</b></string>
</property>
</widget>
</item>
- <item row="1" column="0" colspan="4" >
+ <item row="1" column="0" colspan="3" >
<widget class="Line" name="line1" >
<property name="frameShape" >
<enum>QFrame::HLine</enum>
@@ -40,38 +40,6 @@
</widget>
</item>
<item row="2" column="0" >
- <widget class="QLabel" name="textLabel1_3" >
- <property name="text" >
- <string>Set</string>
- </property>
- <property name="wordWrap" >
- <bool>true</bool>
- </property>
- <property name="buddy" >
- <cstring>mCalculateComboBox</cstring>
- </property>
- </widget>
- </item>
- <item row="2" column="3" >
- <widget class="QComboBox" name="mCalculateComboBox" >
- <property name="enabled" >
- <bool>true</bool>
- </property>
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize" >
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- </widget>
- </item>
- <item row="3" column="0" >
<widget class="QLabel" name="textLabel1" >
<property name="text" >
<string>Width</string>
@@ -84,10 +52,10 @@
</property>
</widget>
</item>
- <item row="3" column="3" >
+ <item row="2" column="2" >
<widget class="QLineEdit" name="mWidthLineEdit" />
</item>
- <item row="4" column="0" >
+ <item row="3" column="0" >
<widget class="QLabel" name="textLabel2" >
<property name="text" >
<string>Height</string>
@@ -100,10 +68,10 @@
</property>
</widget>
</item>
- <item row="4" column="3" >
+ <item row="3" column="2" >
<widget class="QLineEdit" name="mHeightLineEdit" />
</item>
- <item row="5" column="0" >
+ <item row="4" column="0" >
<widget class="QLabel" name="label_2" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
@@ -119,7 +87,7 @@
</property>
</widget>
</item>
- <item row="5" column="1" >
+ <item row="4" column="1" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>1:</string>
@@ -129,46 +97,108 @@
</property>
</widget>
</item>
- <item row="5" column="3" >
+ <item row="4" column="2" >
<widget class="QLineEdit" name="mScaleLineEdit" />
</item>
- <item row="6" column="0" colspan="2" >
- <widget class="QLabel" name="label_3" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
+ <item row="5" column="0" colspan="3" >
+ <widget class="QGroupBox" name="mMapExtentGroupBox" >
+ <property name="title" >
+ <string>Map extent</string>
</property>
- <property name="text" >
- <string/>
- </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <layout class="QVBoxLayout" >
+ <item>
+ <widget class="QLabel" name="mXMinLabel" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
+ <property name="text" >
+ <string>X min:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="mYMinLabel" >
+ <property name="text" >
+ <string>Y min:</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="0" column="1" colspan="2" >
+ <layout class="QVBoxLayout" >
+ <item>
+ <widget class="QLineEdit" name="mXMinLineEdit" />
+ </item>
+ <item>
+ <widget class="QLineEdit" name="mYMinLineEdit" />
+ </item>
+ </layout>
+ </item>
+ <item row="0" column="3" >
+ <layout class="QVBoxLayout" >
+ <item>
+ <widget class="QLabel" name="mXMaxLabel" >
+ <property name="text" >
+ <string>X max:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="mYMaxLabel" >
+ <property name="windowModality" >
+ <enum>Qt::NonModal</enum>
+ </property>
+ <property name="text" >
+ <string>Y max:</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="0" column="4" >
+ <layout class="QVBoxLayout" >
+ <item>
+ <widget class="QLineEdit" name="mXMaxLineEdit" />
+ </item>
+ <item>
+ <widget class="QLineEdit" name="mYMaxLineEdit" />
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0" colspan="2" >
+ <widget class="QPushButton" name="mSetToMapCanvasExtentButton" >
+ <property name="text" >
+ <string>set to map canvas extent</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" colspan="3" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>311</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
</widget>
</item>
- <item row="6" column="3" >
- <widget class="QPushButton" name="mSetCurrentExtentButton" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="toolTip" >
- <string>Set map extent to current extent in QGIS map canvas</string>
- </property>
- <property name="text" >
- <string>Set Extent</string>
- </property>
- </widget>
- </item>
- <item row="7" column="0" colspan="4" >
+ <item row="6" column="0" colspan="3" >
<widget class="QCheckBox" name="mFrameCheckBox" >
<property name="text" >
<string>Frame</string>
</property>
</widget>
</item>
- <item row="8" column="0" colspan="2" >
+ <item row="7" column="0" colspan="2" >
<widget class="QLabel" name="textLabel1_5" >
<property name="text" >
<string>Preview</string>
@@ -181,7 +211,7 @@
</property>
</widget>
</item>
- <item row="8" column="2" colspan="2" >
+ <item row="7" column="2" >
<widget class="QComboBox" name="mPreviewModeComboBox" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
@@ -191,15 +221,15 @@
</property>
</widget>
</item>
- <item row="9" column="2" colspan="2" >
+ <item row="8" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
- <width>20</width>
- <height>40</height>
+ <width>402</width>
+ <height>31</height>
</size>
</property>
</spacer>
@@ -208,10 +238,8 @@
</widget>
<layoutdefault spacing="6" margin="11" />
<tabstops>
- <tabstop>mCalculateComboBox</tabstop>
<tabstop>mWidthLineEdit</tabstop>
<tabstop>mHeightLineEdit</tabstop>
- <tabstop>mSetCurrentExtentButton</tabstop>
<tabstop>mFrameCheckBox</tabstop>
<tabstop>mPreviewModeComboBox</tabstop>
</tabstops>
More information about the QGIS-commit
mailing list