Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add QgsTableWidgetItem for easier sorting of checkbox tables
- Loading branch information
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*************************************************************************** | ||
qgstablewidgetitem.sip - QgsTableWidgetItem | ||
|
||
--------------------- | ||
begin : 27.3.2016 | ||
copyright : (C) 2016 by Matthias Kuhn, OPENGIS.ch | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
class QgsTableWidgetItem : QTableWidgetItem | ||
{ | ||
%TypeHeaderCode | ||
#include "qgstablewidgetitem.h" | ||
%End | ||
|
||
public: | ||
QgsTableWidgetItem(); | ||
QgsTableWidgetItem( const QString& text ); | ||
|
||
/** | ||
* Set the role by which the items should be sorted. | ||
* By default this will be set to Qt::DisplayRole | ||
*/ | ||
void setSortRole( int role ); | ||
/** | ||
* Get the role by which the items should be sorted. | ||
* By default this will be Qt::DisplayRole | ||
*/ | ||
int sortRole() const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*************************************************************************** | ||
qgstablewidgetitem.cpp - QgsTableWidgetItem | ||
--------------------- | ||
begin : 27.3.2016 | ||
copyright : (C) 2016 by Matthias Kuhn, OPENGIS.ch | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include "qgstablewidgetitem.h" | ||
|
||
QgsTableWidgetItem::QgsTableWidgetItem() | ||
: QTableWidgetItem() | ||
, mSortRole( Qt::DisplayRole ) | ||
{ | ||
} | ||
|
||
QgsTableWidgetItem::QgsTableWidgetItem( const QString& text ) | ||
: QTableWidgetItem( text ) | ||
, mSortRole( Qt::DisplayRole ) | ||
{ | ||
} | ||
|
||
void QgsTableWidgetItem::setSortRole( int role ) | ||
{ | ||
mSortRole = role; | ||
} | ||
|
||
int QgsTableWidgetItem::sortRole() const | ||
{ | ||
return mSortRole; | ||
} | ||
|
||
bool QgsTableWidgetItem::operator<( const QTableWidgetItem& other ) const | ||
{ | ||
#if QT_VERSION < 0x050000 | ||
return data( mSortRole ).toString() < other.data( mSortRole ).toString(); | ||
#else | ||
return data( mSortRole ) < other.data( mSortRole ); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*************************************************************************** | ||
qgstablewidgetitem.h - QgsTableWidgetItem | ||
--------------------- | ||
begin : 27.3.2016 | ||
copyright : (C) 2016 by Matthias Kuhn, OPENGIS.ch | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSTABLEWIDGETITEM_H | ||
#define QGSTABLEWIDGETITEM_H | ||
|
||
#include <QTableWidget> | ||
|
||
/** | ||
* This can be used like a regular QTableWidgetItem with the difference that a | ||
* specific role can be set to sort. | ||
*/ | ||
class GUI_EXPORT QgsTableWidgetItem : public QTableWidgetItem | ||
{ | ||
public: | ||
QgsTableWidgetItem(); | ||
/** | ||
* Creates a new table widget item with the specified text. | ||
*/ | ||
QgsTableWidgetItem( const QString& text ); | ||
|
||
|
||
/** | ||
* Set the role by which the items should be sorted. | ||
* By default this will be set to Qt::DisplayRole | ||
*/ | ||
void setSortRole( int role ); | ||
/** | ||
* Get the role by which the items should be sorted. | ||
* By default this will be Qt::DisplayRole | ||
*/ | ||
int sortRole() const; | ||
|
||
bool operator <( const QTableWidgetItem& other ) const override; | ||
|
||
private: | ||
int mSortRole; | ||
}; | ||
|
||
#endif // QGSTABLEWIDGETITEM_H |