Skip to content
Permalink
Browse files

documentation and sip coverage

  • Loading branch information
pierstitus authored and nyalldawson committed Apr 9, 2016
1 parent f27507d commit 2556c7ce9498049d7e1283677a9f66436daaefbe
@@ -11,6 +11,9 @@ class QgsRasterMinMaxWidget: QWidget

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

QgsRectangle extent();
int sampleSize();

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

@@ -9,6 +9,7 @@ class QgsSingleBandPseudoColorRendererWidget : QgsRasterRendererWidget
{
Continuous, // Using breaks from color palette
EqualInterval,
Quantile,
};

QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent = QgsRectangle() );
@@ -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 );
};
@@ -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
@@ -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 )
@@ -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" );
@@ -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" );
@@ -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 );
@@ -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 );
};

0 comments on commit 2556c7c

Please sign in to comment.
You can’t perform that action at this time.