Skip to content

Commit 94264a9

Browse files
author
mhugent
committed
[FEATURE]: add capability to show and manipulate composer item with/ height in item position dialog
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14356 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6894cd0 commit 94264a9

File tree

6 files changed

+89
-30
lines changed

6 files changed

+89
-30
lines changed

python/core/qgscomposeritem.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ class QgsComposerItem: QObject, QGraphicsRectItem
7676
/**Moves the item to a new position (in canvas coordinates)*/
7777
void setItemPosition( double x, double y, ItemPositionMode itemPoint = UpperLeft );
7878

79+
/**Sets item position and width / height in one go
80+
@note: this method was added in version 1.6*/
81+
void setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint = UpperLeft );
82+
7983
/**Sets this items bound in scene coordinates such that 1 item size units
8084
corresponds to 1 scene size unit*/
8185
virtual void setSceneRect( const QRectF& rectangle );

src/app/composer/qgsitempositiondialog.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,18 @@ QgsItemPositionDialog::QgsItemPositionDialog( QgsComposerItem* item, QWidget* pa
3939

4040
mXLineEdit->setValidator( new QDoubleValidator( 0 ) );
4141
mYLineEdit->setValidator( new QDoubleValidator( 0 ) );
42+
mWidthLineEdit->setValidator( new QDoubleValidator( 0 ) );
43+
mHeightLineEdit->setValidator( new QDoubleValidator( 0 ) );
4244

4345
//set lower left position of item
4446
mUpperLeftCheckBox->setCheckState( Qt::Checked );
47+
48+
//set initial width and height
49+
if ( mItem )
50+
{
51+
mWidthLineEdit->setText( QString::number( mItem->rect().width() ) );
52+
mHeightLineEdit->setText( QString::number( mItem->rect().height() ) );
53+
}
4554
}
4655

4756
QgsItemPositionDialog::QgsItemPositionDialog(): mItem( 0 )
@@ -69,6 +78,22 @@ int QgsItemPositionDialog::position( QgsPoint& point ) const
6978
return 0;
7079
}
7180

81+
int QgsItemPositionDialog::size( QSizeF& s ) const
82+
{
83+
bool convSuccessWidth, convSuccessHeight;
84+
double width = mWidthLineEdit->text().toDouble( &convSuccessWidth );
85+
double height = mHeightLineEdit->text().toDouble( &convSuccessHeight );
86+
87+
if ( !convSuccessWidth || !convSuccessHeight )
88+
{
89+
return 1;
90+
}
91+
92+
s.setWidth( width );
93+
s.setHeight( height );
94+
return 0;
95+
}
96+
7297
QgsComposerItem::ItemPositionMode QgsItemPositionDialog::positionMode() const
7398
{
7499
if ( mUpperLeftCheckBox->checkState() == Qt::Checked )
@@ -123,10 +148,18 @@ void QgsItemPositionDialog::on_mSetPositionButton_clicked()
123148
}
124149

125150
QgsPoint itemPosition;
151+
QSizeF itemSize;
152+
126153
if ( position( itemPosition ) == 0 )
127154
{
128-
//query position and mode from dialog
129-
mItem->setItemPosition( itemPosition.x(), itemPosition.y(), positionMode() );
155+
if ( size( itemSize ) == 0 )
156+
{
157+
mItem->setItemPosition( itemPosition.x(), itemPosition.y(), itemSize.width(), itemSize.height(), positionMode() );
158+
}
159+
else
160+
{
161+
mItem->setItemPosition( itemPosition.x(), itemPosition.y(), positionMode() );
162+
}
130163
mItem->update();
131164
}
132165
}

src/app/composer/qgsitempositiondialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class QgsItemPositionDialog: public QDialog, private Ui::QgsItemPositionDialogBa
3232

3333
/**Get selected x- and y-coordinate as point. Returns 0 in case of success*/
3434
int position( QgsPoint& point ) const;
35+
/**Get selected size. Returns 0 in case of success*/
36+
int size( QSizeF& s ) const;
3537
/**A combination of upper/middle/lower and left/middle/right*/
3638
QgsComposerItem::ItemPositionMode positionMode() const;
3739

