Skip to content

Commit

Permalink
documentation and sip coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pierstitus authored and nyalldawson committed Jun 2, 2016
1 parent f27507d commit 2556c7c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
3 changes: 3 additions & 0 deletions python/gui/raster/qgsrasterminmaxwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class QgsRasterMinMaxWidget: QWidget

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

QgsRectangle extent();
int sampleSize();

// Load programmaticaly with current values
void load();

Expand Down
15 changes: 15 additions & 0 deletions python/gui/raster/qgssinglebandpseudocolorrendererwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class QgsSingleBandPseudoColorRendererWidget : QgsRasterRendererWidget
{
Continuous, // Using breaks from color palette
EqualInterval,
Quantile,
};

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

};

class QgsTreeWidgetItem: QObject, QTreeWidgetItem
{
%TypeHeaderCode
#include <qgssinglebandpseudocolorrendererwidget.h>
%End
public:
explicit QgsTreeWidgetItem( QTreeWidget * parent, int type = Type );
virtual void setData( int column, int role, const QVariant & value );
virtual bool operator< ( const QTreeWidgetItem & other ) const;

signals:
void itemEdited( QTreeWidgetItem* item, int column );
};
4 changes: 3 additions & 1 deletion src/gui/raster/qgsrasterminmaxwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class GUI_EXPORT QgsRasterMinMaxWidget: public QWidget, private Ui::QgsRasterMin
void setExtent( const QgsRectangle & theExtent ) { mExtent = theExtent; }

void setBands( const QList<int> & theBands ) { mBands = theBands; }

/** Return the extent selected by the user.
Either an empty extent for 'full' or the current visible extent. */
QgsRectangle extent() { QgsRectangle myExtent; return mCurrentExtentRadioButton->isChecked() ? mExtent : myExtent; }
/** Return the selected sample size. */
int sampleSize() { return mEstimateRadioButton->isChecked() ? 250000 : 0; }

// Load programmaticaly with current values
Expand Down
31 changes: 28 additions & 3 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,29 @@ void QgsTreeWidgetItem::setData( int column, int role, const QVariant & value )
}
}

// override < operator to allow sorting
// override < operator to allow numeric sorting
/** Returns true if the text in the item is less than the text in the other item, otherwise returns false.
*
* Compares on numeric value of text if possible, otherwise on text.
*/
bool QgsTreeWidgetItem::operator<( const QTreeWidgetItem & other ) const
{
// could use treeWidget()->sortColumn() instead of 0
return text( 0 ).toDouble() < other.text( 0 ).toDouble();
int column = treeWidget()->sortColumn();
bool ok1, ok2, val;
val = text( column ).toDouble( &ok1 ) < other.text( column ).toDouble( &ok2 );
if ( ok1 && ok2 )
{
return val;
}
else if ( ok1 || ok2 )
{
// sort numbers before strings
return ok1;
}
else
{
return text( column ) < other.text( column );
}
}

QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent )
Expand Down Expand Up @@ -183,6 +201,10 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
return renderer;
}

/** Generate labels from the values in the color map.
* Skip labels which were manually edited (black text).
* Text of generated labels is made gray
*/
void QgsSingleBandPseudoColorRendererWidget::autoLabel()
{
bool discrete = mColorInterpolationComboBox->currentText() == tr( "Discrete" );
Expand Down Expand Up @@ -223,6 +245,7 @@ void QgsSingleBandPseudoColorRendererWidget::autoLabel()
}
}

/** Extract the unit out of the current labels and set the unit field. */
void QgsSingleBandPseudoColorRendererWidget::setUnitFromLabels()
{
bool discrete = mColorInterpolationComboBox->currentText() == tr( "Discrete" );
Expand Down Expand Up @@ -712,12 +735,14 @@ void QgsSingleBandPseudoColorRendererWidget::on_mColormapTreeWidget_itemDoubleCl
{
if ( column == 2 )
{
// Set text color to default black, which signifies a manually edited label
item->setForeground( 2, QBrush() );
}
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
}
}

/** Update the colormap table after manual edit. */
void QgsSingleBandPseudoColorRendererWidget::mColormapTreeWidget_itemEdited( QTreeWidgetItem* item, int column )
{
Q_UNUSED( item );
Expand Down
6 changes: 6 additions & 0 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,23 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
int mMinMaxOrigin;
};

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

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

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

Expand Down

0 comments on commit 2556c7c

Please sign in to comment.