Skip to content

Commit 26a4f80

Browse files
committed
Update to usability of rule-based styles widgets.
Rule-based tree widget: * Label and expression header sections have a larger initial width of 200, with new minimum width of 100 for all sections. * Resizing of first 3 sections are saved to/restored from QSettings. Last section stretches, so is not saved/restored. * All items now have tool tips of their content (good for small screens). Rule editing dialog: * Expanded width for initial form fields * Added tool tips for expression and description fields.
1 parent 81abf7f commit 26a4f80

4 files changed

+43
-1
lines changed

src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp

+31-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qstring.h"
2727

2828
#include <QMenu>
29+
#include <QSettings>
2930
#include <QTreeWidgetItem>
3031
#include <QVBoxLayout>
3132
#include <QMessageBox>
@@ -89,6 +90,12 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye
8990
connect( btnRenderingOrder, SIGNAL( clicked() ), this, SLOT( setRenderingOrder() ) );
9091

9192
currentRuleChanged();
93+
94+
// store/restore header section widths
95+
connect( viewRules->header(), SIGNAL( sectionResized( int, int, int ) ), this, SLOT( saveSectionWidth( int, int, int ) ) );
96+
97+
restoreSectionWidths();
98+
9299
}
93100

94101
QgsRuleBasedRendererV2Widget::~QgsRuleBasedRendererV2Widget()
@@ -367,6 +374,27 @@ void QgsRuleBasedRendererV2Widget::setRenderingOrder()
367374
dlg.exec();
368375
}
369376

377+
void QgsRuleBasedRendererV2Widget::saveSectionWidth( int section, int oldSize, int newSize )
378+
{
379+
Q_UNUSED( oldSize );
380+
// skip last section, as it stretches
381+
if ( section == 3 )
382+
return;
383+
QSettings settings;
384+
QString path = "/Windows/RuleBasedTree/sectionWidth/" + QString::number( section );
385+
settings.setValue( path, newSize );
386+
}
387+
388+
void QgsRuleBasedRendererV2Widget::restoreSectionWidths()
389+
{
390+
QSettings settings;
391+
QString path = "/Windows/RuleBasedTree/sectionWidth/";
392+
QHeaderView* head = viewRules->header();
393+
head->resizeSection( 0, settings.value( path + QString::number( 0 ), 200 ).toInt() );
394+
head->resizeSection( 1, settings.value( path + QString::number( 1 ), 200 ).toInt() );
395+
head->resizeSection( 2, settings.value( path + QString::number( 2 ), 100 ).toInt() );
396+
}
397+
370398

371399
///////////
372400

@@ -379,8 +407,10 @@ QgsRendererRulePropsDialog::QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::
379407
connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
380408

381409
editFilter->setText( mRule->filterExpression() );
410+
editFilter->setToolTip( mRule->filterExpression() );
382411
editLabel->setText( mRule->label() );
383412
editDescription->setText( mRule->description() );
413+
editDescription->setToolTip( mRule->description() );
384414

385415
if ( mRule->dependsOnScale() )
386416
{
@@ -518,7 +548,7 @@ QVariant QgsRuleBasedRendererV2Model::data( const QModelIndex &index, int role )
518548

519549
QgsRuleBasedRendererV2::Rule* rule = ruleForIndex( index );
520550

521-
if ( role == Qt::DisplayRole )
551+
if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
522552
{
523553
switch ( index.column() )
524554
{

src/gui/symbology-ng/qgsrulebasedrendererv2widget.h

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, priv
107107

108108
void currentRuleChanged( const QModelIndex& current = QModelIndex(), const QModelIndex& previous = QModelIndex() );
109109

110+
void saveSectionWidth( int section, int oldSize, int newSize );
111+
void restoreSectionWidths();
112+
110113
protected:
111114

112115
void refineRule( int type );

src/ui/qgsrendererrulepropsdialogbase.ui

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<layout class="QVBoxLayout" name="verticalLayout">
1717
<item>
1818
<layout class="QFormLayout" name="formLayout">
19+
<property name="fieldGrowthPolicy">
20+
<enum>QFormLayout::ExpandingFieldsGrow</enum>
21+
</property>
1922
<item row="0" column="0">
2023
<widget class="QLabel" name="label_1">
2124
<property name="text">

src/ui/qgsrulebasedrendererv2widget.ui

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
<property name="allColumnsShowFocus">
3838
<bool>true</bool>
3939
</property>
40+
<attribute name="headerMinimumSectionSize">
41+
<number>100</number>
42+
</attribute>
43+
<attribute name="headerStretchLastSection">
44+
<bool>true</bool>
45+
</attribute>
4046
</widget>
4147
</item>
4248
<item>

0 commit comments

Comments
 (0)