Skip to content

Commit 2556c7c

Browse files
pierstitusnyalldawson
authored andcommittedJun 2, 2016
documentation and sip coverage
1 parent f27507d commit 2556c7c

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed
 

‎python/gui/raster/qgsrasterminmaxwidget.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class QgsRasterMinMaxWidget: QWidget
1111

1212
void setBands( const QList<int> & theBands );
1313

14+
QgsRectangle extent();
15+
int sampleSize();
16+
1417
// Load programmaticaly with current values
1518
void load();
1619

‎python/gui/raster/qgssinglebandpseudocolorrendererwidget.sip

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class QgsSingleBandPseudoColorRendererWidget : QgsRasterRendererWidget
99
{
1010
Continuous, // Using breaks from color palette
1111
EqualInterval,
12+
Quantile,
1213
};
1314

1415
QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent = QgsRectangle() );
@@ -23,3 +24,17 @@ class QgsSingleBandPseudoColorRendererWidget : QgsRasterRendererWidget
2324
void loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin );
2425

2526
};
27+
28+
class QgsTreeWidgetItem: QObject, QTreeWidgetItem
29+
{
30+
%TypeHeaderCode
31+
#include <qgssinglebandpseudocolorrendererwidget.h>
32+
%End
33+
public:
34+
explicit QgsTreeWidgetItem( QTreeWidget * parent, int type = Type );
35+
virtual void setData( int column, int role, const QVariant & value );
36+
virtual bool operator< ( const QTreeWidgetItem & other ) const;
37+
38+
signals:
39+
void itemEdited( QTreeWidgetItem* item, int column );
40+
};

‎src/gui/raster/qgsrasterminmaxwidget.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ class GUI_EXPORT QgsRasterMinMaxWidget: public QWidget, private Ui::QgsRasterMin
3232
void setExtent( const QgsRectangle & theExtent ) { mExtent = theExtent; }
3333

3434
void setBands( const QList<int> & theBands ) { mBands = theBands; }
35-
35+
/** Return the extent selected by the user.
36+
Either an empty extent for 'full' or the current visible extent. */
3637
QgsRectangle extent() { QgsRectangle myExtent; return mCurrentExtentRadioButton->isChecked() ? mExtent : myExtent; }
38+
/** Return the selected sample size. */
3739
int sampleSize() { return mEstimateRadioButton->isChecked() ? 250000 : 0; }
3840

3941
// Load programmaticaly with current values

‎src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,29 @@ void QgsTreeWidgetItem::setData( int column, int role, const QVariant & value )
3939
}
4040
}
4141

42-
// override < operator to allow sorting
42+
// override < operator to allow numeric sorting
43+
/** Returns true if the text in the item is less than the text in the other item, otherwise returns false.
44+
*
45+
* Compares on numeric value of text if possible, otherwise on text.
46+
*/
4347
bool QgsTreeWidgetItem::operator<( const QTreeWidgetItem & other ) const
4448
{
45-
// could use treeWidget()->sortColumn() instead of 0
46-
return text( 0 ).toDouble() < other.text( 0 ).toDouble();
49+
int column = treeWidget()->sortColumn();
50+
bool ok1, ok2, val;
51+
val = text( column ).toDouble( &ok1 ) < other.text( column ).toDouble( &ok2 );
52+
if ( ok1 && ok2 )
53+
{
54+
return val;
55+
}
56+
else if ( ok1 || ok2 )
57+
{
58+
// sort numbers before strings
59+
return ok1;
60+
}
61+
else
62+
{
63+
return text( column ) < other.text( column );
64+
}
4765
}
4866

4967
QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent )
@@ -183,6 +201,10 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
183201
return renderer;
184202
}
185203

204+
/** Generate labels from the values in the color map.
205+
* Skip labels which were manually edited (black text).
206+
* Text of generated labels is made gray
207+
*/
186208
void QgsSingleBandPseudoColorRendererWidget::autoLabel()
187209
{
188210
bool discrete = mColorInterpolationComboBox->currentText() == tr( "Discrete" );
@@ -223,6 +245,7 @@ void QgsSingleBandPseudoColorRendererWidget::autoLabel()
223245
}
224246
}
225247

248+
/** Extract the unit out of the current labels and set the unit field. */
226249
void QgsSingleBandPseudoColorRendererWidget::setUnitFromLabels()
227250
{
228251
bool discrete = mColorInterpolationComboBox->currentText() == tr( "Discrete" );
@@ -712,12 +735,14 @@ void QgsSingleBandPseudoColorRendererWidget::on_mColormapTreeWidget_itemDoubleCl
712735
{
713736
if ( column == 2 )
714737
{
738+
// Set text color to default black, which signifies a manually edited label
715739
item->setForeground( 2, QBrush() );
716740
}
717741
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
718742
}
719743
}
720744

745+
/** Update the colormap table after manual edit. */
721746
void QgsSingleBandPseudoColorRendererWidget::mColormapTreeWidget_itemEdited( QTreeWidgetItem* item, int column )
722747
{
723748
Q_UNUSED( item );

‎src/gui/raster/qgssinglebandpseudocolorrendererwidget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,23 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
8181
int mMinMaxOrigin;
8282
};
8383

84+
/**
85+
* Custom QTreeWidgetItem with extra signal when item is edited and numeric sorting.
86+
*/
8487
class GUI_EXPORT QgsTreeWidgetItem: public QObject, public QTreeWidgetItem
8588
{
8689
Q_OBJECT
8790
public:
91+
/** Constructs a tree widget item of the specified type and appends it to the items in the given parent. */
8892
explicit QgsTreeWidgetItem( QTreeWidget * parent, int type = Type ) : QTreeWidgetItem( parent, type ) {}
8993

9094
public:
95+
/** Sets the value for the item's column and role to the given value. */
9196
virtual void setData( int column, int role, const QVariant & value );
9297
virtual bool operator< ( const QTreeWidgetItem & other ) const;
9398

9499
signals:
100+
/** This signal is emitted when the contents of the column in the specified item has been edited by the user. */
95101
void itemEdited( QTreeWidgetItem* item, int column );
96102
};
97103

0 commit comments

Comments
 (0)