Skip to content

Commit

Permalink
[diagrams] Usability improvements
Browse files Browse the repository at this point in the history
 * 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 c7794ff
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
59 changes: 45 additions & 14 deletions src/app/qgsdiagramproperties.cpp
Expand Up @@ -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 )
Expand All @@ -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" ) );
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 );
Expand All @@ -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 )
Expand Down
11 changes: 8 additions & 3 deletions src/ui/qgsdiagrampropertiesbase.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit c7794ff

Please sign in to comment.