本文整理汇总了C++中DynamicObject::removeAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicObject::removeAttribute方法的具体用法?C++ DynamicObject::removeAttribute怎么用?C++ DynamicObject::removeAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicObject
的用法示例。
在下文中一共展示了DynamicObject::removeAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeAttributeByPath
bool DynamicObjectImp::removeAttributeByPath(QStringList pathComponents)
{
if (pathComponents.size() == 0)
{
return false;
}
DynamicObject* pParent = dynamic_cast<DynamicObject*>(this);
string attributeToRemove = pathComponents.last().toStdString();
if (pathComponents.size() > 1)
{
pathComponents.removeLast();
DataVariant& parentVar = getAttributeByPath(pathComponents);
pParent = dv_cast<DynamicObject>(&parentVar);
}
if (pParent == NULL)
{
return false;
}
return pParent->removeAttribute(attributeToRemove);
}
示例2: removeField
void FeatureClassDlg::removeField()
{
QList<QTreeWidgetItem*> items = mpFieldTree->selectedItems();
for (int i = 0; i < items.count(); ++i)
{
QTreeWidgetItem* pItem = items[i];
if (pItem != NULL)
{
QString fieldName = pItem->text(0);
// Remove the field from the member DynamicObject
DynamicObject* pClass = getCurrentFeatureClass();
if (pClass != NULL)
{
pClass->removeAttribute(fieldName.toStdString());
}
// Remove the item from the tree widget
delete pItem;
}
}
}
示例3: setFieldData
void FeatureClassDlg::setFieldData(QTreeWidgetItem* pItem, int column)
{
if (pItem == NULL)
{
return;
}
DynamicObject* pClass = getCurrentFeatureClass();
if (pClass == NULL)
{
return;
}
QString fieldName = pItem->text(0);
if (column == 0) // Name
{
QString oldFieldName = pItem->data(column, Qt::UserRole).toString();
if (fieldName == oldFieldName)
{
return;
}
if (mpFieldTree->findItems(fieldName, Qt::MatchExactly, column).count() > 1)
{
QMessageBox::warning(this, windowTitle(), "Another field exists with the same name. "
"Please choose a unique name for the field.");
pItem->setText(column, oldFieldName);
return;
}
DataVariant field = pClass->getAttribute(oldFieldName.toStdString());
pClass->removeAttribute(oldFieldName.toStdString());
pClass->setAttribute(fieldName.toStdString(), field);
pItem->setData(column, Qt::UserRole, QVariant(fieldName));
}
else // Type or Value
{
QString fieldType = pItem->text(1);
QString fieldValue = pItem->text(2);
if (column == 1) // Type
{
// If the type changed, ensure that the value is valid with the new type and reset the value if necessary
QString validateString = fieldValue;
int pos = 0;
if (fieldType == "int")
{
QIntValidator validator(this);
if (validator.validate(validateString, pos) != QValidator::Acceptable)
{
pItem->setText(2, "0");
return; // Return since this method will be called again as a result to changing the value text
}
}
else if (fieldType == "double")
{
QDoubleValidator validator(this);
if (validator.validate(fieldValue, pos) != QValidator::Acceptable)
{
pItem->setText(2, "0.0");
return; // Return since this method will be called again as a result to changing the value text
}
}
}
DataVariant field;
if (fieldType == "int")
{
int intValue = fieldValue.toInt();
field = DataVariant(intValue);
}
else if (fieldType == "double")
{
double doubleValue = fieldValue.toDouble();
field = DataVariant(doubleValue);
}
else if (fieldType == "string")
{
std::string stringValue = fieldValue.toStdString();
field = DataVariant(stringValue);
}
pClass->setAttribute(fieldName.toStdString(), field);
}
}