|
17 | 17 | #include "qgsfield.h" |
18 | 18 | #include "qgsfield_p.h" |
19 | 19 | #include "qgis.h" |
| 20 | +#include "qgsapplication.h" |
20 | 21 |
|
21 | 22 | #include <QSettings> |
22 | 23 | #include <QDataStream> |
23 | 24 | #include <QtCore/qmath.h> |
| 25 | +#include <QIcon> |
24 | 26 |
|
25 | 27 | /*************************************************************************** |
26 | 28 | * This class is considered CRITICAL and any change MUST be accompanied with |
@@ -437,6 +439,61 @@ bool QgsFields::operator==( const QgsFields &other ) const |
437 | 439 | return d->fields == other.d->fields; |
438 | 440 | } |
439 | 441 |
|
| 442 | +QIcon QgsFields::iconForField( int fieldIdx ) const |
| 443 | +{ |
| 444 | + static QIcon intIcon; |
| 445 | + if ( intIcon.isNull() ) |
| 446 | + intIcon = QgsApplication::getThemeIcon( "/mIconFieldInteger.svg" ); |
| 447 | + static QIcon floatIcon; |
| 448 | + if ( floatIcon.isNull() ) |
| 449 | + floatIcon = QgsApplication::getThemeIcon( "/mIconFieldFloat.svg" ); |
| 450 | + static QIcon stringIcon; |
| 451 | + if ( stringIcon.isNull() ) |
| 452 | + stringIcon = QgsApplication::getThemeIcon( "/mIconFieldText.svg" ); |
| 453 | + static QIcon dateIcon; |
| 454 | + if ( dateIcon.isNull() ) |
| 455 | + dateIcon = QgsApplication::getThemeIcon( "/mIconFieldDate.svg" ); |
| 456 | + static QIcon dateTimeIcon; |
| 457 | + if ( dateTimeIcon.isNull() ) |
| 458 | + dateTimeIcon = QgsApplication::getThemeIcon( "/mIconFieldDateTime.svg" ); |
| 459 | + static QIcon timeIcon; |
| 460 | + if ( timeIcon.isNull() ) |
| 461 | + timeIcon = QgsApplication::getThemeIcon( "/mIconFieldTime.svg" ); |
| 462 | + |
| 463 | + switch ( d->fields.at( fieldIdx ).field.type() ) |
| 464 | + { |
| 465 | + case QVariant::Int: |
| 466 | + case QVariant::UInt: |
| 467 | + case QVariant::LongLong: |
| 468 | + case QVariant::ULongLong: |
| 469 | + { |
| 470 | + return intIcon; |
| 471 | + } |
| 472 | + case QVariant::Double: |
| 473 | + { |
| 474 | + return floatIcon; |
| 475 | + } |
| 476 | + case QVariant::String: |
| 477 | + { |
| 478 | + return stringIcon; |
| 479 | + } |
| 480 | + case QVariant::Date: |
| 481 | + { |
| 482 | + return dateIcon; |
| 483 | + } |
| 484 | + case QVariant::DateTime: |
| 485 | + { |
| 486 | + return dateTimeIcon; |
| 487 | + } |
| 488 | + case QVariant::Time: |
| 489 | + { |
| 490 | + return timeIcon; |
| 491 | + } |
| 492 | + default: |
| 493 | + return QIcon(); |
| 494 | + } |
| 495 | +} |
| 496 | + |
440 | 497 | /*************************************************************************** |
441 | 498 | * This class is considered CRITICAL and any change MUST be accompanied with |
442 | 499 | * full unit tests in testqgsfields.cpp. |
|
0 commit comments