QVariant QtPropertyModel::data(const QModelIndex & index, int role /* = Qt::DisplayRole */) const { QVariant ret; QtPropertyData *data = itemFromIndex(index); if(NULL != data) { if(index.column() == 0) { switch(role) { case Qt::DisplayRole: case Qt::ToolTipRole: ret = data->GetName(); break; case Qt::FontRole: case Qt::BackgroundRole: case Qt::ForegroundRole: ret = data->data(role); break; default: break; } } else if(index.column() == 1) { ret = data->data(role); } } return ret; }
void QtPropertyModel::MergeProperty(QtPropertyData* data, QModelIndex const& parent) { if(NULL != data) { QtPropertyData *parentData = itemFromIndexInternal(parent); if(NULL != parentData) { parentData->MergeChild(data); } } }
void QtPropertyDataIntrospection::AddMember(const DAVA::IntrospectionMember *member, int hasAnyFlags, int hasNotAnyFlags) { void *memberObject = member->Data(object); const DAVA::MetaInfo *memberMetaInfo = member->Type(); const DAVA::IntrospectionInfo *memberIntrospection = memberMetaInfo->GetIntrospection(memberObject); bool isKeyedArchive = false; // keyed archive if(NULL != memberIntrospection && (memberIntrospection->Type() == DAVA::MetaInfo::Instance<DAVA::KeyedArchive>())) { QtPropertyDataDavaKeyedArcive *childData = new QtPropertyDataDavaKeyedArcive((DAVA::KeyedArchive *) memberObject); ChildAdd(member->Name(), childData); } // introspection else if(NULL != memberObject && NULL != memberIntrospection) { QtPropertyDataIntrospection *childData = new QtPropertyDataIntrospection(memberObject, memberIntrospection, hasAnyFlags, hasNotAnyFlags); ChildAdd(member->Name(), childData); } // any other value else { // pointer if(memberMetaInfo->IsPointer()) { QString s; QtPropertyData* childData = new QtPropertyData(s.sprintf("[%p] Pointer", memberObject)); childData->SetFlags(childData->GetFlags() | FLAG_IS_DISABLED); ChildAdd(member->Name(), childData); } // other value else { // collection if(member->Collection() && !isKeyedArchive) { QtPropertyDataIntroCollection *childCollection = new QtPropertyDataIntroCollection(memberObject, member->Collection(), hasAnyFlags, hasNotAnyFlags); ChildAdd(member->Name(), childCollection); } // variant else { QtPropertyDataDavaVariant *childData = new QtPropertyDataDavaVariant(member->Value(object)); if(member->Flags() & DAVA::INTROSPECTION_EDITOR_READONLY) { childData->SetFlags(childData->GetFlags() | FLAG_IS_NOT_EDITABLE); } ChildAdd(member->Name(), childData); childVariantMembers.insert(childData, member); } } } }
void QtPropertyModel::RemoveProperty(const QModelIndex &index) { QtPropertyData *data = itemFromIndex(index); if(NULL != data) { QtPropertyData *parentData = data->Parent(); if(NULL != parentData) { parentData->ChildRemove(data); } } }
bool QtPropertyModel::setData(const QModelIndex & index, const QVariant & value, int role /* = Qt::EditRole */) { bool ret = false; QtPropertyData *data = itemFromIndex(index); if(NULL != data && index.column() == 1) { ret = data->setData(value, role); } return ret; }
QVariant QtPropertyData::GetValue() const { QtPropertyData *self = const_cast<QtPropertyData*>(this); if(curValue.isValid() || !curValue.isNull()) { self->UpdateValue(); } self->BuildCurrentValue(); return curValue; }
int QtPropertyModel::rowCount(const QModelIndex & parent /* = QModelIndex() */) const { int count = 0; QtPropertyData *data = itemFromIndexInternal(parent); if(NULL != data) { count = data->ChildCount(); } return count; }
void QtPropertyModel::UpdateStructureInternal(const QModelIndex &i) { QtPropertyData *data = itemFromIndexInternal(i); if(NULL != data) { data->UpdateValue(); for(int row = 0; row < rowCount(i); ++row) { UpdateStructureInternal(index(row, 0, i)); } } }
QModelIndex QtPropertyModel::InsertProperty(const QString &name, QtPropertyData* data, int row, const QModelIndex &parent /* = QModelIndex() */) { if(NULL != data) { QtPropertyData *parentData = itemFromIndexInternal(parent); if(NULL != parentData) { parentData->ChildInsert(name, data, row); } } return indexFromItem(data); }
void QtPropertyItemDelegate::hideAllChildOptionalWidgets(QtPropertyData* data) { for(int i = 0; i < data->ChildCount(); i++) { QPair<QString, QtPropertyData *> childPair = data->ChildGet(i); QtPropertyData *childData = childPair.second; for (int j = 0; j < childData->GetOWCount(); j++) { childData->GetOW(j)->widget->hide(); } hideAllChildOptionalWidgets(childData); } }
QtPropertyData* QtPropertyModel::itemFromIndex(const QModelIndex & index) const { QtPropertyData *ret = NULL; if(index.isValid() && index.model() == this) { QtPropertyData *parent = static_cast<QtPropertyData *>(index.internalPointer()); if(NULL != parent) { ret = parent->ChildGet(index.row()); } } return ret; }
void QtPropertyItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { const QtPropertyModel *propertyModel = dynamic_cast<const QtPropertyModel *>(index.model()); if(NULL != propertyModel) { QtPropertyItem* item = (QtPropertyItem*) propertyModel->itemFromIndex(index); QtPropertyData* data = item->GetPropertyData(); if(NULL != data) { data->EditorDone(editor); } } QStyledItemDelegate::setModelData(editor, model, index); }
QModelIndex QtPropertyModel::index(int row, int column, const QModelIndex & parent /* = QModelIndex() */) const { QModelIndex ret; QtPropertyData *data = itemFromIndexInternal(parent); if((NULL != data) && (row >= 0) && (column >= 0) && (row < data->ChildCount()) && (column < 2)) { ret = createIndex(row, column, data); } return ret; }
void QtPropertyItemDelegate::recalcOptionalWidgets(const QModelIndex &index, QStyleOptionViewItem *option) const { QtPropertyData* data = index.data(QtPropertyItem::PropertyDataRole).value<QtPropertyData*>(); if(NULL != data) { QWidget *owViewport = data->GetOWViewport(); int prevOWSpace = 0; int owSpacing = 1; int optionRectRight = option->rect.right(); int dataCount = data->GetOWCount(); for (int i = 0; i < dataCount; ++i) { const QtPropertyOW *ow = data->GetOW(i); if(NULL != ow && NULL != owViewport && NULL != ow->widget) { QWidget *owWidget = ow->widget; int owWidth = ow->size.width(); if(0 != owWidth) { QRect owRect = option->rect; owRect.setLeft(optionRectRight - owWidth - prevOWSpace); owRect.setRight(owRect.left() + owWidth); owWidget->setGeometry(owRect); owWidget->show(); // if this widget isn't overlayed we should modify rect for tree view cell to be drawn in. if(!ow->overlay) { option->rect.setRight(owRect.left()); } prevOWSpace += (owWidth + owSpacing); } else { owWidget->hide(); } } } } }
QWidget* QtPropertyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { QWidget* editWidget = NULL; QtPropertyData* data = index.data(QtPropertyItem::PropertyDataRole).value<QtPropertyData*>(); recalcOptionalWidgets(index, (QStyleOptionViewItem *) &option); if(NULL != data) { editWidget = data->CreateEditor(parent, option); } if(NULL == editWidget) { editWidget = QStyledItemDelegate::createEditor(parent, option, index); } return editWidget; }
QModelIndex QtPropertyModel::indexFromItem(QtPropertyData *data) const { QModelIndex ret; if(NULL != data) { QtPropertyData *parent = data->Parent(); if(NULL != parent) { int row = parent->ChildIndex(data); if(row >= 0) { ret = createIndex(row, 0, parent); } } } return ret; }
Qt::ItemFlags QtPropertyModel::flags(const QModelIndex & index) const { Qt::ItemFlags ret = 0; if(index.column() == 1) { QtPropertyData *data = itemFromIndex(index); if(NULL != data) { ret = Qt::ItemIsSelectable | data->GetFlags(); } } else { ret = Qt::ItemIsSelectable | Qt::ItemIsEnabled; } return ret; }
void QtPropertyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { bool doneByInternalEditor = false; const QtPropertyModel *propertyModel = dynamic_cast<const QtPropertyModel *>(index.model()); if(NULL != propertyModel) { QtPropertyItem* item = (QtPropertyItem*) propertyModel->itemFromIndex(index); QtPropertyData* data = item->GetPropertyData(); if(NULL != data) { doneByInternalEditor = data->SetEditorData(editor); } } if(!doneByInternalEditor) { QStyledItemDelegate::setEditorData(editor, index); } }
void QtPropertyData::BuildCurrentValue() { // Build value const QVariant master = GetValueInternal(); bool isAllEqual = true; isValuesMerged = false; for ( int i = 0; i < mergedData.size(); i++ ) { QtPropertyData *item = mergedData.at(i); const QVariant slave = item->GetValue(); if (master != slave) { isAllEqual = false; break; } } curValue = isAllEqual ? master : QVariant(); isValuesMerged = isAllEqual; // Update Qt MVC properties if ( !isAllEqual ) { QList<int> roles; roles << Qt::DecorationRole; for ( int iRole = 0; iRole < roles.size(); iRole++ ) { const int role = roles.at(iRole); auto it = style.find( role ); if ( it != style.end() ) { *it = QVariant(); } } } }
void QtPropertyDataDavaKeyedArcive::ChildCreate(const QString &key, DAVA::VariantType *value) { QtPropertyData *childData = NULL; if(value->type == DAVA::VariantType::TYPE_KEYED_ARCHIVE) { childData = new QtPropertyDataDavaKeyedArcive(value->AsKeyedArchive()); } else { childData = new QtPropertyDataDavaVariant(*value); } ChildAdd(key, childData); // add optional widget (button) to remove this key QPushButton *remButton = new QPushButton(QIcon(":/QtIcons/keyminus.png"), ""); remButton->setIconSize(QSize(12, 12)); childData->AddOW(QtPropertyOW(remButton)); childData->SetOWViewport(GetOWViewport()); QObject::connect(remButton, SIGNAL(pressed()), this, SLOT(RemKeyedArchiveField())); }
QWidget* QtPropertyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { QWidget* editWidget = NULL; const QtPropertyModel *propertyModel = dynamic_cast<const QtPropertyModel *>(index.model()); if(NULL != propertyModel) { QtPropertyItem* item = (QtPropertyItem*) propertyModel->itemFromIndex(index); QtPropertyData* data = item->GetPropertyData(); if(NULL != data) { editWidget = data->CreateEditor(parent, option); } TryEditorWorkarounds(editWidget); } if(NULL == editWidget) { editWidget = QStyledItemDelegate::createEditor(parent, option, index); } return editWidget; }
void QtPropertyDataDavaKeyedArcive::ChildCreate(const QString &key, DAVA::VariantType *value) { QtPropertyData *childData = NULL; if(value->type == DAVA::VariantType::TYPE_KEYED_ARCHIVE) { childData = new QtPropertyDataDavaKeyedArcive(value->AsKeyedArchive()); } else { childData = new QtPropertyKeyedArchiveMember(curArchive, key.toStdString()); int presetValueType = EditorConfig::Instance()->GetPropertyValueType(key.toStdString()); if(presetValueType != DAVA::VariantType::TYPE_NONE) { if(value->type == presetValueType) { const DAVA::Vector<DAVA::String>& allowedValues = EditorConfig::Instance()->GetComboPropertyValues(key.toStdString()); for(size_t i = 0; i < allowedValues.size(); ++i) { ((QtPropertyKeyedArchiveMember *) childData)->AddAllowedValue(DAVA::VariantType((int) i), allowedValues[i].c_str()); } } } } ChildAdd(key, childData); // add optional widget (button) to remove this key QPushButton *remButton = new QPushButton(QIcon(":/QtIcons/keyminus.png"), ""); remButton->setIconSize(QSize(12, 12)); childData->AddOW(QtPropertyOW(remButton)); childData->SetOWViewport(GetOWViewport()); QObject::connect(remButton, SIGNAL(pressed()), this, SLOT(RemKeyedArchiveField())); }
void QtPropertyDataDavaVariant::ChildsCreate() { switch(curVariantValue.type) { case DAVA::VariantType::TYPE_KEYED_ARCHIVE: { DAVA::KeyedArchive *archive = curVariantValue.AsKeyedArchive(); DAVA::Map<DAVA::String, DAVA::VariantType*> data = archive->GetArchieveData(); DAVA::Map<DAVA::String, DAVA::VariantType*>::iterator i = data.begin(); for(; i != data.end(); ++i) { ChildAdd(i->first.c_str(), new QtPropertyDataDavaVariant(*(i->second))); } } break; case DAVA::VariantType::TYPE_MATRIX2: break; case DAVA::VariantType::TYPE_MATRIX3: break; case DAVA::VariantType::TYPE_MATRIX4: break; case DAVA::VariantType::TYPE_VECTOR2: { DAVA::Vector2 vec = curVariantValue.AsVector2(); ChildAdd("X", vec.x); ChildAdd("Y", vec.y); } break; case DAVA::VariantType::TYPE_VECTOR3: { DAVA::Vector3 vec = curVariantValue.AsVector3(); ChildAdd("X", vec.x); ChildAdd("Y", vec.y); ChildAdd("Z", vec.z); } break; case DAVA::VariantType::TYPE_VECTOR4: { DAVA::Vector4 vec = curVariantValue.AsVector4(); ChildAdd("X", vec.x); ChildAdd("Y", vec.y); ChildAdd("Z", vec.z); ChildAdd("W", vec.w); } break; case DAVA::VariantType::TYPE_COLOR: { // DAVA::Color color = curVariantValue.AsColor(); // ChildAdd("R", color.r); // ChildAdd("G", color.g); // ChildAdd("B", color.b); // ChildAdd("A", color.a); } break; case DAVA::VariantType::TYPE_AABBOX3: { DAVA::AABBox3 box = curVariantValue.AsAABBox3(); ChildAdd("min", FromVector3(box.min)); ChildAdd("max", FromVector3(box.max)); QtPropertyData* min = ChildGet("min"); min->SetFlags(FLAG_IS_NOT_EDITABLE); min->ChildAdd("X", box.min.x); min->ChildAdd("Y", box.min.y); min->ChildAdd("Z", box.min.z); QtPropertyData* max = ChildGet("max"); max->SetFlags(FLAG_IS_NOT_EDITABLE); max->ChildAdd("X", box.max.x); max->ChildAdd("Y", box.max.y); max->ChildAdd("Z", box.max.z); } break; } }
void QtPropertyDataDavaVariant::MeSetFromChilds(const QString &lastChangedChildKey, QtPropertyData *lastChangedChildData) { switch(curVariantValue.type) { case DAVA::VariantType::TYPE_KEYED_ARCHIVE: { QtPropertyDataDavaVariant *childVariantData = (QtPropertyDataDavaVariant *) lastChangedChildData; DAVA::KeyedArchive *archive = curVariantValue.AsKeyedArchive(); if(NULL != archive && NULL != childVariantData) { archive->SetVariant(lastChangedChildKey.toStdString(), childVariantData->curVariantValue); } } break; case DAVA::VariantType::TYPE_MATRIX2: break; case DAVA::VariantType::TYPE_MATRIX3: break; case DAVA::VariantType::TYPE_MATRIX4: break; case DAVA::VariantType::TYPE_VECTOR2: { DAVA::Vector2 vec; vec.x = ChildGet("X")->GetValue().toFloat(); vec.y = ChildGet("Y")->GetValue().toFloat(); curVariantValue.SetVector2(vec); } break; case DAVA::VariantType::TYPE_VECTOR3: { DAVA::Vector3 vec; vec.x = ChildGet("X")->GetValue().toFloat(); vec.y = ChildGet("Y")->GetValue().toFloat(); vec.z = ChildGet("Z")->GetValue().toFloat(); curVariantValue.SetVector3(vec); } break; case DAVA::VariantType::TYPE_VECTOR4: { DAVA::Vector4 vec; vec.x = ChildGet("X")->GetValue().toFloat(); vec.y = ChildGet("Y")->GetValue().toFloat(); vec.z = ChildGet("Z")->GetValue().toFloat(); vec.w = ChildGet("W")->GetValue().toFloat(); curVariantValue.SetVector4(vec); } break; case DAVA::VariantType::TYPE_COLOR: { // DAVA::Color color; // color.r = ChildGet("R")->GetValue().toFloat(); // color.g = ChildGet("G")->GetValue().toFloat(); // color.b = ChildGet("B")->GetValue().toFloat(); // color.a = ChildGet("A")->GetValue().toFloat(); // curVariantValue.SetColor(color); } break; case DAVA::VariantType::TYPE_AABBOX3: { DAVA::AABBox3 box; QtPropertyData* min = ChildGet("min"); box.min.x = min->ChildGet("X")->GetValue().toFloat(); box.min.y = min->ChildGet("Y")->GetValue().toFloat(); box.min.z = min->ChildGet("Z")->GetValue().toFloat(); QtPropertyData* max = ChildGet("max"); box.max.x = max->ChildGet("X")->GetValue().toFloat(); box.max.y = max->ChildGet("Y")->GetValue().toFloat(); box.max.z = max->ChildGet("Z")->GetValue().toFloat(); curVariantValue.SetAABBox3(box); } break; } }
QtPropertyDataInspColl::QtPropertyDataInspColl(void *_object, const DAVA::InspColl *_collection, bool autoAddChilds) : object(_object) , collection(_collection) { if(NULL != collection && collection->Size(object) > 0 && autoAddChilds) { int index = 0; DAVA::MetaInfo *valueType = collection->ItemType(); DAVA::InspColl::Iterator i = collection->Begin(object); while(NULL != i) { if(NULL != valueType->GetIntrospection()) { void * itemObject = collection->ItemData(i); const DAVA::InspInfo *itemInfo = valueType->GetIntrospection(itemObject); if(NULL != itemInfo && NULL != itemObject) { QtPropertyData *childData = new QtPropertyDataIntrospection(itemObject, itemInfo); ChildAdd(QString::number(index), childData); } else { QString s; QtPropertyData* childData = new QtPropertyData(s.sprintf("[%p] Pointer", itemObject)); childData->SetEnabled(false); ChildAdd(QString::number(index), childData); } } else { if(!valueType->IsPointer()) { QtPropertyDataMetaObject *childData = new QtPropertyDataMetaObject(collection->ItemPointer(i), valueType); ChildAdd(QString::number(index), childData); } else { QString s; QtPropertyData* childData = new QtPropertyData(s.sprintf("[%p] Pointer", collection->ItemData(i))); childData->SetEnabled(false); if(collection->ItemKeyType() == DAVA::MetaInfo::Instance<DAVA::FastName>()) { const DAVA::FastName *fname = (const DAVA::FastName *) collection->ItemKeyData(i); ChildAdd(fname->operator*(), childData); } else { ChildAdd(QString::number(index), childData); } } } index++; i = collection->Next(i); } } SetEnabled(false); }
QtPropertyData * QtPropertyDataIntrospection::CreateMemberData(void *_object, const DAVA::InspMember *member, int hasAllFlags) { void *memberObject = member->Data(_object); const DAVA::MetaInfo *memberMetaInfo = member->Type(); const DAVA::InspInfo *memberIntrospection = memberMetaInfo->GetIntrospection(memberObject); bool isKeyedArchive = false; QtPropertyData * retData = NULL; // keyed archive if(NULL != memberIntrospection && (memberIntrospection->Type() == DAVA::MetaInfo::Instance<DAVA::KeyedArchive>())) { retData = new QtPropertyDataDavaKeyedArcive((DAVA::KeyedArchive *) memberObject); } // introspection else if(NULL != memberObject && NULL != memberIntrospection) { retData = new QtPropertyDataIntrospection(memberObject, memberIntrospection, hasAllFlags); } // any other value else { // pointer if(memberMetaInfo->IsPointer()) { QString s; retData = new QtPropertyData(s.sprintf("[%p] Pointer", memberObject)); retData->SetFlags(retData->GetFlags() | FLAG_IS_DISABLED); } // other value else { // collection if(member->Collection() && !isKeyedArchive) { retData = new QtPropertyDataInspColl(memberObject, member->Collection(), hasAllFlags); } // variant else { QtPropertyDataInspMember *childData = new QtPropertyDataInspMember(_object, member); if(!(member->Flags() & DAVA::I_EDIT)) { childData->SetFlags(childData->GetFlags() | FLAG_IS_NOT_EDITABLE); } else { // check if description has some predefines enum values const DAVA::InspDesc &desc = member->Desc(); if(NULL != desc.enumMap) { for(size_t i = 0; i < desc.enumMap->GetCount(); ++i) { int v; if(desc.enumMap->GetValue(i, v)) { childData->AddAllowedValue(DAVA::VariantType(v), desc.enumMap->ToString(v)); } } } } retData = childData; } } } return retData; }
void QtPropertyDataDavaVariant::ChildsSetFromMe() { switch(curVariantValue.type) { case DAVA::VariantType::TYPE_KEYED_ARCHIVE: { // No way to change whole archive // so don't need to re-set childs } break; case DAVA::VariantType::TYPE_MATRIX2: break; case DAVA::VariantType::TYPE_MATRIX3: break; case DAVA::VariantType::TYPE_MATRIX4: break; case DAVA::VariantType::TYPE_VECTOR2: { DAVA::Vector2 vec = curVariantValue.AsVector2(); ChildGet("X")->SetValue(vec.x); ChildGet("Y")->SetValue(vec.y); } break; case DAVA::VariantType::TYPE_VECTOR3: { DAVA::Vector3 vec = curVariantValue.AsVector3(); ChildGet("X")->SetValue(vec.x); ChildGet("Y")->SetValue(vec.y); ChildGet("Z")->SetValue(vec.z); } break; case DAVA::VariantType::TYPE_VECTOR4: { DAVA::Vector4 vec = curVariantValue.AsVector4(); ChildGet("X")->SetValue(vec.x); ChildGet("Y")->SetValue(vec.y); ChildGet("Z")->SetValue(vec.z); ChildGet("W")->SetValue(vec.w); } break; case DAVA::VariantType::TYPE_COLOR: { // DAVA::Color color = curVariantValue.AsColor(); // ChildGet("R")->SetValue(color.r); // ChildGet("G")->SetValue(color.g); // ChildGet("B")->SetValue(color.b); // ChildGet("A")->SetValue(color.a); } break; case DAVA::VariantType::TYPE_AABBOX3: { DAVA::AABBox3 box = curVariantValue.AsAABBox3(); QtPropertyData* min = ChildGet("min"); min->SetValue(FromVector3(box.min)); min->ChildGet("X")->SetValue(box.min.x); min->ChildGet("Y")->SetValue(box.min.y); min->ChildGet("Z")->SetValue(box.min.z); QtPropertyData* max = ChildGet("max"); max->SetValue(FromVector3(box.max)); max->ChildGet("X")->SetValue(box.max.x); max->ChildGet("Y")->SetValue(box.max.y); max->ChildGet("Z")->SetValue(box.max.z); } break; } }