Skip to content

Commit

Permalink
[FEATURE]: add capability to show and manipulate composer item with/ …
Browse files Browse the repository at this point in the history
…height in item position dialog

git-svn-id: http://svn.osgeo.org/qgis/trunk@14356 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Oct 8, 2010
1 parent 3b389a9 commit 286bf1a
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 30 deletions.
4 changes: 4 additions & 0 deletions python/core/qgscomposeritem.sip
Expand Up @@ -76,6 +76,10 @@ class QgsComposerItem: QObject, QGraphicsRectItem
/**Moves the item to a new position (in canvas coordinates)*/
void setItemPosition( double x, double y, ItemPositionMode itemPoint = UpperLeft );

/**Sets item position and width / height in one go
@note: this method was added in version 1.6*/
void setItemPosition( double x, double y, double width, double height, 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 );
Expand Down
37 changes: 35 additions & 2 deletions src/app/composer/qgsitempositiondialog.cpp
Expand Up @@ -39,9 +39,18 @@ QgsItemPositionDialog::QgsItemPositionDialog( QgsComposerItem* item, QWidget* pa

mXLineEdit->setValidator( new QDoubleValidator( 0 ) );
mYLineEdit->setValidator( new QDoubleValidator( 0 ) );
mWidthLineEdit->setValidator( new QDoubleValidator( 0 ) );
mHeightLineEdit->setValidator( new QDoubleValidator( 0 ) );

//set lower left position of item
mUpperLeftCheckBox->setCheckState( Qt::Checked );

//set initial width and height
if ( mItem )
{
mWidthLineEdit->setText( QString::number( mItem->rect().width() ) );
mHeightLineEdit->setText( QString::number( mItem->rect().height() ) );
}
}

QgsItemPositionDialog::QgsItemPositionDialog(): mItem( 0 )
Expand Down Expand Up @@ -69,6 +78,22 @@ int QgsItemPositionDialog::position( QgsPoint& point ) const
return 0;
}

int QgsItemPositionDialog::size( QSizeF& s ) const
{
bool convSuccessWidth, convSuccessHeight;
double width = mWidthLineEdit->text().toDouble( &convSuccessWidth );
double height = mHeightLineEdit->text().toDouble( &convSuccessHeight );

if ( !convSuccessWidth || !convSuccessHeight )
{
return 1;
}

s.setWidth( width );
s.setHeight( height );
return 0;
}

QgsComposerItem::ItemPositionMode QgsItemPositionDialog::positionMode() const
{
if ( mUpperLeftCheckBox->checkState() == Qt::Checked )
Expand Down Expand Up @@ -123,10 +148,18 @@ void QgsItemPositionDialog::on_mSetPositionButton_clicked()
}

QgsPoint itemPosition;
QSizeF itemSize;

if ( position( itemPosition ) == 0 )
{
//query position and mode from dialog
mItem->setItemPosition( itemPosition.x(), itemPosition.y(), positionMode() );
if ( size( itemSize ) == 0 )
{
mItem->setItemPosition( itemPosition.x(), itemPosition.y(), itemSize.width(), itemSize.height(), positionMode() );
}
else
{
mItem->setItemPosition( itemPosition.x(), itemPosition.y(), positionMode() );
}
mItem->update();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/composer/qgsitempositiondialog.h
Expand Up @@ -32,6 +32,8 @@ class QgsItemPositionDialog: public QDialog, private Ui::QgsItemPositionDialogBa

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

Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposeritem.cpp
Expand Up @@ -630,7 +630,11 @@ void QgsComposerItem::setItemPosition( double x, double y, ItemPositionMode item
{
double width = rect().width();
double height = rect().height();
setItemPosition( x, y, width, height, itemPoint );
}

void QgsComposerItem::setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint )
{
double upperLeftX = x;
double upperLeftY = y;

Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -109,6 +109,10 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
/**Moves the item to a new position (in canvas coordinates)*/
void setItemPosition( double x, double y, ItemPositionMode itemPoint = UpperLeft );

/**Sets item position and width / height in one go
@note: this method was added in version 1.6*/
void setItemPosition( double x, double y, double width, double height, 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 );
Expand Down
68 changes: 40 additions & 28 deletions src/ui/qgsitempositiondialogbase.ui
Expand Up @@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>274</height>
<width>334</width>
<height>192</height>
</rect>
</property>
<property name="windowTitle">
<string>Set item position</string>
</property>
<layout class="QGridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="mPositionGroupBox">
<property name="title">
Expand Down Expand Up @@ -91,34 +91,46 @@
<property name="title">
<string>Coordinates</string>
</property>
<layout class="QGridLayout">
<layout class="QGridLayout" name="gridLayout">
<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>
<widget class="QLabel" name="mXLabel">
<property name="text">
<string>x</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="mXLineEdit"/>
</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>
<widget class="QLabel" name="mYLabel">
<property name="text">
<string>y</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="mYLineEdit"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="mWidthLabel">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="mWidthLineEdit"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="mHeightLabel">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="mHeightLineEdit"/>
</item>
</layout>
</widget>
Expand Down

0 comments on commit 286bf1a

Please sign in to comment.