Skip to content
Permalink
Browse files

[diagrams] Usability improvements

 * Choose default attribute value for interpolation if none is set
 * Remember last used tab
 * Default for scale dependent visibility matches layer settings
  • Loading branch information
m-kuhn committed May 3, 2013
1 parent b4ba4c8 commit c7794ff1e3ee4c1e90cbbd27b0cf8283d8aa4f71
Showing with 53 additions and 17 deletions.
  1. +45 −14 src/app/qgsdiagramproperties.cpp
  2. +8 −3 src/ui/qgsdiagrampropertiesbase.ui
@@ -22,15 +22,17 @@
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsdiagramproperties.h"
#include "qgsdiagramrendererv2.h"
#include "qgslabelengineconfigdialog.h"
#include "qgsmessagebar.h"
#include "qgsvectorlayerproperties.h"
#include "qgsdiagramrendererv2.h"
#include "qgsvectordataprovider.h"

#include <QColorDialog>
#include <QFontDialog>
#include <QList>
#include <QMessageBox>
#include <QSettings>

QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* parent )
: QWidget( parent )
@@ -44,6 +46,10 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare

setupUi( this );

int tabIdx = QSettings().value( "/Windows/VectorLayerProperties/diagram/tab", 0 ).toInt();

mDiagramPropertiesTabWidget->setCurrentIndex( tabIdx );

mBackgroundColorButton->setColorDialogTitle( tr( "Background color" ) );
mBackgroundColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mDiagramPenColorButton->setColorDialogTitle( tr( "Pen color" ) );
@@ -142,7 +148,9 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mLabelPlacementComboBox->setCurrentIndex( mLabelPlacementComboBox->findText( tr( "x-height" ) ) );
mDiagramSizeSpinBox->setValue( 30 );
mBarWidthSpinBox->setValue( 5 );
mVisibilityGroupBox->setChecked( false );
mVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
mMaximumDiagramScaleLineEdit->setText( QString::number( layer->maximumScale() ) );
mMinimumDiagramScaleLineEdit->setText( QString::number( layer->minimumScale() ) );

switch ( layerType )
{
@@ -467,6 +475,9 @@ void QgsDiagramProperties::on_mEngineSettingsButton_clicked()

void QgsDiagramProperties::apply()
{
QSettings().setValue( "/Windows/VectorLayerProperties/diagram/tab",
mDiagramPropertiesTabWidget->currentIndex() );

if ( !mDisplayDiagramsGroupBox->isChecked() )
{
mLayer->setDiagramRenderer( 0 );
@@ -484,20 +495,40 @@ void QgsDiagramProperties::apply()
}

bool scaleAttributeValueOk = false;
if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
{
// We don't need a scale attribute, the field is used as a multiplicator
scaleAttributeValueOk = true;
}
else
{
// Check if a (usable) scale attribute value is inserted
mValueLineEdit->text().toDouble( &scaleAttributeValueOk );
}
// Check if a (usable) scale attribute value is inserted
mValueLineEdit->text().toDouble( &scaleAttributeValueOk );

if ( !mFixedSizeCheckBox->isChecked() && !scaleAttributeValueOk )
{
QMessageBox::warning( this, tr( "No attribute value specified" ),
tr( "You did not specify a maximum value for the diagram size. Please specify the attribute and a reference value as a base for scaling in the Tab Diagram / Size." ), QMessageBox::Ok );
double maxVal = DBL_MIN;
QgsVectorDataProvider* provider = mLayer->dataProvider();

if ( provider )
{
if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
{
// Find maximum value
for ( int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
{
maxVal = qMax( maxVal, provider->maximumValue( mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, Qt::UserRole ).toInt() ).toDouble() );
}
}
else
{
maxVal = provider->maximumValue( mSizeAttributeComboBox->itemData( mSizeAttributeComboBox->currentIndex() ).toInt() ).toDouble();
}
}

if ( maxVal != DBL_MIN )
{
QgisApp::instance()->messageBar()->pushMessage(
tr( "Interpolation value" ),
tr( "You did not specify an interpolation value. A default value of %1 has been set." ).arg( QString::number( maxVal ) ),
QgsMessageBar::INFO,
5 );

mValueLineEdit->setText( QString::number( maxVal ) );
}
}

if ( diagramType == DIAGRAM_NAME_TEXT )
@@ -40,7 +40,7 @@
<x>0</x>
<y>0</y>
<width>743</width>
<height>644</height>
<height>761</height>
</rect>
</property>
<layout class="QVBoxLayout" name="scrollAreaLayout">
@@ -120,7 +120,7 @@
<item>
<widget class="QTabWidget" name="mDiagramPropertiesTabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="mDiagramPropertiesTabWidgetPage1">
<attribute name="title">
@@ -426,7 +426,12 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="mValueLineEdit"/>
<widget class="QLineEdit" name="mValueLineEdit">
<property name="toolTip">
<string>The attribute value you enter here will correspond to the size entered in the field &quot;Size&quot; and the choosen &quot;Size unit&quot;.
Leave empty to automatically apply the maximum value.</string>
</property>
</widget>
</item>
</layout>
</widget>

0 comments on commit c7794ff

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