Skip to content

Commit

Permalink
Replace QgsNumericSortTreeWidgetItem with upgraded QgsTreeWidgetItem
Browse files Browse the repository at this point in the history
QgsNumericSortTreeWidgetItem had a giant TODO saying "make it work".
This makes it work, and adds some other useful features like
being able to specify custom sort value and force items to always
sort on top.
  • Loading branch information
nyalldawson committed Jul 18, 2016
1 parent 631b5e8 commit 39b3e72
Show file tree
Hide file tree
Showing 20 changed files with 634 additions and 233 deletions.
15 changes: 15 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ plugins calling this method will need to be updated.</li>
plugins calling this method will need to be updated.</li>
</ul>

\subsection qgis_api_break_3_0_QgsNumericSortTreeWidgetItem QgsNumericSortTreeWidgetItem

<ul>
<li>QgsNumericSortTreeWidgetItem has been removed and replaced with QgsTreeWidgetItem, which
has improved sort capabilities including the ability to set custom sort values for items
and for forcing certain items to always sort on top.</li>
</ul>

\subsection qgis_api_break_3_0_QgsTreeWidgetItem QgsTreeWidgetItem

<ul>
<li>QgsTreeWidgetItem is no longer a QObject and does not emit the itemEdited signal. Instead,
use QgsTreeWidgetItemObject which is an upgraded version of the original QgsTreeWidgetItem</li>
</ul>

\subsection qgis_api_break_3_0_QgsVectorLayer QgsVectorLayer

<ul>
Expand Down
2 changes: 1 addition & 1 deletion python/gui/gui.sip
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
%Include qgsnewnamedialog.sip
%Include qgsnewvectorlayerdialog.sip
%Include qgsnewgeopackagelayerdialog.sip
%Include qgsnumericsortlistviewitem.sip
%Include qgsoptionsdialogbase.sip
%Include qgsorderbydialog.sip
%Include qgsowssourceselect.sip
Expand Down Expand Up @@ -162,6 +161,7 @@
%Include qgstablewidgetitem.sip
%Include qgstextannotationitem.sip
%Include qgstrackedvectorlayertools.sip
%Include qgstreewidgetitem.sip
%Include qgsunitselectionwidget.sip
%Include qgsuserinputdockwidget.sip
%Include qgsvariableeditorwidget.sip
Expand Down
18 changes: 0 additions & 18 deletions python/gui/qgsnumericsortlistviewitem.sip

This file was deleted.

129 changes: 129 additions & 0 deletions python/gui/qgstreewidgetitem.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/** \ingroup gui
* \class QgsTreeWidgetItem
* \note added in QGIS 3.0
* QTreeWidgetItem subclass with custom handling for item sorting.
*
* QgsTreeWidgetItem allows for items to be sorted using a specified user role, and
* also correctly handles sorting numeric or mixed text and numeric values.
*/
class QgsTreeWidgetItem : QTreeWidgetItem
{
%TypeHeaderCode
#include <qgstreewidgetitem.h>
%End
public:

/** Constructor for QgsTreeWidgetItem
* @param view parent QTreeWidget view
* @param type item type
*/
explicit QgsTreeWidgetItem( QTreeWidget * view /TransferThis/, int type = Type );

/** Constructor for QgsTreeWidgetItem
* @param type item type
*/
explicit QgsTreeWidgetItem( int type = Type );

/** Constructor for QgsTreeWidgetItem
* @param strings list of strings containing text for each column in the item
* @param type item type
*/
QgsTreeWidgetItem( const QStringList &strings, int type = Type );

/** Constructor for QgsTreeWidgetItem
* @param view parent QTreeWidget view
* @param strings list of strings containing text for each column in the item
* @param type item type
*/
QgsTreeWidgetItem( QTreeWidget *view /TransferThis/, const QStringList &strings, int type = Type );

/** Constructor for QgsTreeWidgetItem
* @param view parent QTreeWidget view
* @param after QTreeWidgetItem to place insert item after in the view
* @param type item type
*/
QgsTreeWidgetItem( QTreeWidget *view /TransferThis/, QTreeWidgetItem *after, int type = Type );

/** Constructor for QgsTreeWidgetItem
* @param parent QTreeWidgetItem item
* @param type item type
*/
explicit QgsTreeWidgetItem( QTreeWidgetItem *parent /TransferThis/, int type = Type );

/** Constructor for QgsTreeWidgetItem
* @param parent QTreeWidgetItem item
* @param strings list of strings containing text for each column in the item
* @param type item type
*/
QgsTreeWidgetItem( QTreeWidgetItem *parent /TransferThis/, const QStringList &strings, int type = Type );

/** Constructor for QgsTreeWidgetItem
* @param parent QTreeWidgetItem item
* @param after QTreeWidgetItem to place insert item after in the view
* @param type item type
*/
QgsTreeWidgetItem( QTreeWidgetItem *parent /TransferThis/, QTreeWidgetItem *after, int type = Type );

/** Sets the custom sort data for a specified column. If set, this value will be used when
* sorting the item instead of the item's display text. If not set, the item's display
* text will be used when sorting.
* @param column column index
* @param value sort value
* @see sortData()
*/
void setSortData( int column, const QVariant& value );

/** Returns the custom sort data for a specified column. If set, this value will be used when
* sorting the item instead of the item's display text. If not set, the item's display
* text will be used when sorting.
* @see setSortData()
*/
QVariant sortData( int column ) const;

/** Sets a the item to display always on top of other items in the widget, regardless of the
* sort column and sort or display value for the item.
* @param priority priority for sorting always on top items. Items with a lower priority will
* be placed above items with a higher priority.
* @see alwaysOnTopPriority()
*/
void setAlwaysOnTopPriority( int priority );

/** Returns the item's priority when it is set to show always on top. Items with a lower priority will
* be placed above items with a higher priority.
* @returns priority, or -1 if item is not set to show always on top
* @see setAlwaysOnTopPriority()
*/
int alwaysOnTopPriority() const;

virtual bool operator<( const QTreeWidgetItem &other ) const;

};

