fix5475.diff
python/gui/qgsattributeeditor.sip | ||
---|---|---|
6 | 6 |
#include <qgsattributeeditor.h> |
7 | 7 |
%End |
8 | 8 |
public: |
9 |
QgsAttributeEditor( QObject *parent ); |
|
10 |
static QWidget *createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value ); |
|
9 |
QgsAttributeEditor( QObject *parent, QgsVectorLayer *vl, int idx );
|
|
10 |
static QWidget *createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, qint64 fid, int idx, const QVariant &value );
|
|
11 | 11 |
static bool retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value ); |
12 | 12 |
static bool setValue( QWidget *widget, QgsVectorLayer *vl, int idx, const QVariant &value ); |
13 | 13 |
src/app/qgsattributedialog.cpp | ||
---|---|---|
136 | 136 |
QString myFieldName = vl->attributeDisplayName( it.key() ); |
137 | 137 |
int myFieldType = field.type(); |
138 | 138 | |
139 |
QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, 0, vl, it.key(), it.value() ); |
|
139 |
QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, 0, vl, mFeature->id(), it.key(), it.value() );
|
|
140 | 140 |
if ( !myWidget ) |
141 | 141 |
continue; |
142 | 142 | |
... | ... | |
187 | 187 |
if ( !myWidget ) |
188 | 188 |
continue; |
189 | 189 | |
190 |
QgsAttributeEditor::createAttributeEditor( mDialog, myWidget, vl, it.key(), it.value() ); |
|
190 |
QgsAttributeEditor::createAttributeEditor( mDialog, myWidget, vl, mFeature->id(), it.key(), it.value() );
|
|
191 | 191 | |
192 | 192 |
if ( vl->editType( it.key() ) != QgsVectorLayer::Immutable ) |
193 | 193 |
{ |
src/app/qgsmergeattributesdialog.cpp | ||
---|---|---|
119 | 119 |
QTableWidgetItem* attributeValItem = new QTableWidgetItem( attrs[idx].toString() ); |
120 | 120 |
attributeValItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); |
121 | 121 |
mTableWidget->setItem( i + 1, j, attributeValItem ); |
122 |
mTableWidget->setCellWidget( i + 1, j, QgsAttributeEditor::createAttributeEditor( mTableWidget, NULL, mVectorLayer, idx, attrs[idx] ) ); |
|
122 |
mTableWidget->setCellWidget( i + 1, j, QgsAttributeEditor::createAttributeEditor( mTableWidget, NULL, mVectorLayer, mFeatureList[i].id(), idx, attrs[idx] ) );
|
|
123 | 123 |
} |
124 | 124 |
} |
125 | 125 |
src/gui/attributetable/qgsattributetabledelegate.cpp | ||
---|---|---|
76 | 76 |
if ( !vl ) |
77 | 77 |
return NULL; |
78 | 78 | |
79 |
QWidget *w = QgsAttributeEditor::createAttributeEditor( parent, 0, vl, fieldIdx( index ), index.model()->data( index, Qt::EditRole ) ); |
|
79 |
QWidget *w = QgsAttributeEditor::createAttributeEditor( parent, 0, vl, featureId( index ), fieldIdx( index ), index.model()->data( index, Qt::EditRole ) );
|
|
80 | 80 | |
81 | 81 |
if ( parent ) |
82 | 82 |
{ |
src/gui/qgsattributeeditor.cpp | ||
---|---|---|
16 | 16 |
***************************************************************************/ |
17 | 17 | |
18 | 18 |
#include "qgsattributeeditor.h" |
19 |
#include <qgsvectorlayer.h> |
|
20 |
#include <qgsvectordataprovider.h>
|
|
21 |
#include <qgsuniquevaluerenderer.h>
|
|
22 |
#include <qgscategorizedsymbolrendererv2.h>
|
|
23 |
#include <qgssymbol.h>
|
|
24 |
#include <qgslonglongvalidator.h>
|
|
25 |
#include <qgsfieldvalidator.h>
|
|
26 |
#include <qgsmaplayerregistry.h>
|
|
27 |
#include <qgslogger.h>
|
|
19 | ||
20 |
#include "qgsvectorlayer.h"
|
|
21 |
#include "qgsvectordataprovider.h"
|
|
22 |
#include "qgsuniquevaluerenderer.h"
|
|
23 |
#include "qgscategorizedsymbolrendererv2.h"
|
|
24 |
#include "qgssymbol.h"
|
|
25 |
#include "qgslonglongvalidator.h"
|
|
26 |
#include "qgsfieldvalidator.h"
|
|
27 |
#include "qgsmaplayerregistry.h"
|
|
28 | 28 | |
29 | 29 |
#include <QPushButton> |
30 | 30 |
#include <QLineEdit> |
... | ... | |
42 | 42 |
#include <QSettings> |
43 | 43 |
#include <QDir> |
44 | 44 |
#include <QUuid> |
45 |
#include <QMenu> |
|
45 | 46 | |
46 | 47 |
void QgsAttributeEditor::selectFileName() |
47 | 48 |
{ |
... | ... | |
101 | 102 |
} |
102 | 103 |
} |
103 | 104 | |
105 |
void QgsAttributeEditor::resetToDefault() |
|
106 |
{ |
|
107 |
QWidget *w = qobject_cast<QWidget *>( parent() ); |
|
108 |
if ( w ) |
|
109 |
{ |
|
110 |
QVariant v( mLayer->dataProvider()->defaultValue( mIdx ) ); |
|
111 |
setValue( w, mLayer, mIdx, v ); |
|
112 |
} |
|
113 |
} |
|
114 | ||
104 | 115 |
QComboBox *QgsAttributeEditor::comboBox( QWidget *editor, QWidget *parent ) |
105 | 116 |
{ |
106 | 117 |
QComboBox *cb = NULL; |
... | ... | |
112 | 123 |
return cb; |
113 | 124 |
} |
114 | 125 | |
115 |
QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value ) |
|
126 |
QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, QgsFeatureId fid, int idx, const QVariant &value )
|
|
116 | 127 |
{ |
117 | 128 |
if ( !vl ) |
118 | 129 |
return NULL; |
... | ... | |
122 | 133 |
const QgsField &field = vl->pendingFields()[idx]; |
123 | 134 |
QVariant::Type myFieldType = field.type(); |
124 | 135 | |
136 |
QgsAttributeEditor *ae = new QgsAttributeEditor( 0, vl, idx ); |
|
137 | ||
125 | 138 |
switch ( editType ) |
126 | 139 |
{ |
127 | 140 |
case QgsVectorLayer::UniqueValues: |
... | ... | |
471 | 484 |
if ( pb ) |
472 | 485 |
{ |
473 | 486 |
if ( editType == QgsVectorLayer::FileName ) |
474 |
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) );
|
|
487 |
connect( pb, SIGNAL( clicked() ), ae, SLOT( selectFileName() ) );
|
|
475 | 488 |
if ( editType == QgsVectorLayer::Calendar ) |
476 |
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectDate() ) );
|
|
489 |
connect( pb, SIGNAL( clicked() ), ae, SLOT( selectDate() ) );
|
|
477 | 490 |
} |
478 | 491 |
} |
479 | 492 |
break; |
... | ... | |
481 | 494 | |
482 | 495 |
setValue( myWidget, vl, idx, value ); |
483 | 496 | |
497 |
ae->setParent( myWidget ); |
|
498 | ||
499 |
if ( FID_IS_NEW( fid ) ) |
|
500 |
myWidget->installEventFilter( ae ); |
|
501 | ||
484 | 502 |
return myWidget; |
485 | 503 |
} |
486 | 504 | |
... | ... | |
588 | 606 |
text = le->text(); |
589 | 607 |
} |
590 | 608 | |
591 |
switch ( theField.type() ) |
|
609 |
if ( !text.isEmpty() && text == vl->dataProvider()->defaultValue( idx ).toString() ) |
|
610 |
{ |
|
611 |
value = QVariant( text ); |
|
612 |
modified = true; |
|
613 |
} |
|
614 |
else |
|
592 | 615 |
{ |
593 |
case QVariant::Int:
|
|
616 |
switch ( theField.type() )
|
|
594 | 617 |
{ |
595 |
bool ok; |
|
596 |
int myIntValue = text.toInt( &ok ); |
|
597 |
if ( ok && !text.isEmpty() ) |
|
598 |
{ |
|
599 |
value = QVariant( myIntValue ); |
|
600 |
modified = true; |
|
601 |
} |
|
602 |
else if ( modified ) |
|
618 |
case QVariant::Int: |
|
603 | 619 |
{ |
604 |
value = QVariant(); |
|
620 |
bool ok; |
|
621 |
int myIntValue = text.toInt( &ok ); |
|
622 |
if ( ok && !text.isEmpty() ) |
|
623 |
{ |
|
624 |
value = QVariant( myIntValue ); |
|
625 |
modified = true; |
|
626 |
} |
|
627 |
else if ( modified ) |
|
628 |
{ |
|
629 |
value = QVariant(); |
|
630 |
} |
|
605 | 631 |
} |
606 |
} |
|
607 |
break; |
|
608 |
case QVariant::LongLong: |
|
609 |
{ |
|
610 |
bool ok; |
|
611 |
qlonglong myLongValue = text.toLong( &ok ); |
|
612 |
if ( ok && !text.isEmpty() ) |
|
632 |
break; |
|
633 |
case QVariant::LongLong: |
|
613 | 634 |
{ |
614 |
value = QVariant( myLongValue ); |
|
615 |
modified = true; |
|
635 |
bool ok; |
|
636 |
qlonglong myLongValue = text.toLong( &ok ); |
|
637 |
if ( ok && !text.isEmpty() ) |
|
638 |
{ |
|
639 |
value = QVariant( myLongValue ); |
|
640 |
modified = true; |
|
641 |
} |
|
642 |
else if ( modified ) |
|
643 |
{ |
|
644 |
value = QVariant(); |
|
645 |
} |
|
616 | 646 |
} |
617 |
else if ( modified )
|
|
647 |
case QVariant::Double:
|
|
618 | 648 |
{ |
619 |
value = QVariant();
|
|
620 |
}
|
|
621 |
}
|
|
622 |
case QVariant::Double:
|
|
623 |
{
|
|
624 |
bool ok;
|
|
625 |
double myDblValue = text.toDouble( &ok );
|
|
626 |
if ( ok && !text.isEmpty() )
|
|
627 |
{ |
|
628 |
value = QVariant( myDblValue );
|
|
629 |
modified = true;
|
|
649 |
bool ok;
|
|
650 |
double myDblValue = text.toDouble( &ok );
|
|
651 |
if ( ok && !text.isEmpty() )
|
|
652 |
{
|
|
653 |
value = QVariant( myDblValue );
|
|
654 |
modified = true;
|
|
655 |
}
|
|
656 |
else if ( modified )
|
|
657 |
{
|
|
658 |
value = QVariant();
|
|
659 |
}
|
|
630 | 660 |
} |
631 |
else if ( modified ) |
|
661 |
break; |
|
662 |
case QVariant::Date: |
|
632 | 663 |
{ |
633 |
value = QVariant(); |
|
664 |
QDate myDateValue = QDate::fromString( text, Qt::ISODate ); |
|
665 |
if ( myDateValue.isValid() && !text.isEmpty() ) |
|
666 |
{ |
|
667 |
value = myDateValue; |
|
668 |
modified = true; |
|
669 |
} |
|
670 |
else if ( modified ) |
|
671 |
{ |
|
672 |
value = QVariant(); |
|
673 |
} |
|
634 | 674 |
} |
635 |
} |
|
636 |
break; |
|
637 |
case QVariant::Date: |
|
638 |
{ |
|
639 |
QDate myDateValue = QDate::fromString( text, Qt::ISODate ); |
|
640 |
if ( myDateValue.isValid() && !text.isEmpty() ) |
|
641 |
{ |
|
642 |
value = myDateValue; |
|
675 |
break; |
|
676 |
default: //string |
|
643 | 677 |
modified = true; |
644 |
} |
|
645 |
else if ( modified ) |
|
646 |
{ |
|
647 |
value = QVariant(); |
|
648 |
} |
|
678 |
value = QVariant( text ); |
|
679 |
break; |
|
649 | 680 |
} |
650 |
break; |
|
651 |
default: //string |
|
652 |
modified = true; |
|
653 |
value = QVariant( text ); |
|
654 |
break; |
|
655 | 681 |
} |
656 | 682 | |
657 | 683 |
return modified; |
... | ... | |
794 | 820 | |
795 | 821 |
return true; |
796 | 822 |
} |
823 | ||
824 |
bool QgsAttributeEditor::eventFilter( QObject *obj, QEvent *event ) |
|
825 |
{ |
|
826 |
QContextMenuEvent *cme = dynamic_cast<QContextMenuEvent *>( event ); |
|
827 |
if ( !cme ) |
|
828 |
return false; |
|
829 | ||
830 |
QLineEdit *le = qobject_cast<QLineEdit *>( obj ); |
|
831 |
if ( le ) |
|
832 |
{ |
|
833 |
QMenu *menu = le->createStandardContextMenu(); |
|
834 |
connect( menu->addAction( tr( "Reset to default" ) ), SIGNAL( triggered() ), this, SLOT( resetToDefault() ) ); |
|
835 |
menu->setAttribute( Qt::WA_DeleteOnClose ); |
|
836 |
menu->popup( cme->globalPos() ); |
|
837 |
return true; |
|
838 |
} |
|
839 | ||
840 |
return false; |
|
841 |
} |
src/gui/qgsattributeeditor.h | ||
---|---|---|
17 | 17 |
#ifndef QGSATTRIBUTEEDITOR_H |
18 | 18 |
#define QGSATTRIBUTEEDITOR_H |
19 | 19 | |
20 |
#include "qgsfeature.h" |
|
21 | ||
20 | 22 |
#include <QVariant> |
21 | 23 | |
22 | 24 |
class QObject; |
... | ... | |
30 | 32 |
Q_OBJECT |
31 | 33 | |
32 | 34 |
public: |
33 |
QgsAttributeEditor( QObject *parent ) : QObject( parent ) {}; |
|
34 |
static QWidget *createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value ); |
|
35 |
QgsAttributeEditor( QObject *parent, QgsVectorLayer *vl, int idx ) |
|
36 |
: QObject( parent ) |
|
37 |
, mLayer( vl ) |
|
38 |
, mIdx( idx ) |
|
39 |
{} |
|
40 |
static QWidget *createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, QgsFeatureId fid, int idx, const QVariant &value ); |
|
35 | 41 |
static bool retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value ); |
36 | 42 |
static bool setValue( QWidget *widget, QgsVectorLayer *vl, int idx, const QVariant &value ); |
37 | 43 | |
38 | 44 |
private: |
39 | 45 |
static QComboBox *comboBox( QWidget *editor, QWidget *parent ); |
46 |
bool eventFilter( QObject *obj, QEvent *event ); |
|
47 | ||
48 |
QgsVectorLayer *mLayer; |
|
49 |
int mIdx; |
|
40 | 50 | |
41 | 51 |
public slots: |
42 | 52 |
void selectFileName(); |
43 | 53 |
void selectDate(); |
54 |
void resetToDefault(); |
|
44 | 55 |
}; |
45 | 56 | |
46 | ||
47 | 57 |
#endif |
src/gui/qgsformannotationitem.cpp | ||
---|---|---|
98 | 98 |
QWidget* attWidget = widget->findChild<QWidget*>( fieldIt->name() ); |
99 | 99 |
if ( attWidget ) |
100 | 100 |
{ |
101 |
QgsAttributeEditor::createAttributeEditor( widget, attWidget, mVectorLayer, attIt.key(), attIt.value() ); |
|
101 |
QgsAttributeEditor::createAttributeEditor( widget, attWidget, mVectorLayer, mFeature, attIt.key(), attIt.value() );
|
|
102 | 102 |
} |
103 | 103 |
} |
104 | 104 |
} |