Skip to content
Permalink
Browse files

Add unit types to new item properties dialog, handle different reference

point settings
  • Loading branch information
nyalldawson committed Jul 18, 2017
1 parent 19a7863 commit de2626d65c59db9831f18d9532621d69d1544d8e
@@ -9,32 +9,66 @@



class QgsLayoutNewItemPropertiesDialog : QDialog
class QgsLayoutItemPropertiesDialog : QDialog
{
%Docstring
A dialog for configuring properties like the size and position of new layout items.
A dialog for configuring properties like the size and position of layout items.

This is usually used only when constructing new layout items, allowing users to precisely
enter their sizes and positions.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutnewitempropertiesdialog.h"
%End
public:

QgsLayoutNewItemPropertiesDialog( QWidget *parent = 0, Qt::WindowFlags flags = 0 );

QgsLayoutItemPropertiesDialog( QWidget *parent = 0, Qt::WindowFlags flags = 0 );
%Docstring
Constructor for QgsLayoutNewItemPropertiesDialog.
%End

void setInitialItemPosition( QPointF position );
void setItemPosition( QgsLayoutPoint position );
%Docstring
Sets the item ``position`` to show in the dialog.
.. seealso:: itemPosition()
%End

QgsLayoutPoint itemPosition() const;
%Docstring
Returns the current item position defined by the dialog.
.. seealso:: setItemPosition()
:rtype: QgsLayoutPoint
%End

void setItemSize( QgsLayoutSize size );
%Docstring
Sets the item ``size`` to show in the dialog.
.. seealso:: itemSize()
%End

QgsLayoutSize itemSize() const;
%Docstring
Returns the item size defined by the dialog.
.. seealso:: setItemSize()
:rtype: QgsLayoutSize
%End

QgsLayoutItem::ReferencePoint referencePoint() const;
%Docstring
Returns the item reference point defined by the dialog.
.. seealso:: setReferencePoint()
:rtype: QgsLayoutItem.ReferencePoint
%End

void setReferencePoint( QgsLayoutItem::ReferencePoint point );
%Docstring
Sets the item reference ``point`` defined to show in the dialog.
.. seealso:: referencePoint()
%End

};