/** \ingroup gui
* \class QgsTreeWidgetItemObject
* \note added in QGIS 3.0
* Custom QgsTreeWidgetItem with extra signals when item is edited.
*/
class QgsTreeWidgetItemObject: QObject, QgsTreeWidgetItem
{
%TypeHeaderCode
#include <qgstreewidgetitem.h>
%End
public:

/** Constructor for QgsTreeWidgetItemObject
* @param type item type
*/
explicit QgsTreeWidgetItemObject( int type = Type );

/** Constructs a tree widget item of the specified type and appends it to the items in the given parent. */
explicit QgsTreeWidgetItemObject( QTreeWidget * parent /TransferThis/, int type = Type );

/** Sets the value for the item's column and role to the given value. */
virtual void setData( int column, int role, const QVariant & value );

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 );
};

20 changes: 0 additions & 20 deletions python/gui/raster/qgssinglebandpseudocolorrendererwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,3 @@ class QgsSingleBandPseudoColorRendererWidget : QgsRasterRendererWidget

};

/**
* Custom QTreeWidgetItem with extra signal when item is edited and numeric sorting.
*/
class QgsTreeWidgetItem: QObject, QTreeWidgetItem
{
%TypeHeaderCode
#include <qgssinglebandpseudocolorrendererwidget.h>
%End
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 );

/** 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 );
};
4 changes: 2 additions & 2 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ SET(QGIS_GUI_SRCS
qgsnewnamedialog.cpp
qgsnewvectorlayerdialog.cpp
qgsnewgeopackagelayerdialog.cpp
qgsnumericsortlistviewitem.cpp
qgsoptionsdialogbase.cpp
qgsorderbydialog.cpp
qgsowssourceselect.cpp
Expand Down Expand Up @@ -301,6 +300,7 @@ SET(QGIS_GUI_SRCS
qgstablewidgetitem.cpp
qgstextannotationitem.cpp
qgstrackedvectorlayertools.cpp
qgstreewidgetitem.cpp
qgsunitselectionwidget.cpp
qgsuserinputdockwidget.cpp
qgsvariableeditorwidget.cpp
Expand Down Expand Up @@ -447,6 +447,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsslider.h
qgssqlcomposerdialog.h
qgssublayersdialog.h
qgstreewidgetitem.h
qgsunitselectionwidget.h
qgsuserinputdockwidget.h
qgsvariableeditorwidget.h
Expand Down Expand Up @@ -634,7 +635,6 @@ SET(QGIS_GUI_HDRS
qgsmaplayerconfigwidgetfactory.h
qgsmapmouseevent.h
qgsmaptip.h
qgsnumericsortlistviewitem.h
qgsrubberband.h
qgssqlcomposerdialog.h
qgssvgannotationitem.h
Expand Down
49 changes: 0 additions & 49 deletions src/gui/qgsnumericsortlistviewitem.cpp

This file was deleted.

52 changes: 0 additions & 52 deletions src/gui/qgsnumericsortlistviewitem.h

This file was deleted.

12 changes: 6 additions & 6 deletions src/gui/qgsowssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "qgsmanageconnectionsdialog.h"
#include "qgsmessageviewer.h"
#include "qgsnewhttpconnection.h"
#include "qgsnumericsortlistviewitem.h"
#include "qgstreewidgetitem.h"
#include "qgsproject.h"
#include "qgsproviderregistry.h"
#include "qgsowsconnection.h"
Expand Down Expand Up @@ -303,10 +303,10 @@ void QgsOWSSourceSelect::on_mLoadButton_clicked()
emit connectionsChanged();
}

QgsNumericSortTreeWidgetItem *QgsOWSSourceSelect::createItem(
QgsTreeWidgetItem *QgsOWSSourceSelect::createItem(
int id,
const QStringList &names,
QMap<int, QgsNumericSortTreeWidgetItem *> &items,
QMap<int, QgsTreeWidgetItem *> &items,
int &layerAndStyleCount,
const QMap<int, int> &layerParents,
const QMap<int, QStringList> &layerParentNames )
Expand All @@ -316,15 +316,15 @@ QgsNumericSortTreeWidgetItem *QgsOWSSourceSelect::createItem(
return items[id];


QgsNumericSortTreeWidgetItem *item;
QgsTreeWidgetItem *item;
if ( layerParents.contains( id ) )
{
// it has parent -> create first its parent
int parent = layerParents[ id ];
item = new QgsNumericSortTreeWidgetItem( createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
item = new QgsTreeWidgetItem( createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
}
else
item = new QgsNumericSortTreeWidgetItem( mLayersTreeWidget );
item = new QgsTreeWidgetItem( mLayersTreeWidget );

item->setText( 0, QString::number( ++layerAndStyleCount ) );
item->setText( 1, names[0].simplified() );
Expand Down
Loading

0 comments on commit 39b3e72

Please sign in to comment.