Skip to content

Commit 39b3e72

Browse files
committedJul 18, 2016
Replace QgsNumericSortTreeWidgetItem with upgraded QgsTreeWidgetItem
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.
1 parent 631b5e8 commit 39b3e72

20 files changed

+634
-233
lines changed
 

‎doc/api_break.dox

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ plugins calling this method will need to be updated.</li>
179179
plugins calling this method will need to be updated.</li>
180180
</ul>
181181

182+
\subsection qgis_api_break_3_0_QgsNumericSortTreeWidgetItem QgsNumericSortTreeWidgetItem
183+
184+
<ul>
185+
<li>QgsNumericSortTreeWidgetItem has been removed and replaced with QgsTreeWidgetItem, which
186+
has improved sort capabilities including the ability to set custom sort values for items
187+
and for forcing certain items to always sort on top.</li>
188+
</ul>
189+
190+
\subsection qgis_api_break_3_0_QgsTreeWidgetItem QgsTreeWidgetItem
191+
192+
<ul>
193+
<li>QgsTreeWidgetItem is no longer a QObject and does not emit the itemEdited signal. Instead,
194+
use QgsTreeWidgetItemObject which is an upgraded version of the original QgsTreeWidgetItem</li>
195+
</ul>
196+
182197
\subsection qgis_api_break_3_0_QgsVectorLayer QgsVectorLayer
183198

184199
<ul>

‎python/gui/gui.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
%Include qgsnewnamedialog.sip
132132
%Include qgsnewvectorlayerdialog.sip
133133
%Include qgsnewgeopackagelayerdialog.sip
134-
%Include qgsnumericsortlistviewitem.sip
135134
%Include qgsoptionsdialogbase.sip
136135
%Include qgsorderbydialog.sip
137136
%Include qgsowssourceselect.sip
@@ -162,6 +161,7 @@
162161
%Include qgstablewidgetitem.sip
163162
%Include qgstextannotationitem.sip
164163
%Include qgstrackedvectorlayertools.sip
164+
%Include qgstreewidgetitem.sip
165165
%Include qgsunitselectionwidget.sip
166166
%Include qgsuserinputdockwidget.sip
167167
%Include qgsvariableeditorwidget.sip

