Skip to content
Permalink
Browse files

Implement logic to use radio buttons for diagram placement

  • Loading branch information
DelazJ authored and m-kuhn committed Sep 2, 2017
1 parent ea30377 commit e677e1f4ed0d734445cbc2e5a212ca9e3f125776
Showing with 75 additions and 42 deletions.
  1. +69 −16 src/app/qgsdiagramproperties.cpp
  2. +1 −3 src/app/qgsdiagramproperties.h
  3. +5 −23 src/ui/qgsdiagrampropertiesbase.ui
@@ -124,7 +124,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare

// set placement methods page based on geometry type

switch ( mLayer->geometryType() )
switch ( layerType )
{
case QgsWkbTypes::PointGeometry:
stackedPlacement->setCurrentWidget( pagePoint );
@@ -139,32 +139,31 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
mLinePlacementFrame->setVisible( false );
break;
case QgsWkbTypes::NullGeometry:
break;
case QgsWkbTypes::UnknownGeometry:
qFatal( "unknown geometry type unexpected" );
break;
}

//insert placement options
// setup point placement button group
mPlacePointBtnGrp = new QButtonGroup( this );
mPlacePointBtnGrp->addButton( radAroundPoint, ( int )QgsDiagramLayerSettings::AroundPoint );
mPlacePointBtnGrp->addButton( radOverPoint, ( int )QgsDiagramLayerSettings::OverPoint );
mPlacePointBtnGrp->addButton( radAroundPoint );
mPlacePointBtnGrp->addButton( radOverPoint );
mPlacePointBtnGrp->setExclusive( true );
connect( mPlacePointBtnGrp, static_cast<void ( QButtonGroup::* )( int )>( &QButtonGroup::buttonClicked ), this, &QgsDiagramProperties::updatePlacementWidgets );

// setup line placement button group (assigned enum id currently unused)
// setup line placement button group
mPlaceLineBtnGrp = new QButtonGroup( this );
mPlaceLineBtnGrp->addButton( radAroundLine, ( int )QgsDiagramLayerSettings::Line );
mPlaceLineBtnGrp->addButton( radOverLine, ( int )QgsDiagramLayerSettings::Horizontal );
mPlaceLineBtnGrp->addButton( radAroundLine );
mPlaceLineBtnGrp->addButton( radOverLine );
mPlaceLineBtnGrp->setExclusive( true );
connect( mPlaceLineBtnGrp, static_cast<void ( QButtonGroup::* )( int )>( &QButtonGroup::buttonClicked ), this, &QgsDiagramProperties::updatePlacementWidgets );

// setup polygon placement button group (assigned enum id currently unused)
// setup polygon placement button group
mPlacePolygonBtnGrp = new QButtonGroup( this );
mPlacePolygonBtnGrp->addButton( radAroundCentroid, ( int )QgsDiagramLayerSettings::AroundPoint );
mPlacePolygonBtnGrp->addButton( radOverCentroid, ( int )QgsDiagramLayerSettings::OverPoint );
mPlacePolygonBtnGrp->addButton( radPolygonPerimeter, ( int )QgsDiagramLayerSettings::Line );
mPlacePolygonBtnGrp->addButton( radInsidePolygon, ( int )QgsDiagramLayerSettings::Horizontal );
mPlacePolygonBtnGrp->addButton( radAroundCentroid );
mPlacePolygonBtnGrp->addButton( radOverCentroid );
mPlacePolygonBtnGrp->addButton( radPolygonPerimeter );
mPlacePolygonBtnGrp->addButton( radInsidePolygon );
mPlacePolygonBtnGrp->setExclusive( true );
connect( mPlacePolygonBtnGrp, static_cast<void ( QButtonGroup::* )( int )>( &QButtonGroup::buttonClicked ), this, &QgsDiagramProperties::updatePlacementWidgets );

@@ -242,16 +241,19 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
case QgsWkbTypes::PointGeometry:
radAroundPoint->setChecked( true );
break;

case QgsWkbTypes::LineGeometry:
radAroundLine->setChecked( true );
chkLineAbove->setChecked( true );
chkLineBelow->setChecked( false );
chkLineOn->setChecked( false );
chkLineOrientationDependent->setChecked( false );
break;

case QgsWkbTypes::PolygonGeometry:
radAroundCentroid->setChecked( true );
break;

case QgsWkbTypes::UnknownGeometry:
case QgsWkbTypes::NullGeometry:
break;
@@ -394,13 +396,39 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
mDiagramDistanceSpinBox->setValue( dls->distance() );
mPrioritySlider->setValue( dls->priority() );
mZIndexSpinBox->setValue( dls->zIndex() );
mPlacementComboBox->setCurrentIndex( mPlacementComboBox->findData( dls->placement() ) );