src/core/composer/qgscomposeritem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,11 @@ void QgsComposerItem::setItemPosition( double x, double y, ItemPositionMode item
630630
{
631631
double width = rect().width();
632632
double height = rect().height();
633+
setItemPosition( x, y, width, height, itemPoint );
634+
}
633635

636+
void QgsComposerItem::setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint )
637+
{
634638
double upperLeftX = x;
635639
double upperLeftY = y;
636640

src/core/composer/qgscomposeritem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
109109
/**Moves the item to a new position (in canvas coordinates)*/
110110
void setItemPosition( double x, double y, ItemPositionMode itemPoint = UpperLeft );
111111

112+
/**Sets item position and width / height in one go
113+
@note: this method was added in version 1.6*/
114+
void setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint = UpperLeft );
115+
112116
/**Sets this items bound in scene coordinates such that 1 item size units
113117
corresponds to 1 scene size unit*/
114118
virtual void setSceneRect( const QRectF& rectangle );

src/ui/qgsitempositiondialogbase.ui

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>434</width>
10-
<height>274</height>
9+
<width>334</width>
10+
<height>192</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Set item position</string>
1515
</property>
16-
<layout class="QGridLayout">
16+
<layout class="QGridLayout" name="gridLayout_2">
1717
<item row="0" column="0">
1818
<widget class="QGroupBox" name="mPositionGroupBox">
1919
<property name="title">
@@ -91,34 +91,46 @@
9191
<property name="title">
9292
<string>Coordinates</string>
9393
</property>
94-
<layout class="QGridLayout">
94+
<layout class="QGridLayout" name="gridLayout">
9595
<item row="0" column="0">
96-
<layout class="QHBoxLayout">
97-
<item>
98-
<widget class="QLabel" name="mXLabel">
99-
<property name="text">
100-
<string>x</string>
101-
</property>
102-
</widget>
103-
</item>
104-
<item>
105-
<widget class="QLineEdit" name="mXLineEdit"/>
106-
</item>
107-
</layout>
96+
<widget class="QLabel" name="mXLabel">
97+
<property name="text">
98+
<string>x</string>
99+
</property>
100+
</widget>
101+
</item>
102+
<item row="0" column="1" colspan="2">
103+
<widget class="QLineEdit" name="mXLineEdit"/>
108104
</item>
109105
<item row="1" column="0">
110-
<layout class="QHBoxLayout">
111-
<item>
112-
<widget class="QLabel" name="mYLabel">
113-
<property name="text">
114-
<string>y</string>
115-
</property>
116-
</widget>
117-
</item>
118-
<item>
119-
<widget class="QLineEdit" name="mYLineEdit"/>
120-
</item>
121-
</layout>
106+
<widget class="QLabel" name="mYLabel">
107+
<property name="text">
108+
<string>y</string>
109+
</property>
110+
</widget>
111+
</item>
112+
<item row="1" column="1" colspan="2">
113+
<widget class="QLineEdit" name="mYLineEdit"/>
114+
</item>
115+
<item row="2" column="0" colspan="2">
116+
<widget class="QLabel" name="mWidthLabel">
117+
<property name="text">
118+
<string>Width</string>
119+
</property>
120+
</widget>
121+
</item>
122+
<item row="2" column="2">
123+
<widget class="QLineEdit" name="mWidthLineEdit"/>
124+
</item>
125+
<item row="3" column="0" colspan="2">
126+
<widget class="QLabel" name="mHeightLabel">
127+
<property name="text">
128+
<string>Height</string>
129+
</property>
130+
</widget>
131+
</item>
132+
<item row="3" column="2">
133+
<widget class="QLineEdit" name="mHeightLineEdit"/>
122134
</item>
123135
</layout>
124136
</widget>

0 commit comments

Comments
 (0)