Skip to content

Commit

Permalink
Add minimum size option for diagrams. (Will be scaled if smaller)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 9, 2012
1 parent d81df7c commit bb8f1d6
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 42 deletions.
44 changes: 37 additions & 7 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,15 +846,24 @@ void QgsVectorLayerProperties::apply()
ds.sizeType = QgsDiagramSettings::MM;
}

if ( !tr( "Height" ).compare( mLabelPlacementComboBox->currentText() ) )
if ( tr( "Height" ) == mLabelPlacementComboBox->currentText() )
{
ds.labelPlacementMethod = QgsDiagramSettings::Height;
}
else if ( !tr( "x-height" ).compare( mLabelPlacementComboBox->currentText() ) )
else if ( tr( "x-height" ) == mLabelPlacementComboBox->currentText() )
{
ds.labelPlacementMethod = QgsDiagramSettings::XHeight;
}

if ( mIncreaseSmallDiagramsCheckBox->isChecked() )
{
ds.mMinimumSize = mIncreaseMinimumSizeSpinBox->value();
}
else
{
ds.mMinimumSize = 0;
}

ds.backgroundColor = mBackgroundColorButton->color();
ds.penColor = mDiagramPenColorButton->color();
ds.penWidth = mPenWidthSpinBox->value();
Expand Down Expand Up @@ -1329,6 +1338,20 @@ void QgsVectorLayerProperties::handleDiagramTypeChanged( const QString& itemtext
}
}

void QgsVectorLayerProperties::on_mIncreaseSmallDiagramsCheckBox_stateChanged( int state )
{
if ( Qt::Checked == state )
{
mIncreaseMinimumSizeLabel->setEnabled( true );
mIncreaseMinimumSizeSpinBox->setEnabled( true );
}
else
{
mIncreaseMinimumSizeLabel->setEnabled( false );
mIncreaseMinimumSizeSpinBox->setEnabled( false );
}
}

void QgsVectorLayerProperties::useNewSymbology()
{
int res = QMessageBox::question( this, tr( "Symbology" ),
Expand Down Expand Up @@ -1476,6 +1499,9 @@ void QgsVectorLayerProperties::on_mFixedSizeCheckBox_stateChanged( int state )

//enable / disable all widget in the scaling layout
mLinearlyScalingLabel->setEnabled( state != Qt::Checked );
mIncreaseSmallDiagramsCheckBox->setEnabled( state != Qt::Checked );
mIncreaseMinimumSizeLabel->setEnabled( state != Qt::Checked && mIncreaseSmallDiagramsCheckBox->isChecked() == Qt::Checked );
mIncreaseMinimumSizeSpinBox->setEnabled( state != Qt::Checked && mIncreaseSmallDiagramsCheckBox->isChecked() == Qt::Checked );
QWidget* currentWidget = 0;
for ( int i = 0; i < mLinearlyScalingLayout->count(); ++i )
{
Expand All @@ -1485,6 +1511,7 @@ void QgsVectorLayerProperties::on_mFixedSizeCheckBox_stateChanged( int state )
currentWidget->setEnabled( state != Qt::Checked );
}
}

}

void QgsVectorLayerProperties::on_mScaleDependentDiagramVisibilityCheckBox_stateChanged( int state )
Expand Down Expand Up @@ -1681,7 +1708,8 @@ void QgsVectorLayerProperties::initDiagramTab()
mLabelPlacementComboBox->setCurrentIndex( 1 );
}


mIncreaseSmallDiagramsCheckBox->setChecked( settingList.at( 0 ).mMinimumSize != 0 );
mIncreaseMinimumSizeSpinBox->setValue( settingList.at( 0 ).mMinimumSize );

QList< QColor > categoryColors = settingList.at( 0 ).categoryColors;
QList< int > categoryIndices = settingList.at( 0 ).categoryIndices;
Expand Down Expand Up @@ -1734,8 +1762,10 @@ void QgsVectorLayerProperties::initDiagramTab()
}

// Hide/Show diagram specific widgets
handleDiagramTypeChanged( mDiagramTypeComboBox->currentText() );

QObject::connect( mDiagramAttributesTreeWidget, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( handleDiagramItemDoubleClick( QTreeWidgetItem*, int ) ) );
QObject::connect( mDiagramTypeComboBox, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( handleDiagramTypeChanged( const QString& ) ) );
// handleDiagramTypeChanged( mDiagramTypeComboBox->currentText() );
// Enable / disable small diagram scaling related widgets
// on_mFixedSizeCheckBox_stateChanged( mIncreaseSmallDiagramsCheckBox->checkState() );
connect( mDiagramAttributesTreeWidget, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( handleDiagramItemDoubleClick( QTreeWidgetItem*, int ) ) );
connect( mDiagramTypeComboBox, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( handleDiagramTypeChanged( const QString& ) ) );
// connect( mIncreaseSmallDiagramsCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( handleIncreaseSmallDiagramsChanged( int ) ) );
}
3 changes: 3 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
void on_mBackgroundColorButton_clicked();
void on_mDiagramPenColorButton_clicked();
void on_pbnUpdateExtents_clicked();
void on_mIncreaseSmallDiagramsCheckBox_stateChanged( int state );

void enableLabelOptions( bool theFlag );
void addAttribute();
Expand All @@ -145,6 +146,8 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
/**Set color for diagram category*/
void handleDiagramItemDoubleClick( QTreeWidgetItem * item, int column );
void handleDiagramTypeChanged( const QString& itemtext );
/** The checkbox for small diagram scaling has been changed*/
// void handleIncreaseSmallDiagramsChanged( int state );

signals:

Expand Down
12 changes: 10 additions & 2 deletions src/core/qgsdiagramrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,16 @@ QSizeF QgsLinearlyInterpolatedDiagramRenderer::diagramSize( const QgsAttributeMa

//interpolate size
double ratio = ( value - mLowerValue ) / ( mUpperValue - mLowerValue );
return QSizeF( mUpperSize.width() * ratio + mLowerSize.width() * ( 1 - ratio ),
mUpperSize.height() * ratio + mLowerSize.height() * ( 1 - ratio ) );
QSizeF size = QSizeF( mUpperSize.width() * ratio + mLowerSize.width() * ( 1 - ratio ),
mUpperSize.height() * ratio + mLowerSize.height() * ( 1 - ratio ) );

// Scale, if extension is smaller than the specified minimum
if ( size.width() <= mSettings.mMinimumSize && size.height() <= mSettings.mMinimumSize )
{
size.scale( mSettings.mMinimumSize, mSettings.mMinimumSize, Qt::KeepAspectRatio );
}

return size;
}

void QgsLinearlyInterpolatedDiagramRenderer::readXML( const QDomElement& elem )
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsdiagramrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ struct CORE_EXPORT QgsDiagramSettings
double minScaleDenominator;
double maxScaleDenominator;

//! Scale diagrams smaller than mMinimumSize to mMinimumSize
double mMinimumSize;

void readXML( const QDomElement& elem );
void writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;
};
Expand Down
Loading

0 comments on commit bb8f1d6

Please sign in to comment.