‎python/gui/qgsnumericsortlistviewitem.sip

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎python/gui/qgstreewidgetitem.sip

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/** \ingroup gui
2+
* \class QgsTreeWidgetItem
3+
* \note added in QGIS 3.0
4+
* QTreeWidgetItem subclass with custom handling for item sorting.
5+
*
6+
* QgsTreeWidgetItem allows for items to be sorted using a specified user role, and
7+
* also correctly handles sorting numeric or mixed text and numeric values.
8+
*/
9+
class QgsTreeWidgetItem : QTreeWidgetItem
10+
{
11+
%TypeHeaderCode
12+
#include <qgstreewidgetitem.h>
13+
%End
14+
public:
15+
16+
/** Constructor for QgsTreeWidgetItem
17+
* @param view parent QTreeWidget view
18+
* @param type item type
19+
*/
20+
explicit QgsTreeWidgetItem( QTreeWidget * view /TransferThis/, int type = Type );
21+
22+
/** Constructor for QgsTreeWidgetItem
23+
* @param type item type
24+
*/
25+
explicit QgsTreeWidgetItem( int type = Type );
26+
27+
/** Constructor for QgsTreeWidgetItem
28+
* @param strings list of strings containing text for each column in the item
29+
* @param type item type
30+
*/
31+
QgsTreeWidgetItem( const QStringList &strings, int type = Type );
32+
33+
/** Constructor for QgsTreeWidgetItem
34+
* @param view parent QTreeWidget view
35+
* @param strings list of strings containing text for each column in the item
36+
* @param type item type
37+
*/
38+
QgsTreeWidgetItem( QTreeWidget *view /TransferThis/, const QStringList &strings, int type = Type );
39+
40+
/** Constructor for QgsTreeWidgetItem
41+
* @param view parent QTreeWidget view
42+
* @param after QTreeWidgetItem to place insert item after in the view
43+
* @param type item type
44+
*/
45+
QgsTreeWidgetItem( QTreeWidget *view /TransferThis/, QTreeWidgetItem *after, int type = Type );
46+
47+
/** Constructor for QgsTreeWidgetItem
48+
* @param parent QTreeWidgetItem item
49+
* @param type item type
50+
*/
51+
explicit QgsTreeWidgetItem( QTreeWidgetItem *parent /TransferThis/, int type = Type );
52+
53+
/** Constructor for QgsTreeWidgetItem
54+
* @param parent QTreeWidgetItem item
55+
* @param strings list of strings containing text for each column in the item
56+
* @param type item type
57+
*/
58+
QgsTreeWidgetItem( QTreeWidgetItem *parent /TransferThis/, const QStringList &strings, int type = Type );
59+
60+
/** Constructor for QgsTreeWidgetItem
61+
* @param parent QTreeWidgetItem item
62+
* @param after QTreeWidgetItem to place insert item after in the view
63+
* @param type item type
64+
*/
65+
QgsTreeWidgetItem( QTreeWidgetItem *parent /TransferThis/, QTreeWidgetItem *after, int type = Type );
66+
67+
/** Sets the custom sort data for a specified column. If set, this value will be used when
68+
* sorting the item instead of the item's display text. If not set, the item's display
69+
* text will be used when sorting.
70+
* @param column column index
71+
* @param value sort value
72+
* @see sortData()
73+
*/
74+
void setSortData( int column, const QVariant& value );
75+
76+
/** Returns the custom sort data for a specified column. If set, this value will be used when
77+
* sorting the item instead of the item's display text. If not set, the item's display
78+
* text will be used when sorting.
79+
* @see setSortData()
80+
*/
81+
QVariant sortData( int column ) const;
82+
83+
/** Sets a the item to display always on top of other items in the widget, regardless of the
84+
* sort column and sort or display value for the item.
85+
* @param priority priority for sorting always on top items. Items with a lower priority will
86+
* be placed above items with a higher priority.
87+
* @see alwaysOnTopPriority()
88+
*/
89+
void setAlwaysOnTopPriority( int priority );
90+
91+
/** Returns the item's priority when it is set to show always on top. Items with a lower priority will
92+
* be placed above items with a higher priority.
93+
* @returns priority, or -1 if item is not set to show always on top
94+
* @see setAlwaysOnTopPriority()
95+
*/
96+
int alwaysOnTopPriority() const;
97+
98+
virtual bool operator<( const QTreeWidgetItem &other ) const;
99+
100+
};
101+
102+
/** \ingroup gui
103+
* \class QgsTreeWidgetItemObject
104+
* \note added in QGIS 3.0
105+
* Custom QgsTreeWidgetItem with extra signals when item is edited.
106+
*/
107+
class QgsTreeWidgetItemObject: QObject, QgsTreeWidgetItem
108+
{
109+
%TypeHeaderCode
110+
#include <qgstreewidgetitem.h>
111+
%End
112+
public:
113+
114+
/** Constructor for QgsTreeWidgetItemObject
115+
* @param type item type
116+
*/
117+
explicit QgsTreeWidgetItemObject( int type = Type );
118+
119+
/** Constructs a tree widget item of the specified type and appends it to the items in the given parent. */
120+
explicit QgsTreeWidgetItemObject( QTreeWidget * parent /TransferThis/, int type = Type );
121+
122+
/** Sets the value for the item's column and role to the given value. */
123+
virtual void setData( int column, int role, const QVariant & value );
124+
125+
signals:
126+
/** This signal is emitted when the contents of the column in the specified item has been edited by the user. */
127+
void itemEdited( QTreeWidgetItem* item, int column );
128+
};
129+

‎python/gui/raster/qgssinglebandpseudocolorrendererwidget.sip

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,3 @@ class QgsSingleBandPseudoColorRendererWidget : QgsRasterRendererWidget
2626

2727
};
2828

29-
/**
30-
* Custom QTreeWidgetItem with extra signal when item is edited and numeric sorting.
31-
*/
32-
class QgsTreeWidgetItem: QObject, QTreeWidgetItem
33-
{
34-
%TypeHeaderCode
35-
#include <qgssinglebandpseudocolorrendererwidget.h>
36-
%End
37-
public:
38-
/** Constructs a tree widget item of the specified type and appends it to the items in the given parent. */
39-
explicit QgsTreeWidgetItem( QTreeWidget * parent, int type = Type );
40-
41-
/** Sets the value for the item's column and role to the given value. */
42-
virtual void setData( int column, int role, const QVariant & value );
43-
virtual bool operator< ( const QTreeWidgetItem & other ) const;
44-
45-
signals:
46-
/** This signal is emitted when the contents of the column in the specified item has been edited by the user. */
47-
void itemEdited( QTreeWidgetItem* item, int column );
48-
};

