Skip to content

Commit c7794ff

Browse files
committedMay 3, 2013
[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
1 parent b4ba4c8 commit c7794ff

File tree

2 files changed

+53
-17
lines changed

2 files changed

+53
-17
lines changed
 

‎src/app/qgsdiagramproperties.cpp

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@
2222
#include "qgisapp.h"
2323
#include "qgsapplication.h"
2424
#include "qgsdiagramproperties.h"
25+
#include "qgsdiagramrendererv2.h"
2526
#include "qgslabelengineconfigdialog.h"
27+
#include "qgsmessagebar.h"
2628
#include "qgsvectorlayerproperties.h"
27-
#include "qgsdiagramrendererv2.h"
2829
#include "qgsvectordataprovider.h"
2930

3031
#include <QColorDialog>
3132
#include <QFontDialog>
3233
#include <QList>
3334
#include <QMessageBox>
35+
#include <QSettings>
3436

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

4547
setupUi( this );
4648

49+
int tabIdx = QSettings().value( "/Windows/VectorLayerProperties/diagram/tab", 0 ).toInt();
50+
51+
mDiagramPropertiesTabWidget->setCurrentIndex( tabIdx );
52+
4753
mBackgroundColorButton->setColorDialogTitle( tr( "Background color" ) );
4854
mBackgroundColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
4955
mDiagramPenColorButton->setColorDialogTitle( tr( "Pen color" ) );
@@ -142,7 +148,9 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
142148
mLabelPlacementComboBox->setCurrentIndex( mLabelPlacementComboBox->findText( tr( "x-height" ) ) );
143149
mDiagramSizeSpinBox->setValue( 30 );
144150
mBarWidthSpinBox->setValue( 5 );
145-
mVisibilityGroupBox->setChecked( false );
151+
mVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
152+
mMaximumDiagramScaleLineEdit->setText( QString::number( layer->maximumScale() ) );
153+
mMinimumDiagramScaleLineEdit->setText( QString::number( layer->minimumScale() ) );
146154

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

468476
void QgsDiagramProperties::apply()
469477
{
478+
QSettings().setValue( "/Windows/VectorLayerProperties/diagram/tab",
479+
mDiagramPropertiesTabWidget->currentIndex() );
480+
470481
if ( !mDisplayDiagramsGroupBox->isChecked() )
471482
{
472483
mLayer->setDiagramRenderer( 0 );
@@ -484,20 +495,40 @@ void QgsDiagramProperties::apply()
484495
}
485496

486497
bool scaleAttributeValueOk = false;
487-
if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
488-
{
489-
// We don't need a scale attribute, the field is used as a multiplicator
490-
scaleAttributeValueOk = true;
491-
}
492-
else
493-
{
494-
// Check if a (usable) scale attribute value is inserted
495-
mValueLineEdit->text().toDouble( &scaleAttributeValueOk );
496-
}
498+
// Check if a (usable) scale attribute value is inserted
499+
mValueLineEdit->text().toDouble( &scaleAttributeValueOk );
500+
497501
if ( !mFixedSizeCheckBox->isChecked() && !scaleAttributeValueOk )
498502
{
499-
QMessageBox::warning( this, tr( "No attribute value specified" ),
500-
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 );
503+
double maxVal = DBL_MIN;
504+
QgsVectorDataProvider* provider = mLayer->dataProvider();
505+
506+
if ( provider )
507+
{
508+
if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
509+
{
510+
// Find maximum value
511+
for ( int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
512+
{
513+
maxVal = qMax( maxVal, provider->maximumValue( mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, Qt::UserRole ).toInt() ).toDouble() );
514+
}
515+
}
516+
else
517+
{
518+
maxVal = provider->maximumValue( mSizeAttributeComboBox->itemData( mSizeAttributeComboBox->currentIndex() ).toInt() ).toDouble();
519+
}
520+
}
521+
522+
if ( maxVal != DBL_MIN )
523+
{
524+
QgisApp::instance()->messageBar()->pushMessage(
525+
tr( "Interpolation value" ),
526+
tr( "You did not specify an interpolation value. A default value of %1 has been set." ).arg( QString::number( maxVal ) ),
527+
QgsMessageBar::INFO,
528+
5 );
529+
530+
mValueLineEdit->setText( QString::number( maxVal ) );
531+
}
501532
}
502533

503534
if ( diagramType == DIAGRAM_NAME_TEXT )

‎src/ui/qgsdiagrampropertiesbase.ui

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<x>0</x>
4141
<y>0</y>
4242
<width>743</width>
43-
<height>644</height>
43+
<height>761</height>
4444
</rect>
4545
</property>
4646
<layout class="QVBoxLayout" name="scrollAreaLayout">
@@ -120,7 +120,7 @@
120120
<item>
121121
<widget class="QTabWidget" name="mDiagramPropertiesTabWidget">
122122
<property name="currentIndex">
123-
<number>0</number>
123+
<number>1</number>
124124
</property>
125125
<widget class="QWidget" name="mDiagramPropertiesTabWidgetPage1">
126126
<attribute name="title">
@@ -426,7 +426,12 @@
426426
</widget>
427427
</item>
428428
<item>
429-
<widget class="QLineEdit" name="mValueLineEdit"/>
429+
<widget class="QLineEdit" name="mValueLineEdit">
430+
<property name="toolTip">
431+
<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;.
432+
Leave empty to automatically apply the maximum value.</string>
433+
</property>
434+
</widget>
430435
</item>
431436
</layout>
432437
</widget>

0 commit comments

Comments
 (0)
Please sign in to comment.