/************************************************************************
@@ -16,29 +16,134 @@
#include "qgslayoutnewitempropertiesdialog.h"
#include "qgssettings.h"

QgsLayoutNewItemPropertiesDialog::QgsLayoutNewItemPropertiesDialog( QWidget *parent, Qt::WindowFlags flags )
QgsLayoutItemPropertiesDialog::QgsLayoutItemPropertiesDialog( QWidget *parent, Qt::WindowFlags flags )
: QDialog( parent, flags )
{
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 );

QgsSettings settings;
double lastWidth = settings.value( QStringLiteral( "LayoutDesigner/lastItemWidth" ), QStringLiteral( "50" ) ).toDouble();
double lastHeight = settings.value( QStringLiteral( "LayoutDesigner/lastItemHeight" ), QStringLiteral( "50" ) ).toDouble();
mWidthSpin->setValue( lastWidth );
mHeightSpin->setValue( lastHeight );
QgsUnitTypes::LayoutUnit lastSizeUnit = static_cast< QgsUnitTypes::LayoutUnit >( settings.value( QStringLiteral( "LayoutDesigner/lastSizeUnit" ) ).toInt() );
setItemSize( QgsLayoutSize( lastWidth, lastHeight, lastSizeUnit ) );
}

void QgsLayoutNewItemPropertiesDialog::setInitialItemPosition( QPointF position )
void QgsLayoutItemPropertiesDialog::setItemPosition( QgsLayoutPoint position )
{
mXPosSpin->setValue( position.x() );
mYPosSpin->setValue( position.y() );
mPosUnitsComboBox->setUnit( position.units() );
}

QgsLayoutPoint QgsLayoutItemPropertiesDialog::itemPosition() const
{
return QgsLayoutPoint( mXPosSpin->value(), mYPosSpin->value(), mPosUnitsComboBox->unit() );
}

QgsLayoutPoint QgsLayoutNewItemPropertiesDialog::itemPosition() const
void QgsLayoutItemPropertiesDialog::setItemSize( QgsLayoutSize size )
{
return QgsLayoutPoint( mXPosSpin->value(), mYPosSpin->value() );
mWidthSpin->setValue( size.width() );
mHeightSpin->setValue( size.height() );
mSizeUnitsComboBox->setUnit( size.units() );
}

QgsLayoutSize QgsLayoutNewItemPropertiesDialog::itemSize() const
QgsLayoutSize QgsLayoutItemPropertiesDialog::itemSize() const
{
return QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value() );
return QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
}

QgsLayoutItem::ReferencePoint QgsLayoutItemPropertiesDialog::referencePoint() const
{
if ( mUpperLeftCheckBox->checkState() == Qt::Checked )
{
return QgsLayoutItem::UpperLeft;
}
else if ( mUpperMiddleCheckBox->checkState() == Qt::Checked )
{
return QgsLayoutItem::UpperMiddle;
}
else if ( mUpperRightCheckBox->checkState() == Qt::Checked )
{
return QgsLayoutItem::UpperRight;
}
else if ( mMiddleLeftCheckBox->checkState() == Qt::Checked )
{
return QgsLayoutItem::MiddleLeft;
}
else if ( mMiddleCheckBox->checkState() == Qt::Checked )
{
return QgsLayoutItem::Middle;
}
else if ( mMiddleRightCheckBox->checkState() == Qt::Checked )
{
return QgsLayoutItem::MiddleRight;
}
else if ( mLowerLeftCheckBox->checkState() == Qt::Checked )
{
return QgsLayoutItem::LowerLeft;
}
else if ( mLowerMiddleCheckBox->checkState() == Qt::Checked )
{
return QgsLayoutItem::LowerMiddle;
}
else if ( mLowerRightCheckBox->checkState() == Qt::Checked )
{
return QgsLayoutItem::LowerRight;
}
return QgsLayoutItem::UpperLeft;
}

void QgsLayoutItemPropertiesDialog::setReferencePoint( QgsLayoutItem::ReferencePoint point )
{
switch ( point )
{
case QgsLayoutItem::UpperLeft:
mUpperLeftCheckBox->setChecked( true );
break;

case QgsLayoutItem::UpperMiddle:
mUpperMiddleCheckBox->setChecked( true );
break;

case QgsLayoutItem::UpperRight:
mUpperRightCheckBox->setChecked( true );
break;

case QgsLayoutItem::MiddleLeft:
mMiddleLeftCheckBox->setChecked( true );
break;

case QgsLayoutItem::Middle:
mMiddleCheckBox->setChecked( true );
break;

case QgsLayoutItem::MiddleRight:
mMiddleRightCheckBox->setChecked( true );
break;

case QgsLayoutItem::LowerLeft:
mLowerLeftCheckBox->setChecked( true );
break;

case QgsLayoutItem::LowerMiddle:
mLowerMiddleCheckBox->setChecked( true );
break;

case QgsLayoutItem::LowerRight:
mLowerRightCheckBox->setChecked( true );
break;
}
}
@@ -22,26 +22,64 @@

#include "qgslayoutsize.h"
#include "qgslayoutpoint.h"
#include "qgslayoutitem.h"

/**
* \ingroup gui
* \brief A dialog for configuring properties like the size and position of new layout items.
* \brief A dialog for configuring properties like the size and position of layout items.
*
* This is usually used only when constructing new layout items, allowing users to precisely
* enter their sizes and positions.
*
* \since QGIS 3.0
*/
class GUI_EXPORT QgsLayoutNewItemPropertiesDialog : public QDialog, private Ui::QgsLayoutNewItemPropertiesDialog
class GUI_EXPORT QgsLayoutItemPropertiesDialog : public QDialog, private Ui::QgsLayoutNewItemPropertiesDialog
{
Q_OBJECT

public:

QgsLayoutNewItemPropertiesDialog( QWidget *parent = nullptr, Qt::WindowFlags flags = 0 );
/**
* Constructor for QgsLayoutNewItemPropertiesDialog.
*/
QgsLayoutItemPropertiesDialog( QWidget *parent = nullptr, Qt::WindowFlags flags = 0 );

/**
* Sets the item \a position to show in the dialog.
* \see itemPosition()
*/
void setItemPosition( QgsLayoutPoint position );

void setInitialItemPosition( QPointF position );

/**
* Returns the current item position defined by the dialog.
* \see setItemPosition()
*/
QgsLayoutPoint itemPosition() const;

/**
* Sets the item \a size to show in the dialog.
* \see itemSize()
*/
void setItemSize( QgsLayoutSize size );

/**
* Returns the item size defined by the dialog.
* \see setItemSize()
*/
QgsLayoutSize itemSize() const;

/**
* Returns the item reference point defined by the dialog.
* \see setReferencePoint()
*/
QgsLayoutItem::ReferencePoint referencePoint() const;

/**
* Sets the item reference \a point defined to show in the dialog.
* \see referencePoint()
*/
void setReferencePoint( QgsLayoutItem::ReferencePoint point );

};

#endif // QGSLAYOUTNEWITEMPROPERTIESDIALOG_H
@@ -89,10 +89,11 @@ void QgsLayoutViewToolAddItem::layoutReleaseEvent( QgsLayoutViewMouseEvent *even
bool clickOnly = !isClickAndDrag( mMousePressStartPos, event->pos() );
if ( clickOnly )
{
QgsLayoutNewItemPropertiesDialog dlg( view() );
dlg.setInitialItemPosition( event->layoutPoint() );
QgsLayoutItemPropertiesDialog dlg( view() );
dlg.setItemPosition( QgsLayoutPoint( event->layoutPoint(), layout()->units() ) );
if ( dlg.exec() )
{
item->setReferencePoint( dlg.referencePoint() );
item->attemptResize( dlg.itemSize() );
item->attemptMove( dlg.itemPosition() );
}
@@ -112,7 +113,7 @@ void QgsLayoutViewToolAddItem::layoutReleaseEvent( QgsLayoutViewMouseEvent *even
QgsSettings settings;
settings.setValue( QStringLiteral( "LayoutDesigner/lastItemWidth" ), item->sizeWithUnits().width() );
settings.setValue( QStringLiteral( "LayoutDesigner/lastItemHeight" ), item->sizeWithUnits().height() );

settings.setValue( QStringLiteral( "LayoutDesigner/lastSizeUnit" ), static_cast< int >( item->sizeWithUnits().units() ) );

layout()->addItem( item );
}

0 comments on commit de2626d

Please sign in to comment.
You can’t perform that action at this time.