‎src/gui/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ SET(QGIS_GUI_SRCS
269269
qgsnewnamedialog.cpp
270270
qgsnewvectorlayerdialog.cpp
271271
qgsnewgeopackagelayerdialog.cpp
272-
qgsnumericsortlistviewitem.cpp
273272
qgsoptionsdialogbase.cpp
274273
qgsorderbydialog.cpp
275274
qgsowssourceselect.cpp
@@ -301,6 +300,7 @@ SET(QGIS_GUI_SRCS
301300
qgstablewidgetitem.cpp
302301
qgstextannotationitem.cpp
303302
qgstrackedvectorlayertools.cpp
303+
qgstreewidgetitem.cpp
304304
qgsunitselectionwidget.cpp
305305
qgsuserinputdockwidget.cpp
306306
qgsvariableeditorwidget.cpp
@@ -447,6 +447,7 @@ SET(QGIS_GUI_MOC_HDRS
447447
qgsslider.h
448448
qgssqlcomposerdialog.h
449449
qgssublayersdialog.h
450+
qgstreewidgetitem.h
450451
qgsunitselectionwidget.h
451452
qgsuserinputdockwidget.h
452453
qgsvariableeditorwidget.h
@@ -634,7 +635,6 @@ SET(QGIS_GUI_HDRS
634635
qgsmaplayerconfigwidgetfactory.h
635636
qgsmapmouseevent.h
636637
qgsmaptip.h
637-
qgsnumericsortlistviewitem.h
638638
qgsrubberband.h
639639
qgssqlcomposerdialog.h
640640
qgssvgannotationitem.h

‎src/gui/qgsnumericsortlistviewitem.cpp

Lines changed: 0 additions & 49 deletions
This file was deleted.

‎src/gui/qgsnumericsortlistviewitem.h

Lines changed: 0 additions & 52 deletions
This file was deleted.

‎src/gui/qgsowssourceselect.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "qgsmanageconnectionsdialog.h"
3030
#include "qgsmessageviewer.h"
3131
#include "qgsnewhttpconnection.h"
32-
#include "qgsnumericsortlistviewitem.h"
32+
#include "qgstreewidgetitem.h"
3333
#include "qgsproject.h"
3434
#include "qgsproviderregistry.h"
3535
#include "qgsowsconnection.h"
@@ -303,10 +303,10 @@ void QgsOWSSourceSelect::on_mLoadButton_clicked()
303303
emit connectionsChanged();
304304
}
305305

306-
QgsNumericSortTreeWidgetItem *QgsOWSSourceSelect::createItem(
306+
QgsTreeWidgetItem *QgsOWSSourceSelect::createItem(
307307
int id,
308308
const QStringList &names,
309-
QMap<int, QgsNumericSortTreeWidgetItem *> &items,
309+
QMap<int, QgsTreeWidgetItem *> &items,
310310
int &layerAndStyleCount,
311311
const QMap<int, int> &layerParents,
312312
const QMap<int, QStringList> &layerParentNames )
@@ -316,15 +316,15 @@ QgsNumericSortTreeWidgetItem *QgsOWSSourceSelect::createItem(
316316
return items[id];
317317

318318

319-
QgsNumericSortTreeWidgetItem *item;
319+
QgsTreeWidgetItem *item;
320320
if ( layerParents.contains( id ) )
321321
{
322322
// it has parent -> create first its parent
323323
int parent = layerParents[ id ];
324-
item = new QgsNumericSortTreeWidgetItem( createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
324+
item = new QgsTreeWidgetItem( createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
325325
}
326326
else
327-
item = new QgsNumericSortTreeWidgetItem( mLayersTreeWidget );
327+
item = new QgsTreeWidgetItem( mLayersTreeWidget );
328328

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

0 commit comments

Comments
 (0)
Please sign in to comment.