ALWAYS_INLINE void Element::setAttributeInternal(size_t index, const QualifiedName& name, const AtomicString& newValue, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute) { if (newValue.isNull()) { if (index != kNotFound) removeAttributeInternal(index, inSynchronizationOfLazyAttribute); return; } if (index == kNotFound) { appendAttributeInternal(name, newValue, inSynchronizationOfLazyAttribute); return; } const Attribute& existingAttribute = elementData()->attributes().at(index); QualifiedName existingAttributeName = existingAttribute.name(); if (newValue == existingAttribute.value()) return; if (!inSynchronizationOfLazyAttribute) willModifyAttribute(existingAttributeName, existingAttribute.value(), newValue); ensureUniqueElementData().attributes().at(index).setValue(newValue); if (!inSynchronizationOfLazyAttribute) attributeChanged(existingAttributeName, newValue); }
void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const QgsFeatureRequest &request, QgsAttributeEditorContext context ) { mEditorContext = context; connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ), this, SLOT( viewWillShowContextMenu( QMenu*, QModelIndex ) ) ); initLayerCache( layer ); initModels( mapCanvas, request ); mTableView->setModel( mFilterModel ); mFeatureList->setModel( mFeatureListModel ); mAttributeForm = new QgsAttributeForm( layer, QgsFeature(), mEditorContext ); mAttributeEditorScrollArea->setLayout( new QGridLayout() ); mAttributeEditorScrollArea->layout()->addWidget( mAttributeForm ); mAttributeEditorScrollArea->setWidget( mAttributeForm ); mAttributeForm->hideButtonBox(); connect( mAttributeForm, SIGNAL( attributeChanged( QString, QVariant ) ), this, SLOT( featureFormAttributeChanged() ) ); if ( mFeatureListPreviewButton->defaultAction() ) mFeatureList->setDisplayExpression( mDisplayExpression ); else columnBoxInit(); mFeatureList->setEditSelection( QgsFeatureIds() << mFeatureListModel->idxToFid( mFeatureListModel->index( 0, 0 ) ) ); }
void ItemModel::set_attribute(const QString &attribute) { if (attribute != attribute_) { attribute_ = attribute; emit attributeChanged(); } }
void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const QgsFeatureRequest &request, const QgsAttributeEditorContext &context ) { mEditorContext = context; connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ), this, SLOT( viewWillShowContextMenu( QMenu*, QModelIndex ) ) ); initLayerCache( layer, !request.filterRect().isNull() ); initModels( mapCanvas, request ); mConditionalFormatWidget->setLayer( layer ); mTableView->setModel( mFilterModel ); mFeatureList->setModel( mFeatureListModel ); mAttributeForm = new QgsAttributeForm( layer, QgsFeature(), mEditorContext ); if ( !mAttributeEditorScrollArea->layout() ) mAttributeEditorScrollArea->setLayout( new QGridLayout() ); mAttributeEditorScrollArea->layout()->addWidget( mAttributeForm ); mAttributeEditorScrollArea->setWidget( mAttributeForm ); mAttributeForm->hideButtonBox(); connect( mAttributeForm, SIGNAL( attributeChanged( QString, QVariant ) ), this, SLOT( featureFormAttributeChanged() ) ); connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) ); if ( mFeatureListPreviewButton->defaultAction() ) mFeatureList->setDisplayExpression( mDisplayExpression ); else columnBoxInit(); // This slows down load of the attribute table heaps and uses loads of memory. //mTableView->resizeColumnsToContents(); mFeatureList->setEditSelection( QgsFeatureIds() << mFeatureListModel->idxToFid( mFeatureListModel->index( 0, 0 ) ) ); }
void VariantPropertyManager::setAttribute(QtProperty *property, const QString &attribute, const QVariant &val) { if (mValues.contains(property)) { if (attribute == QLatin1String("filter")) { if (val.type() != QVariant::String && !val.canConvert(QVariant::String)) return; QString str = val.toString(); Data d = mValues[property]; if (d.filter == str) return; d.filter = str; mValues[property] = d; emit attributeChanged(property, attribute, str); } return; } if (mStringAttributes.contains(property)) { if (attribute == mSuggestionsAttribute) { mStringAttributes[property].suggestions = val.toStringList(); return; } if (attribute == mMultilineAttribute) { mStringAttributes[property].multiline = val.toBool(); return; } } QtVariantPropertyManager::setAttribute(property, attribute, val); }
void Element::setAttributeMap(PassRefPtr<NamedAttrMap> list) { document()->incDOMTreeVersion(); // If setting the whole map changes the id attribute, we need to call updateId. Attribute* oldId = namedAttrMap ? namedAttrMap->getAttributeItem(idAttr) : 0; Attribute* newId = list ? list->getAttributeItem(idAttr) : 0; if (oldId || newId) updateId(oldId ? oldId->value() : nullAtom, newId ? newId->value() : nullAtom); if (namedAttrMap) namedAttrMap->m_element = 0; namedAttrMap = list; if (namedAttrMap) { namedAttrMap->m_element = this; unsigned len = namedAttrMap->length(); for (unsigned i = 0; i < len; i++) attributeChanged(namedAttrMap->m_attributes[i].get()); // FIXME: What about attributes that were in the old map that are not in the new map? } }
void Element::setAttribute(const AtomicString& name, const AtomicString& value, ExceptionCode& ec) { if (!Document::isValidName(name)) { ec = INVALID_CHARACTER_ERR; return; } const AtomicString& localName = (shouldIgnoreAttributeCase(this) && !name.string().impl()->isLower()) ? AtomicString(name.string().lower()) : name; // allocate attributemap if necessary Attribute* old = attributes(false)->getAttributeItem(localName, false); document()->incDOMTreeVersion(); if (localName == idAttr.localName()) updateId(old ? old->value() : nullAtom, value); if (old && value.isNull()) namedAttrMap->removeAttribute(old->name()); else if (!old && !value.isNull()) namedAttrMap->addAttribute(createAttribute(QualifiedName(nullAtom, localName, nullAtom), value)); else if (old && !value.isNull()) { old->setValue(value); attributeChanged(old); } }
void Element::appendAttributeInternal(const QualifiedName& name, const AtomicString& value, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute) { if (!inSynchronizationOfLazyAttribute) willModifyAttribute(name, nullAtom, value); ensureUniqueElementData().attributes().append(name, value); if (!inSynchronizationOfLazyAttribute) attributeChanged(name, value); }
void Function::adjustAttribute(qreal fraction, int attributeIndex) { if (attributeIndex >= m_attributes.count()) return; //qDebug() << Q_FUNC_INFO << "idx:" << attributeIndex << ", val:" << fraction; m_attributes[attributeIndex].value = CLAMP(fraction, 0.0, 1.0); emit attributeChanged(attributeIndex, m_attributes[attributeIndex].value); }
int QtVariantPropertyManager::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QtAbstractPropertyManager::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: valueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QVariant(*)>(_a[2]))); break; case 1: attributeChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QVariant(*)>(_a[3]))); break; case 2: setValue((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QVariant(*)>(_a[2]))); break; case 3: setAttribute((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QVariant(*)>(_a[3]))); break; case 4: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 5: d_func()->slotRangeChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< int(*)>(_a[3]))); break; case 6: d_func()->slotSingleStepChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 7: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2]))); break; case 8: d_func()->slotRangeChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2])),(*reinterpret_cast< double(*)>(_a[3]))); break; case 9: d_func()->slotSingleStepChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2]))); break; case 10: d_func()->slotDecimalsChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 11: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break; case 12: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 13: d_func()->slotRegExpChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QRegExp(*)>(_a[2]))); break; case 14: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QDate(*)>(_a[2]))); break; case 15: d_func()->slotRangeChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QDate(*)>(_a[2])),(*reinterpret_cast< const QDate(*)>(_a[3]))); break; case 16: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QTime(*)>(_a[2]))); break; case 17: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QDateTime(*)>(_a[2]))); break; case 18: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QKeySequence(*)>(_a[2]))); break; case 19: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QChar(*)>(_a[2]))); break; case 20: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QLocale(*)>(_a[2]))); break; case 21: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QPoint(*)>(_a[2]))); break; case 22: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QPointF(*)>(_a[2]))); break; case 23: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QSize(*)>(_a[2]))); break; case 24: d_func()->slotRangeChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QSize(*)>(_a[2])),(*reinterpret_cast< const QSize(*)>(_a[3]))); break; case 25: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QSizeF(*)>(_a[2]))); break; case 26: d_func()->slotRangeChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QSizeF(*)>(_a[2])),(*reinterpret_cast< const QSizeF(*)>(_a[3]))); break; case 27: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QRect(*)>(_a[2]))); break; case 28: d_func()->slotConstraintChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QRect(*)>(_a[2]))); break; case 29: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QRectF(*)>(_a[2]))); break; case 30: d_func()->slotConstraintChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QRectF(*)>(_a[2]))); break; case 31: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QColor(*)>(_a[2]))); break; case 32: d_func()->slotEnumNamesChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QStringList(*)>(_a[2]))); break; case 33: d_func()->slotEnumIconsChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QMap<int,QIcon>(*)>(_a[2]))); break; case 34: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QSizePolicy(*)>(_a[2]))); break; case 35: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QFont(*)>(_a[2]))); break; case 36: d_func()->slotValueChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QCursor(*)>(_a[2]))); break; case 37: d_func()->slotFlagNamesChanged((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< const QStringList(*)>(_a[2]))); break; case 38: d_func()->slotPropertyInserted((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< QtProperty*(*)>(_a[2])),(*reinterpret_cast< QtProperty*(*)>(_a[3]))); break; case 39: d_func()->slotPropertyRemoved((*reinterpret_cast< QtProperty*(*)>(_a[1])),(*reinterpret_cast< QtProperty*(*)>(_a[2]))); break; default: ; } _id -= 40; } return _id; }
void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const QgsFeatureRequest &request, const QgsAttributeEditorContext &context ) { if ( !layer ) return; mEditorContext = context; connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ), this, SLOT( viewWillShowContextMenu( QMenu*, QModelIndex ) ) ); mTableView->horizontalHeader()->setContextMenuPolicy( Qt::CustomContextMenu ); connect( mTableView->horizontalHeader(), SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( showViewHeaderMenu( QPoint ) ) ); connect( mTableView, SIGNAL( columnResized( int, int ) ), this, SLOT( tableColumnResized( int, int ) ) ); initLayerCache( layer, !request.filterRect().isNull() ); initModels( mapCanvas, request ); mConditionalFormatWidget->setLayer( layer ); mTableView->setModel( mFilterModel ); mFeatureList->setModel( mFeatureListModel ); delete mAttributeForm; mAttributeForm = new QgsAttributeForm( layer, QgsFeature(), mEditorContext ); if ( !context.parentContext() ) { mAttributeEditorScrollArea = new QScrollArea(); mAttributeEditorScrollArea->setWidgetResizable( true ); mAttributeEditor->layout()->addWidget( mAttributeEditorScrollArea ); mAttributeEditorScrollArea->setWidget( mAttributeForm ); } else { mAttributeEditor->layout()->addWidget( mAttributeForm ); } connect( mAttributeForm, SIGNAL( attributeChanged( QString, QVariant ) ), this, SLOT( featureFormAttributeChanged() ) ); connect( mAttributeForm, SIGNAL( modeChanged( QgsAttributeForm::Mode ) ), this, SIGNAL( formModeChanged( QgsAttributeForm::Mode ) ) ); connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) ); connect( mAttributeForm, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ), this, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ) ); connect( mFilterModel, SIGNAL( sortColumnChanged( int, Qt::SortOrder ) ), this, SLOT( onSortColumnChanged() ) ); if ( mFeatureListPreviewButton->defaultAction() ) mFeatureList->setDisplayExpression( mDisplayExpression ); else columnBoxInit(); // This slows down load of the attribute table heaps and uses loads of memory. //mTableView->resizeColumnsToContents(); mFeatureList->setEditSelection( QgsFeatureIds() << mFeatureListModel->idxToFid( mFeatureListModel->index( 0, 0 ) ) ); }
void Element::removeAttributeInternal(size_t index, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute) { MutableAttributeCollection attributes = ensureUniqueElementData().attributes(); ASSERT_WITH_SECURITY_IMPLICATION(index < attributes.size()); QualifiedName name = attributes[index].name(); AtomicString valueBeingRemoved = attributes[index].value(); if (!inSynchronizationOfLazyAttribute) { if (!valueBeingRemoved.isNull()) willModifyAttribute(name, valueBeingRemoved, nullAtom); } attributes.remove(index); if (!inSynchronizationOfLazyAttribute) attributeChanged(name, nullAtom); }
void Element::setAttribute(const QualifiedName& name, const AtomicString& value, ExceptionCode&) { document()->incDOMTreeVersion(); // allocate attributemap if necessary Attribute* old = attributes(false)->getAttributeItem(name); if (name == idAttr) updateId(old ? old->value() : nullAtom, value); if (old && value.isNull()) namedAttrMap->removeAttribute(name); else if (!old && !value.isNull()) namedAttrMap->addAttribute(createAttribute(name, value)); else if (old) { old->setValue(value); attributeChanged(old); } }
void SurfaceObserver::attrib_changed(MirSurfaceAttrib attribute, int value) { if (m_listener) { Q_EMIT attributeChanged(attribute, value); } }
void UMLAttribute::setName(const QString &name) { m_Name = name; emit attributeChanged(); UMLObject::emitModified(); }
void TestQgsAttributeForm::testFieldConstraint() { // make a temporary vector layer QString def = QStringLiteral( "Point?field=col0:integer" ); QgsVectorLayer* layer = new QgsVectorLayer( def, QStringLiteral( "test" ), QStringLiteral( "memory" ) ); layer->setEditorWidgetSetup( 0, QgsEditorWidgetSetup( QStringLiteral( "TextEdit" ), QVariantMap() ) ); // add a feature to the vector layer QgsFeature ft( layer->dataProvider()->fields(), 1 ); ft.setAttribute( QStringLiteral( "col0" ), 0 ); // build a form for this feature QgsAttributeForm form( layer ); form.setFeature( ft ); // testing stuff QString validLabel = QStringLiteral( "col0<font color=\"green\">✔</font>" ); QString invalidLabel = QStringLiteral( "col0<font color=\"red\">✘</font>" ); QString warningLabel = QStringLiteral( "col0<font color=\"orange\">✘</font>" ); // set constraint layer->setConstraintExpression( 0, QString() ); // get wrapper QgsEditorWidgetWrapper *ww; ww = qobject_cast<QgsEditorWidgetWrapper*>( form.mWidgets[0] ); // no constraint so we expect a label with just the field name QLabel *label = form.mBuddyMap.value( ww->widget() ); QCOMPARE( label->text(), QString( "col0" ) ); // set a not null constraint layer->setConstraintExpression( 0, QStringLiteral( "col0 is not null" ) ); // build a form for this feature QgsAttributeForm form2( layer ); form2.setFeature( ft ); QSignalSpy spy( &form2, SIGNAL( attributeChanged( QString, QVariant ) ) ); ww = qobject_cast<QgsEditorWidgetWrapper*>( form2.mWidgets[0] ); label = form2.mBuddyMap.value( ww->widget() ); // set value to 1 ww->setValue( 1 ); QCOMPARE( spy.count(), 2 ); QCOMPARE( label->text(), validLabel ); // set value to null spy.clear(); ww->setValue( QVariant() ); QCOMPARE( spy.count(), 2 ); QCOMPARE( label->text(), invalidLabel ); // set value to 1 spy.clear(); ww->setValue( 1 ); QCOMPARE( spy.count(), 2 ); QCOMPARE( label->text(), validLabel ); // set a soft constraint layer->setConstraintExpression( 0, QStringLiteral( "col0 is not null" ) ); layer->setFieldConstraint( 0, QgsFieldConstraints::ConstraintExpression, QgsFieldConstraints::ConstraintStrengthSoft ); // build a form for this feature QgsAttributeForm form3( layer ); form3.setFeature( ft ); ww = qobject_cast<QgsEditorWidgetWrapper*>( form3.mWidgets[0] ); label = form3.mBuddyMap.value( ww->widget() ); // set value to 1 ww->setValue( 1 ); QCOMPARE( label->text(), validLabel ); // set value to null ww->setValue( QVariant() ); QCOMPARE( label->text(), warningLabel ); // set value to 1 ww->setValue( 1 ); QCOMPARE( label->text(), validLabel ); }
void TestQgsAttributeForm::testOKButtonStatus() { // make a temporary vector layer QString def = QStringLiteral( "Point?field=col0:integer" ); QgsVectorLayer* layer = new QgsVectorLayer( def, QStringLiteral( "test" ), QStringLiteral( "memory" ) ); // add a feature to the vector layer QgsFeature ft( layer->dataProvider()->fields(), 1 ); ft.setAttribute( QStringLiteral( "col0" ), 0 ); ft.setValid( true ); // set constraint layer->setConstraintExpression( 0, QString() ); // build a form for this feature QgsAttributeForm form( layer ); form.setFeature( ft ); QPushButton *okButton = form.mButtonBox->button( QDialogButtonBox::Ok ); // get wrapper QgsEditorWidgetWrapper *ww; ww = qobject_cast<QgsEditorWidgetWrapper*>( form.mWidgets[0] ); // testing stuff QSignalSpy spy1( &form, SIGNAL( attributeChanged( QString, QVariant ) ) ); QSignalSpy spy2( layer, SIGNAL( editingStarted() ) ); QSignalSpy spy3( layer, SIGNAL( editingStopped() ) ); // no constraint but layer not editable : OK button disabled QCOMPARE( layer->isEditable(), false ); QCOMPARE( okButton->isEnabled(), false ); // no constraint and editable layer : OK button enabled layer->startEditing(); QCOMPARE( spy2.count(), 1 ); QCOMPARE( layer->isEditable(), true ); QCOMPARE( okButton->isEnabled(), true ); // invalid constraint and editable layer : OK button disabled layer->setConstraintExpression( 0, QStringLiteral( "col0 = 0" ) ); QgsAttributeForm form2( layer ); form2.setFeature( ft ); ww = qobject_cast<QgsEditorWidgetWrapper*>( form2.mWidgets[0] ); okButton = form2.mButtonBox->button( QDialogButtonBox::Ok ); ww->setValue( 1 ); QCOMPARE( okButton->isEnabled(), false ); // valid constraint and editable layer : OK button enabled layer->setConstraintExpression( 0, QStringLiteral( "col0 = 2" ) ); QgsAttributeForm form3( layer ); form3.setFeature( ft ); ww = qobject_cast<QgsEditorWidgetWrapper*>( form3.mWidgets[0] ); okButton = form3.mButtonBox->button( QDialogButtonBox::Ok ); ww->setValue( 2 ); QCOMPARE( okButton->isEnabled(), true ); // valid constraint and not editable layer : OK button disabled layer->rollBack(); QCOMPARE( spy3.count(), 1 ); QCOMPARE( layer->isEditable(), false ); QCOMPARE( okButton->isEnabled(), false ); // set soft constraint layer->setFieldConstraint( 0, QgsFieldConstraints::ConstraintExpression, QgsFieldConstraints::ConstraintStrengthSoft ); QgsAttributeForm form4( layer ); form4.setFeature( ft ); ww = qobject_cast<QgsEditorWidgetWrapper*>( form4.mWidgets[0] ); okButton = form4.mButtonBox->button( QDialogButtonBox::Ok ); ww->setValue( 1 ); QVERIFY( !okButton->isEnabled() ); layer->startEditing(); // just a soft constraint, so OK should be enabled QVERIFY( okButton->isEnabled() ); layer->rollBack(); QVERIFY( !okButton->isEnabled() ); }
void TestQgsAttributeForm::testFieldMultiConstraints() { // make a temporary layer to check through QString def = QStringLiteral( "Point?field=col0:integer&field=col1:integer&field=col2:integer&field=col3:integer" ); QgsVectorLayer* layer = new QgsVectorLayer( def, QStringLiteral( "test" ), QStringLiteral( "memory" ) ); // add features to the vector layer QgsFeature ft( layer->dataProvider()->fields(), 1 ); ft.setAttribute( QStringLiteral( "col0" ), 0 ); ft.setAttribute( QStringLiteral( "col1" ), 1 ); ft.setAttribute( QStringLiteral( "col2" ), 2 ); ft.setAttribute( QStringLiteral( "col3" ), 3 ); // set constraints for each field layer->setConstraintExpression( 0, QString() ); layer->setConstraintExpression( 1, QString() ); layer->setConstraintExpression( 2, QString() ); layer->setConstraintExpression( 3, QString() ); // build a form for this feature QgsAttributeForm form( layer ); form.setFeature( ft ); // testing stuff QSignalSpy spy( &form, SIGNAL( attributeChanged( QString, QVariant ) ) ); QString val = QStringLiteral( "<font color=\"green\">✔</font>" ); QString inv = QStringLiteral( "<font color=\"red\">✘</font>" ); // get wrappers for each widget QgsEditorWidgetWrapper *ww0, *ww1, *ww2, *ww3; ww0 = qobject_cast<QgsEditorWidgetWrapper*>( form.mWidgets[0] ); ww1 = qobject_cast<QgsEditorWidgetWrapper*>( form.mWidgets[1] ); ww2 = qobject_cast<QgsEditorWidgetWrapper*>( form.mWidgets[2] ); ww3 = qobject_cast<QgsEditorWidgetWrapper*>( form.mWidgets[3] ); // get label for wrappers QLabel *label0 = form.mBuddyMap.value( ww0->widget() ); QLabel *label1 = form.mBuddyMap.value( ww1->widget() ); QLabel *label2 = form.mBuddyMap.value( ww2->widget() ); QLabel *label3 = form.mBuddyMap.value( ww3->widget() ); // no constraint so we expect a label with just the field name QCOMPARE( label0->text(), QString( "col0" ) ); QCOMPARE( label1->text(), QString( "col1" ) ); QCOMPARE( label2->text(), QString( "col2" ) ); QCOMPARE( label3->text(), QString( "col3" ) ); // update constraint layer->setConstraintExpression( 0, QStringLiteral( "col0 < (col1 * col2)" ) ); layer->setConstraintExpression( 1, QString() ); layer->setConstraintExpression( 2, QString() ); layer->setConstraintExpression( 3, QStringLiteral( "col0 = 2" ) ); QgsAttributeForm form2( layer ); form2.setFeature( ft ); ww0 = qobject_cast<QgsEditorWidgetWrapper*>( form2.mWidgets[0] ); ww1 = qobject_cast<QgsEditorWidgetWrapper*>( form2.mWidgets[1] ); ww2 = qobject_cast<QgsEditorWidgetWrapper*>( form2.mWidgets[2] ); ww3 = qobject_cast<QgsEditorWidgetWrapper*>( form2.mWidgets[3] ); label0 = form2.mBuddyMap.value( ww0->widget() ); label1 = form2.mBuddyMap.value( ww1->widget() ); label2 = form2.mBuddyMap.value( ww2->widget() ); label3 = form2.mBuddyMap.value( ww3->widget() ); QSignalSpy spy2( &form2, SIGNAL( attributeChanged( QString, QVariant ) ) ); // change value ww0->setValue( 2 ); // update col0 QCOMPARE( spy2.count(), 2 ); QCOMPARE( label0->text(), QString( "col0" + inv ) ); // 2 < ( 1 + 2 ) QCOMPARE( label1->text(), QString( "col1" ) ); QCOMPARE( label2->text(), QString( "col2" ) ); QCOMPARE( label3->text(), QString( "col3" + val ) ); // 2 = 2 // change value spy2.clear(); ww0->setValue( 1 ); // update col0 QCOMPARE( spy2.count(), 2 ); QCOMPARE( label0->text(), QString( "col0" + val ) ); // 1 < ( 1 + 2 ) QCOMPARE( label1->text(), QString( "col1" ) ); QCOMPARE( label2->text(), QString( "col2" ) ); QCOMPARE( label3->text(), QString( "col3" + inv ) ); // 2 = 1 }
void UMLAttribute::setVisibility(Uml::Visibility s) { m_Vis = s; emit attributeChanged(); UMLObject::emitModified(); }
inline void Element::attributeChangedFromParserOrByCloning(const QualifiedName& name, const AtomicString& newValue, AttributeModificationReason reason) { attributeChanged(name, newValue, reason); }