[QGIS Commit] r9543 - in branches/advanced_printing_branch2/src:
app app/composer core/composer ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Oct 25 07:09:28 EDT 2008
Author: mhugent
Date: 2008-10-25 07:09:28 -0400 (Sat, 25 Oct 2008)
New Revision: 9543
Added:
branches/advanced_printing_branch2/src/app/composer/qgsitempositiondialog.cpp
branches/advanced_printing_branch2/src/app/composer/qgsitempositiondialog.h
branches/advanced_printing_branch2/src/ui/qgsitempositiondialogbase.ui
Modified:
branches/advanced_printing_branch2/src/app/CMakeLists.txt
branches/advanced_printing_branch2/src/app/composer/qgscomposeritemwidget.cpp
branches/advanced_printing_branch2/src/app/composer/qgscomposeritemwidget.h
branches/advanced_printing_branch2/src/core/composer/qgscomposeritem.cpp
branches/advanced_printing_branch2/src/core/composer/qgscomposeritem.h
branches/advanced_printing_branch2/src/ui/qgscomposeritemwidgetbase.ui
Log:
First version that allows positioning item to given coordinates. The dialog needs some more work
Modified: branches/advanced_printing_branch2/src/app/CMakeLists.txt
===================================================================
--- branches/advanced_printing_branch2/src/app/CMakeLists.txt 2008-10-24 23:22:44 UTC (rev 9542)
+++ branches/advanced_printing_branch2/src/app/CMakeLists.txt 2008-10-25 11:09:28 UTC (rev 9543)
@@ -64,6 +64,7 @@
composer/qgscomposerlegenditemdialog.cpp
composer/qgscomposerlegendwidget.cpp
composer/qgscompositionwidget.cpp
+ composer/qgsitempositiondialog.cpp
legend/qgslegendgroup.cpp
legend/qgslegend.cpp
@@ -127,6 +128,7 @@
composer/qgscomposerpicturewidget.h
composer/qgscomposerscalebarwidget.h
composer/qgscompositionwidget.h
+ composer/qgsitempositiondialog.h
legend/qgslegend.h
legend/qgslegendlayer.h
Modified: branches/advanced_printing_branch2/src/app/composer/qgscomposeritemwidget.cpp
===================================================================
--- branches/advanced_printing_branch2/src/app/composer/qgscomposeritemwidget.cpp 2008-10-24 23:22:44 UTC (rev 9542)
+++ branches/advanced_printing_branch2/src/app/composer/qgscomposeritemwidget.cpp 2008-10-25 11:09:28 UTC (rev 9543)
@@ -17,6 +17,8 @@
#include "qgscomposeritemwidget.h"
#include "qgscomposeritem.h"
+#include "qgsitempositiondialog.h"
+#include "qgspoint.h"
#include <QColorDialog>
QgsComposerItemWidget::QgsComposerItemWidget( QWidget* parent, QgsComposerItem* item ): QWidget( parent ), mItem( item )
@@ -147,3 +149,23 @@
mFrameCheckBox->blockSignals( false );
}
+
+void QgsComposerItemWidget::on_mPositionButton_clicked()
+{
+ if(!mItem)
+ {
+ return;
+ }
+
+ QgsItemPositionDialog d(QRectF(mItem->transform().dx(), mItem->transform().dy(), mItem->rect().width(), mItem->rect().height()), 0);
+ if(d.exec() == QDialog::Accepted)
+ {
+ QgsPoint itemPosition;
+ if(d.position(itemPosition) == 0)
+ {
+ //query position and mode from dialog
+ mItem->setItemPosition(itemPosition.x(), itemPosition.y(), d.positionMode());
+ mItem->update();
+ }
+ }
+}
Modified: branches/advanced_printing_branch2/src/app/composer/qgscomposeritemwidget.h
===================================================================
--- branches/advanced_printing_branch2/src/app/composer/qgscomposeritemwidget.h 2008-10-24 23:22:44 UTC (rev 9542)
+++ branches/advanced_printing_branch2/src/app/composer/qgscomposeritemwidget.h 2008-10-25 11:09:28 UTC (rev 9543)
@@ -37,6 +37,7 @@
void on_mOpacitySlider_sliderReleased();
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_mFrameCheckBox_stateChanged( int state );
+ void on_mPositionButton_clicked();
private:
QgsComposerItemWidget();
Added: branches/advanced_printing_branch2/src/app/composer/qgsitempositiondialog.cpp
===================================================================
--- branches/advanced_printing_branch2/src/app/composer/qgsitempositiondialog.cpp (rev 0)
+++ branches/advanced_printing_branch2/src/app/composer/qgsitempositiondialog.cpp 2008-10-25 11:09:28 UTC (rev 9543)
@@ -0,0 +1,192 @@
+/***************************************************************************
+ qgsitempositiondialog.cpp
+ -------------------------
+ begin : October 2008
+ copyright : (C) 2008 by Marco Hugentobler
+ email : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 "qgsitempositiondialog.h"
+#include "qgspoint.h"
+#include <QButtonGroup>
+#include <QDoubleValidator>
+
+QgsItemPositionDialog::QgsItemPositionDialog(const QRectF& itemPosition, QWidget* parent): QDialog(parent), mItemPosition(itemPosition)
+{
+ setupUi(this);
+
+ //make button exclusive
+ QButtonGroup* buttonGroup = new QButtonGroup(this);
+ buttonGroup->addButton(mUpperLeftCheckBox);
+ buttonGroup->addButton(mUpperMiddleCheckBox);
+ buttonGroup->addButton(mUpperRightCheckBox);
+ buttonGroup->addButton(mMiddleLeftCheckBox);
+ buttonGroup->addButton(mMiddleCheckBox);
+ buttonGroup->addButton(mMiddleRightCheckBox);
+ buttonGroup->addButton(mLowerLeftCheckBox);
+ buttonGroup->addButton(mLowerMiddleCheckBox);
+ buttonGroup->addButton(mLowerRightCheckBox);
+ buttonGroup->setExclusive(true);
+
+ mXLineEdit->setValidator(new QDoubleValidator(0));
+ mYLineEdit->setValidator(new QDoubleValidator(0));
+
+ //set lower left position of item
+ mUpperLeftCheckBox->setCheckState(Qt::Checked);
+}
+
+QgsItemPositionDialog::QgsItemPositionDialog()
+{
+}
+
+QgsItemPositionDialog::~QgsItemPositionDialog()
+{
+
+}
+
+int QgsItemPositionDialog::position(QgsPoint& point) const
+{
+ bool convXSuccess, convYSuccess;
+ double x = mXLineEdit->text().toDouble(&convXSuccess);
+ double y = mYLineEdit->text().toDouble(&convYSuccess);
+
+ if(!convXSuccess || !convYSuccess)
+ {
+ return 1;
+ }
+
+ point.setX(x);
+ point.setY(y);
+ return 0;
+}
+
+QgsComposerItem::ItemPositionMode QgsItemPositionDialog::positionMode() const
+{
+ if(mUpperLeftCheckBox->checkState() == Qt::Checked)
+ {
+ return QgsComposerItem::UpperLeft;
+ }
+ else if(mUpperMiddleCheckBox->checkState() == Qt::Checked)
+ {
+ return QgsComposerItem::UpperMiddle;
+ }
+ else if(mUpperRightCheckBox->checkState() == Qt::Checked)
+ {
+ return QgsComposerItem::UpperRight;
+ }
+ else if(mMiddleLeftCheckBox->checkState() == Qt::Checked)
+ {
+ return QgsComposerItem::MiddleLeft;
+ }
+ else if(mMiddleCheckBox->checkState() == Qt::Checked)
+ {
+ return QgsComposerItem::Middle;
+ }
+ else if(mMiddleRightCheckBox->checkState() == Qt::Checked)
+ {
+ return QgsComposerItem::MiddleRight;
+ }
+ else if(mLowerLeftCheckBox->checkState() == Qt::Checked)
+ {
+ return QgsComposerItem::LowerLeft;
+ }
+ else if(mLowerMiddleCheckBox->checkState() == Qt::Checked)
+ {
+ return QgsComposerItem::LowerMiddle;
+ }
+ else if(mLowerRightCheckBox->checkState() == Qt::Checked)
+ {
+ return QgsComposerItem::LowerRight;
+ }
+ return QgsComposerItem::UpperLeft;
+}
+
+void QgsItemPositionDialog::on_mUpperLeftCheckBox_stateChanged(int state)
+{
+ if(state == Qt::Checked)
+ {
+ mXLineEdit->setText(QString::number(mItemPosition.left()));
+ mYLineEdit->setText(QString::number(mItemPosition.top()));
+ }
+}
+
+void QgsItemPositionDialog::on_mUpperMiddleCheckBox_stateChanged(int state)
+{
+ if(state == Qt::Checked)
+ {
+ mXLineEdit->setText(QString::number(mItemPosition.left() + mItemPosition.width() / 2.0));
+ mYLineEdit->setText(QString::number(mItemPosition.top()));
+ }
+}
+
+void QgsItemPositionDialog::on_mUpperRightCheckBox_stateChanged(int state)
+{
+ if(state == Qt::Checked)
+ {
+ mXLineEdit->setText(QString::number(mItemPosition.right()));
+ mYLineEdit->setText(QString::number(mItemPosition.top()));
+ }
+}
+
+void QgsItemPositionDialog::on_mMiddleLeftCheckBox_stateChanged(int state)
+{
+ if(state == Qt::Checked)
+ {
+ mXLineEdit->setText(QString::number(mItemPosition.left()));
+ mYLineEdit->setText(QString::number(mItemPosition.bottom() + mItemPosition.height() / 2.0));
+ }
+}
+
+void QgsItemPositionDialog::on_mMiddleCheckBox_stateChanged(int state)
+{
+ if(state == Qt::Checked)
+ {
+ mXLineEdit->setText(QString::number(mItemPosition.left() + mItemPosition.width() / 2.0));
+ mYLineEdit->setText(QString::number(mItemPosition.bottom() + mItemPosition.height() / 2.0));
+ }
+}
+
+void QgsItemPositionDialog::on_mMiddleRightCheckBox_stateChanged(int state)
+{
+ if(state == Qt::Checked)
+ {
+ mXLineEdit->setText(QString::number(mItemPosition.right()));
+ mYLineEdit->setText(QString::number(mItemPosition.bottom() + mItemPosition.height() / 2.0));
+ }
+}
+
+void QgsItemPositionDialog::on_mLowerLeftCheckBox_stateChanged(int state)
+{
+ if(state == Qt::Checked)
+ {
+ mXLineEdit->setText(QString::number(mItemPosition.left()));
+ mYLineEdit->setText(QString::number(mItemPosition.bottom()));
+ }
+}
+
+void QgsItemPositionDialog::on_mLowerMiddleCheckBox_stateChanged(int state)
+{
+ if(state == Qt::Checked)
+ {
+ mXLineEdit->setText(QString::number(mItemPosition.left() + mItemPosition.width() / 2.0));
+ mYLineEdit->setText(QString::number(mItemPosition.bottom()));
+ }
+}
+
+void QgsItemPositionDialog::on_mLowerRightCheckBox_stateChanged(int state)
+{
+ if(state == Qt::Checked)
+ {
+ //mXLineEdit->setText();
+ //mYLineEdit->setText();
+ }
+}
Added: branches/advanced_printing_branch2/src/app/composer/qgsitempositiondialog.h
===================================================================
--- branches/advanced_printing_branch2/src/app/composer/qgsitempositiondialog.h (rev 0)
+++ branches/advanced_printing_branch2/src/app/composer/qgsitempositiondialog.h 2008-10-25 11:09:28 UTC (rev 9543)
@@ -0,0 +1,57 @@
+/***************************************************************************
+ qgsitempositiondialog.h
+ -------------------------
+ begin : October 2008
+ copyright : (C) 2008 by Marco Hugentobler
+ email : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 QGSITEMPOSITIONDIALOG_H
+#define QGSITEMPOSITIONDIALOG_H
+
+#include "ui_qgsitempositiondialogbase.h"
+#include "qgscomposeritem.h"
+class QgsPoint;
+
+/**A dialog to set the position of upper/middle/lower left/middle/lower point of an item*/
+class QgsItemPositionDialog: public QDialog, private Ui::QgsItemPositionDialogBase
+{
+ Q_OBJECT
+ public:
+ QgsItemPositionDialog(const QRectF& itemPosition, QWidget* parent = 0);
+ ~QgsItemPositionDialog();
+
+ /**Get selected x- and y-coordinate as point. Returns 0 in case of success*/
+ int position(QgsPoint& point) const;
+ /**A combination of upper/middle/lower and left/middle/right*/
+ QgsComposerItem::ItemPositionMode positionMode() const;
+
+ public slots:
+ //adjust coordinates in line edits
+ void on_mUpperLeftCheckBox_stateChanged(int state);
+ void on_mUpperMiddleCheckBox_stateChanged(int state);
+ void on_mUpperRightCheckBox_stateChanged(int state);
+ void on_mMiddleLeftCheckBox_stateChanged(int state);
+ void on_mMiddleCheckBox_stateChanged(int state);
+ void on_mMiddleRightCheckBox_stateChanged(int state);
+ void on_mLowerLeftCheckBox_stateChanged(int state);
+ void on_mLowerMiddleCheckBox_stateChanged(int state);
+ void on_mLowerRightCheckBox_stateChanged(int state);
+
+ private:
+ QRectF mItemPosition;
+
+ //default constructor forbidden
+ QgsItemPositionDialog();
+};
+
+#endif
Modified: branches/advanced_printing_branch2/src/core/composer/qgscomposeritem.cpp
===================================================================
--- branches/advanced_printing_branch2/src/core/composer/qgscomposeritem.cpp 2008-10-24 23:22:44 UTC (rev 9542)
+++ branches/advanced_printing_branch2/src/core/composer/qgscomposeritem.cpp 2008-10-25 11:09:28 UTC (rev 9543)
@@ -497,6 +497,37 @@
setSceneRect( newSceneRect );
}
+void QgsComposerItem::setItemPosition(double x, double y, ItemPositionMode itemPoint)
+{
+ double width = rect().width();
+ double height = rect().height();
+
+ double upperLeftX = x;
+ double upperLeftY = y;
+
+ //adjust x-coordinate if placement is not done to a left point
+ if(itemPoint == UpperMiddle || itemPoint == Middle || itemPoint == LowerMiddle)
+ {
+ upperLeftX -= width / 2.0;
+ }
+ else if(itemPoint == UpperRight || itemPoint == MiddleRight || itemPoint == LowerRight)
+ {
+ upperLeftX -= width;
+ }
+
+ //adjust y-coordinate if placement is not done to an upper point
+ if(itemPoint == MiddleLeft || itemPoint == Middle || itemPoint == MiddleRight)
+ {
+ upperLeftY -= height / 2.0;
+ }
+ else if(itemPoint == LowerLeft || itemPoint == LowerMiddle || itemPoint == LowerRight)
+ {
+ upperLeftY -= height;
+ }
+
+ setSceneRect(QRectF(upperLeftX, upperLeftY, width, height));
+}
+
void QgsComposerItem::setSceneRect( const QRectF& rectangle )
{
//setRect in item coordinates
Modified: branches/advanced_printing_branch2/src/core/composer/qgscomposeritem.h
===================================================================
--- branches/advanced_printing_branch2/src/core/composer/qgscomposeritem.h 2008-10-24 23:22:44 UTC (rev 9542)
+++ branches/advanced_printing_branch2/src/core/composer/qgscomposeritem.h 2008-10-25 11:09:28 UTC (rev 9543)
@@ -48,6 +48,19 @@
resizeDRightDown
};
+ enum ItemPositionMode
+ {
+ UpperLeft,
+ UpperMiddle,
+ UpperRight,
+ MiddleLeft,
+ Middle,
+ MiddleRight,
+ LowerLeft,
+ LowerMiddle,
+ LowerRight
+ };
+
/**Constructor
@param manageZValue true if the z-Value of this object should be managed by mComposition*/
QgsComposerItem( QgsComposition* composition, bool manageZValue = true);
@@ -85,6 +98,9 @@
@param y y-position of mouse cursor (in item coordinates)*/
virtual void zoomContent( int delta, double x, double y) {}
+ /**Moves the item to a new position (in canvas coordinates)*/
+ void setItemPosition(double x, double y, ItemPositionMode itemPoint = UpperLeft);
+
/**Sets this items bound in scene coordinates such that 1 item size units
corresponds to 1 scene size unit*/
virtual void setSceneRect( const QRectF& rectangle );
Modified: branches/advanced_printing_branch2/src/ui/qgscomposeritemwidgetbase.ui
===================================================================
--- branches/advanced_printing_branch2/src/ui/qgscomposeritemwidgetbase.ui 2008-10-24 23:22:44 UTC (rev 9542)
+++ branches/advanced_printing_branch2/src/ui/qgscomposeritemwidgetbase.ui 2008-10-25 11:09:28 UTC (rev 9543)
@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>355</width>
- <height>203</height>
+ <width>347</width>
+ <height>207</height>
</rect>
</property>
<property name="windowTitle" >
@@ -68,6 +68,13 @@
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox" />
</item>
<item row="3" column="0" colspan="2" >
+ <widget class="QPushButton" name="mPositionButton" >
+ <property name="text" >
+ <string>Position...</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="3" >
<widget class="QCheckBox" name="mFrameCheckBox" >
<property name="text" >
<string>Frame</string>
Added: branches/advanced_printing_branch2/src/ui/qgsitempositiondialogbase.ui
===================================================================
--- branches/advanced_printing_branch2/src/ui/qgsitempositiondialogbase.ui (rev 0)
+++ branches/advanced_printing_branch2/src/ui/qgsitempositiondialogbase.ui 2008-10-25 11:09:28 UTC (rev 9543)
@@ -0,0 +1,172 @@
+<ui version="4.0" >
+ <class>QgsItemPositionDialogBase</class>
+ <widget class="QDialog" name="QgsItemPositionDialogBase" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>434</width>
+ <height>229</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Set item position</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QGroupBox" name="mPositionGroupBox" >
+ <property name="title" >
+ <string>Item Point</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QCheckBox" name="mUpperLeftCheckBox" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QCheckBox" name="mUpperMiddleCheckBox" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2" >
+ <widget class="QCheckBox" name="mUpperRightCheckBox" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QCheckBox" name="mMiddleLeftCheckBox" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QCheckBox" name="mMiddleCheckBox" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" >
+ <widget class="QCheckBox" name="mMiddleRightCheckBox" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QCheckBox" name="mLowerLeftCheckBox" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QCheckBox" name="mLowerMiddleCheckBox" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2" >
+ <widget class="QCheckBox" name="mLowerRightCheckBox" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QGroupBox" name="mCoordinatesGroupBox" >
+ <property name="title" >
+ <string>Coordinates</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <layout class="QHBoxLayout" >
+ <item>
+ <widget class="QLabel" name="mXLabel" >
+ <property name="text" >
+ <string>x:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="mXLineEdit" />
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0" >
+ <layout class="QHBoxLayout" >
+ <item>
+ <widget class="QLabel" name="mYLabel" >
+ <property name="text" >
+ <string>y:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="mYLineEdit" />
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2" >
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>QgsItemPositionDialogBase</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>QgsItemPositionDialogBase</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
More information about the QGIS-commit
mailing list