switch ( dls->placement() )
{
case QgsDiagramLayerSettings::AroundPoint:
radAroundPoint->setChecked( true );
radAroundCentroid->setChecked( true );
break;

case QgsDiagramLayerSettings::OverPoint:
radOverPoint->setChecked( true );
radOverCentroid->setChecked( true );
break;

case QgsDiagramLayerSettings::Line:
radAroundLine->setChecked( true );
radPolygonPerimeter->setChecked( true );
break;

case QgsDiagramLayerSettings::Horizontal:
radOverLine->setChecked( true );
radInsidePolygon->setChecked( true );
break;

default:
break;
}

chkLineAbove->setChecked( dls->linePlacementFlags() & QgsDiagramLayerSettings::AboveLine );
chkLineBelow->setChecked( dls->linePlacementFlags() & QgsDiagramLayerSettings::BelowLine );
chkLineOn->setChecked( dls->linePlacementFlags() & QgsDiagramLayerSettings::OnLine );
if ( !( dls->linePlacementFlags() & QgsDiagramLayerSettings::MapOrientation ) )
chkLineOrientationDependent->setChecked( true );
updatePlacementWidgets();

mShowAllCheckBox->setChecked( dls->showAllDiagrams() );

@@ -845,7 +873,32 @@ void QgsDiagramProperties::apply()
dls.setPriority( mPrioritySlider->value() );
dls.setZIndex( mZIndexSpinBox->value() );
dls.setShowAllDiagrams( mShowAllCheckBox->isChecked() );
//dls.setPlacement( ( QgsDiagramLayerSettings::Placement )mPlacementComboBox->currentData().toInt() );

QWidget *curWdgt = stackedPlacement->currentWidget();
if ( ( curWdgt == pagePoint && radAroundPoint->isChecked() )
|| ( curWdgt == pagePolygon && radAroundCentroid->isChecked() ) )
{
dls.setPlacement( QgsDiagramLayerSettings::AroundPoint );
}
else if ( ( curWdgt == pagePoint && radOverPoint->isChecked() )
|| ( curWdgt == pagePolygon && radOverCentroid->isChecked() ) )
{
dls.setPlacement( QgsDiagramLayerSettings::OverPoint );
}
else if ( ( curWdgt == pageLine && radAroundLine->isChecked() )
|| ( curWdgt == pagePolygon && radPolygonPerimeter->isChecked() ) )
{
dls.setPlacement( QgsDiagramLayerSettings::Line );
}
else if ( ( curWdgt == pageLine && radOverLine->isChecked() )
|| ( curWdgt == pagePolygon && radInsidePolygon->isChecked() ) )
{
dls.setPlacement( QgsDiagramLayerSettings::Horizontal );
}
else
{
qFatal( "Invalid settings" );
}

QgsDiagramLayerSettings::LinePlacementFlags flags = 0;
if ( chkLineAbove->isChecked() )
@@ -950,7 +1003,7 @@ void QgsDiagramProperties::updatePlacementWidgets()
mDistanceDDBtn->setEnabled( false );
}

bool linePlacementEnabled = mLayer->geometryType() == QgsWkbTypes::LineGeometry && ( curWdgt == pageLine && radAroundLine->isChecked() ); // && currentPlacement == QgsDiagramLayerSettings::Line;
bool linePlacementEnabled = mLayer->geometryType() == QgsWkbTypes::LineGeometry && ( curWdgt == pageLine && radAroundLine->isChecked() );
chkLineAbove->setEnabled( linePlacementEnabled );
chkLineBelow->setEnabled( linePlacementEnabled );
chkLineOn->setEnabled( linePlacementEnabled );
@@ -54,7 +54,7 @@ class APP_EXPORT QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPr
void scalingTypeChanged();
void showSizeLegendDialog();

protected:
private:

QgsVectorLayer *mLayer = nullptr;
//! Point placement button group
@@ -64,8 +64,6 @@ class APP_EXPORT QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPr
//! Polygon placement button group
QButtonGroup *mPlacePolygonBtnGrp = nullptr;

private:

enum Columns
{
ColumnAttributeExpression = 0,
@@ -1626,31 +1626,14 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="3" column="0">
<item row="2" column="0">
<widget class="QLabel" name="mDiagramDistanceLabel">
<property name="text">
<string>Distance</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mPlacementComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mPlacementLabel">
<property name="text">
<string>Placement</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QgsDoubleSpinBox" name="mDiagramDistanceSpinBox">
@@ -1677,7 +1660,7 @@
<item row="1" column="0">
<widget class="QStackedWidget" name="stackedPlacement">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -1927,8 +1910,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>106</width>
<height>161</height>
<width>642</width>
<height>421</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -2346,7 +2329,6 @@
<tabstop>scrollArea_2</tabstop>
<tabstop>mCheckBoxAttributeLegend</tabstop>
<tabstop>mButtonSizeLegendSettings</tabstop>
<tabstop>mPlacementComboBox</tabstop>
</tabstops>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit e677e1f

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