QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgstreewidgetitem.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgstreewidgetitem.cpp
3
---------------------
4
begin : 06 Nov, 2005
5
copyright : (C) 2005 by Brendan Morley
6
email : morb at ozemail dot com dot au
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include "
qgstreewidgetitem.h
"
19
20
#include "
qgis.h
"
21
#include "
qgsvariantutils.h
"
22
23
#include "moc_qgstreewidgetitem.cpp"
24
25
QgsTreeWidgetItem::QgsTreeWidgetItem
( QTreeWidget *parent,
int
type )
26
: QTreeWidgetItem( parent, type )
27
{}
28
29
QgsTreeWidgetItem::QgsTreeWidgetItem
(
int
type )
30
: QTreeWidgetItem( type )
31
{}
32
33
QgsTreeWidgetItem::QgsTreeWidgetItem
(
const
QStringList &strings,
int
type )
34
: QTreeWidgetItem( strings, type )
35
{}
36
37
QgsTreeWidgetItem::QgsTreeWidgetItem
( QTreeWidget *view,
const
QStringList &strings,
int
type )
38
: QTreeWidgetItem( view, strings, type )
39
{}
40
41
QgsTreeWidgetItem::QgsTreeWidgetItem
( QTreeWidget *view, QTreeWidgetItem *after,
int
type )
42
: QTreeWidgetItem( view, after, type )
43
{}
44
45
QgsTreeWidgetItem::QgsTreeWidgetItem
( QTreeWidgetItem *parent,
int
type )
46
: QTreeWidgetItem( parent, type )
47
{}
48
49
QgsTreeWidgetItem::QgsTreeWidgetItem
( QTreeWidgetItem *parent,
const
QStringList &strings,
int
type )
50
: QTreeWidgetItem( parent, strings, type )
51
{}
52
53
QgsTreeWidgetItem::QgsTreeWidgetItem
( QTreeWidgetItem *parent, QTreeWidgetItem *after,
int
type )
54
: QTreeWidgetItem( parent, after, type )
55
{}
56
57
void
QgsTreeWidgetItem::setSortData
(
int
column,
const
QVariant &value )
58
{
59
setData( column, CustomSortRole, value );
60
}
61
62
QVariant
QgsTreeWidgetItem::sortData
(
int
column )
const
63
{
64
return
data( column, CustomSortRole );
65
}
66
67
void
QgsTreeWidgetItem::setAlwaysOnTopPriority
(
int
priority )
68
{
69
setData( 0, AlwaysOnTopPriorityRole, priority );
70
}
71
72
int
QgsTreeWidgetItem::alwaysOnTopPriority
()
const
73
{
74
const
QVariant val = data( 0, AlwaysOnTopPriorityRole );
75
return
val.isValid() ? val.toInt() : -1;
76
}
77
78
bool
QgsTreeWidgetItem::operator<
(
const
QTreeWidgetItem &other )
const
79
{
80
const
int
column = treeWidget()->sortColumn();
81
82
// check always on top priority - note - no way of determining sort order from tree widget, so
83
// these will sometimes be incorrectly placed at the bottom
84
const
QVariant priority1 = data( 0, AlwaysOnTopPriorityRole );
85
const
QVariant priority2 = other.data( 0, AlwaysOnTopPriorityRole );
86
if
( priority1.isValid() && priority2.isValid() )
87
{
88
const
int
i1 = priority1.toInt();
89
const
int
i2 = priority2.toInt();
90
if
( i1 != i2 )
91
return
priority1.toInt() < priority2.toInt();
92
}
93
else
if
( priority1.isValid() )
94
{
95
return
true
;
96
}
97
else
if
( priority2.isValid() )
98
{
99
return
false
;
100
}
101
102
// no always on top priorities, check data
103
bool
ok1, ok2, val;
104
105
// prefer the custom sort role, but fall back to display text
106
QVariant val1 = data( column, CustomSortRole );
107
if
( !val1.isValid() )
108
val1 = text( column );
109
QVariant val2 = other.data( column, CustomSortRole );
110
if
( !val2.isValid() )
111
val2 = other.text( column );
112
113
if
( !
QgsVariantUtils::isNull
( val1 ) && !
QgsVariantUtils::isNull
( val2 ) )
114
{
115
val = val1.toDouble( &ok1 ) < val2.toDouble( &ok2 );
116
if
( ok1 && ok2 )
117
{
118
return
val;
119
}
120
else
if
( ok1 || ok2 )
121
{
122
// sort numbers before strings
123
return
ok1;
124
}
125
}
126
127
return
qgsVariantLessThan
( val1, val2 );
128
}
129
130
//
131
// QgsTreeWidgetItemObject
132
//
133
134
QgsTreeWidgetItemObject::QgsTreeWidgetItemObject
(
int
type )
135
:
QgsTreeWidgetItem
( type )
136
{}
137
138
QgsTreeWidgetItemObject::QgsTreeWidgetItemObject
( QTreeWidget *parent,
int
type )
139
:
QgsTreeWidgetItem
( parent, type )
140
{}
141
142
// override setData to emit signal when edited. By default the itemChanged signal fires way too often
143
void
QgsTreeWidgetItemObject::setData
(
int
column,
int
role,
const
QVariant &value )
144
{
145
QgsTreeWidgetItem::setData( column, role, value );
146
if
( role == Qt::EditRole )
147
{
148
emit
itemEdited
(
this
, column );
149
}
150
}
QgsTreeWidgetItemObject::itemEdited
void itemEdited(QTreeWidgetItem *item, int column)
Emitted when the contents of the column in the specified item has been edited by the user.
QgsTreeWidgetItemObject::QgsTreeWidgetItemObject
QgsTreeWidgetItemObject(int type=Type)
Constructor for QgsTreeWidgetItemObject.
Definition
qgstreewidgetitem.cpp:134
QgsTreeWidgetItemObject::setData
void setData(int column, int role, const QVariant &value) override
Sets the value for the item's column and role to the given value.
Definition
qgstreewidgetitem.cpp:143
QgsTreeWidgetItem::setAlwaysOnTopPriority
void setAlwaysOnTopPriority(int priority)
Sets a the item to display always on top of other items in the widget, regardless of the sort column ...
Definition
qgstreewidgetitem.cpp:67
QgsTreeWidgetItem::alwaysOnTopPriority
int alwaysOnTopPriority() const
Returns the item's priority when it is set to show always on top.
Definition
qgstreewidgetitem.cpp:72
QgsTreeWidgetItem::setSortData
void setSortData(int column, const QVariant &value)
Sets the custom sort data for a specified column.
Definition
qgstreewidgetitem.cpp:57
QgsTreeWidgetItem::operator<
bool operator<(const QTreeWidgetItem &other) const override
Returns true if this item should appear before another item when sorting a list of items.
Definition
qgstreewidgetitem.cpp:78
QgsTreeWidgetItem::sortData
QVariant sortData(int column) const
Returns the custom sort data for a specified column.
Definition
qgstreewidgetitem.cpp:62
QgsTreeWidgetItem::QgsTreeWidgetItem
QgsTreeWidgetItem(QTreeWidget *view, int type=Type)
Constructor for QgsTreeWidgetItem.
Definition
qgstreewidgetitem.cpp:25
QgsVariantUtils::isNull
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Definition
qgsvariantutils.cpp:176
qgsVariantLessThan
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
Definition
qgis.cpp:596
qgis.h
qgstreewidgetitem.h
qgsvariantutils.h
Generated on
for QGIS API Documentation by
1.17.0