Beispiel #1
0
QPair<QtPropertyItem*, QtPropertyItem*> QtPropertyModel::GetProperty(const QString &name, QtPropertyItem* parent/* = NULL*/)
{
	QPair<QtPropertyItem*, QtPropertyItem*> ret(NULL, NULL);

    QStandardItem* root = (QStandardItem *) parent;
	if(NULL == root)
	{
		root = invisibleRootItem();
	}

    for(DAVA::int32 r = 0; r < root->rowCount(); ++r)
    {
        QtPropertyItem *keyItem = (QtPropertyItem *) root->child(r, 0);
        if(keyItem->GetPropertyData()->GetValue().toString() == name)
        {
            QtPropertyItem *dataItem = (QtPropertyItem *) root->child(r, 1);

			ret.first = keyItem;
			ret.second = dataItem;

			break;
        }
    }
    
    return ret;
}
Beispiel #2
0
void QtPropertyModel::OnItemChanged(QStandardItem* item)
{
	QtPropertyItem *propItem = (QtPropertyItem *) item;

	if(NULL != propItem)
	{
		if(propItem->isCheckable())
		{
			propItem->GetPropertyData()->SetValue(QVariant(propItem->checkState() == Qt::Checked));
		}
	}
}
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);
}
void QtPropertyItem::ChildAdd(const QString &key, QtPropertyData* data)
{
	if(NULL != parentName)
	{
		QList<QStandardItem *> subItems;
		QtPropertyItem *subName = new QtPropertyItem(key);
		QtPropertyItem *subValue = new QtPropertyItem(data, subName);

		subValue->itemDataDeleteByParent = true;
		// subValue->setFont(QFont("Courier"));
		subName->setEditable(false);

		subItems.append(subName);
		subItems.append(subValue);

		parentName->appendRow(subItems);
	}
}
Beispiel #5
0
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);
	}
}
Beispiel #6
0
QPair<QtPropertyItem*, QtPropertyItem*> QtPropertyModel::AppendProperty(const QString &name, QtPropertyData* data, QtPropertyItem* parent /*= NULL*/)
{
	QList<QStandardItem *> items;
	QStandardItem* root = (QStandardItem *) parent;

	QtPropertyItem *newPropertyName = new QtPropertyItem(name);
	QtPropertyItem *newPropertyValue = new QtPropertyItem(data, newPropertyName);

	newPropertyName->setEditable(false);

	items.append(newPropertyName);
	items.append(newPropertyValue);

	if(NULL == root)
	{
		root = invisibleRootItem();
	}

	root->appendRow(items);

	return QPair<QtPropertyItem*, QtPropertyItem*>(newPropertyName, newPropertyValue);
}
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;
}