Commit 198d8173 authored by Thomas Hartmann's avatar Thomas Hartmann

QuickDesigner.navigator: Display all QGraphicsObject-type node

properties

The navigator now displays all properties whose type is a sub class
of QGraphicsObject, except for those properties inherited by Qt/Item.
The contents of the default property are displayed as direct children
of the model node's tree node.
Reparenting into and from the displayed properties is supported.

original author: Joerg Schummer
parent 8fa642d8
......@@ -50,8 +50,8 @@ class NavigatorTreeModel : public QStandardItemModel
struct ItemRow {
ItemRow()
: idItem(0), lockItem(0), visibilityItem(0) {}
ItemRow(QStandardItem *id, QStandardItem *lock, QStandardItem *visibility)
: idItem(id), lockItem(lock), visibilityItem(visibility) {}
ItemRow(QStandardItem *id, QStandardItem *lock, QStandardItem *visibility, const PropertyItemMap &properties)
: idItem(id), lockItem(lock), visibilityItem(visibility), propertyItems(properties) {}
QList<QStandardItem*> toList() const {
return QList<QStandardItem*>() << idItem << lockItem << visibilityItem;
......@@ -60,13 +60,14 @@ class NavigatorTreeModel : public QStandardItemModel
QStandardItem *idItem;
QStandardItem *lockItem;
QStandardItem *visibilityItem;
QMap<QString, QStandardItem *> propertyItems;
};
#else
struct ItemRow {
ItemRow()
: idItem(0), visibilityItem(0) {}
ItemRow(QStandardItem *id, QStandardItem *visibility)
: idItem(id), visibilityItem(visibility) {}
ItemRow(QStandardItem *id, QStandardItem *visibility, const QMap<QString, QStandardItem *> &properties)
: idItem(id), visibilityItem(visibility), propertyItems(properties) {}
QList<QStandardItem*> toList() const {
return QList<QStandardItem*>() << idItem << visibilityItem;
......@@ -74,9 +75,12 @@ class NavigatorTreeModel : public QStandardItemModel
QStandardItem *idItem;
QStandardItem *visibilityItem;
QMap<QString, QStandardItem *> propertyItems;
};
#endif
static const int NavigatorRole;
public:
NavigatorTreeModel(QObject *parent = 0);
~NavigatorTreeModel();
......@@ -105,7 +109,7 @@ public:
void addSubTree(const ModelNode &node);
void removeSubTree(const ModelNode &node);
void updateItemRow(const ModelNode &node);
void updateItemRowOrder(const ModelNode &node);
void updateItemRowOrder(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void setId(const QModelIndex &index, const QString &id);
void setVisible(const QModelIndex &index, bool visible);
......@@ -123,9 +127,13 @@ private:
ItemRow createItemRow(const ModelNode &node);
void updateItemRow(const ModelNode &node, ItemRow row);
void reparentModelNode(const ModelNode &parentNode, const ModelNode &node);
void moveNodesInteractive(NodeAbstractProperty parentProperty, const QList<ModelNode> &modelNodes, int targetIndex);
QList<ModelNode> modelNodeChildren(const ModelNode &parentNode);
QString qmlTypeInQtContainer(const QString &qtContainerType) const;
QStringList visibleProperties(const ModelNode &node) const;
bool blockItemChangedSignal(bool block);
private:
......@@ -134,6 +142,8 @@ private:
QWeakPointer<AbstractView> m_view;
bool m_blockItemChangedSignal;
QStringList m_hiddenProperties;
};
} // namespace QmlDesigner
......
......@@ -127,12 +127,19 @@ QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem &option,
{
Q_UNUSED(option);
Q_UNUSED(index);
return QSize(15,20);
if (!index.data(Qt::UserRole).isValid())
return QSize();
return QSize(15, 20);
}
void IconCheckboxItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (!index.data(Qt::UserRole).isValid())
return;
painter->save();
if (option.state & QStyle::State_Selected)
drawSelectionBackground(painter, option);
......@@ -152,70 +159,84 @@ void IconCheckboxItemDelegate::paint(QPainter *painter,
painter->restore();
}
void IdItemDelegate::paint(QPainter *painter,
void NameItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (option.state & QStyle::State_Selected)
drawSelectionBackground(painter, option);
QString displayString;
QPoint displayStringOffset;
painter->save();
if (m_TreeModel->isNodeInvisible( index ))
painter->setOpacity(0.5);
if (index.data(Qt::UserRole).isValid()) {
ModelNode node = m_TreeModel->nodeForIndex(index);
int pixmapSide = 16;
QIcon icon;
if (node.metaInfo().isValid()) {
icon=node.metaInfo().icon();
if (icon.isNull())
{
// if node has no own icon, search for it in the itemlibrary
const NodeMetaInfo typeInfo = node.metaInfo();
const ItemLibraryInfo *libraryInfo = node.metaInfo().metaInfo().itemLibraryInfo();
QList <ItemLibraryEntry> infoList = libraryInfo->entriesForType(typeInfo.typeName(),
typeInfo.majorVersion(),
typeInfo.minorVersion());
foreach (const ItemLibraryEntry &entry, infoList) {
if (!icon.isNull()) {
icon = entry.icon();
break;
if (m_TreeModel->isNodeInvisible( index ))
painter->setOpacity(0.5);
ModelNode node = m_TreeModel->nodeForIndex(index);
QIcon icon;
if (node.metaInfo().isValid()) {
icon=node.metaInfo().icon();
if (icon.isNull())
{
// if node has no own icon, search for it in the itemlibrary
const NodeMetaInfo typeInfo = node.metaInfo();
const ItemLibraryInfo *libraryInfo = node.metaInfo().metaInfo().itemLibraryInfo();
QList <ItemLibraryEntry> infoList = libraryInfo->entriesForType(typeInfo.typeName(),
typeInfo.majorVersion(),
typeInfo.minorVersion());
foreach (const ItemLibraryEntry &entry, infoList) {
if (!icon.isNull()) {
icon = entry.icon();
break;
}
}
}
}
}
// if the library was also empty, use the default icon
if (icon.isNull())
icon = QIcon(QLatin1String(":/ItemLibrary/images/item-default-icon.png"));
// If no icon is present, leave an empty space of 24 pixels anyway
int pixmapSide = 16;
QPixmap pixmap = icon.pixmap(pixmapSide, pixmapSide);
painter->drawPixmap(option.rect.x()+1,option.rect.y()+2,pixmap);
// If no icon is present, leave an empty space of 24 pixels anyway
QPixmap pixmap = icon.pixmap(pixmapSide, pixmapSide);
painter->drawPixmap(option.rect.x()+1,option.rect.y()+2,pixmap);
QString myString = node.id();
if (myString.isEmpty())
myString = node.simplifiedTypeName();
displayString = node.id();
if (displayString.isEmpty())
displayString = node.simplifiedTypeName();
// Check text length does not exceed available space
int extraSpace=12+pixmapSide;
QFontMetrics fm(option.font);
myString = fm.elidedText(myString,Qt::ElideMiddle,option.rect.width()-extraSpace);
// Check text length does not exceed available space
int extraSpace=12+pixmapSide;
QFontMetrics fm(option.font);
displayString = fm.elidedText(displayString,Qt::ElideMiddle,option.rect.width()-extraSpace);
displayStringOffset = QPoint(5+pixmapSide,-5);
}
else {
displayString = index.data(Qt::DisplayRole).toString();
displayStringOffset = QPoint(0, -2);
}
painter->drawText(option.rect.bottomLeft()+QPoint(5+pixmapSide,-5),myString);
painter->drawText(option.rect.bottomLeft()+displayStringOffset,displayString);
painter->restore();
}
QWidget *IdItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
QWidget *NameItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
if (!index.data(Qt::UserRole).isValid())
return 0;
return new QLineEdit(parent);
}
void IdItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
void NameItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
ModelNode node = m_TreeModel->nodeForIndex(index);
QString value = node.id();
......@@ -224,7 +245,7 @@ void IdItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) co
lineEdit->setText(value);
}
void IdItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
void NameItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
Q_UNUSED(model);
QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
......@@ -232,7 +253,7 @@ void IdItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, co
lineEdit->clearFocus();
}
void IdItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
void NameItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(index);
QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
......
......@@ -70,10 +70,10 @@ class IconCheckboxItemDelegate : public QStyledItemDelegate
};
class IdItemDelegate : public QStyledItemDelegate
class NameItemDelegate : public QStyledItemDelegate
{
public:
explicit IdItemDelegate(QObject *parent=0, NavigatorTreeModel *treeModel=NULL) : QStyledItemDelegate(parent),m_TreeModel(treeModel) {}
explicit NameItemDelegate(QObject *parent=0, NavigatorTreeModel *treeModel=NULL) : QStyledItemDelegate(parent),m_TreeModel(treeModel) {}
void paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
......
......@@ -49,7 +49,7 @@ NavigatorView::NavigatorView(QObject* parent) :
connect(treeWidget()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(changeSelection(QItemSelection,QItemSelection)));
treeWidget()->setIndentation(treeWidget()->indentation() * 0.5);
IdItemDelegate *idDelegate = new IdItemDelegate(this,m_treeModel.data());
NameItemDelegate *idDelegate = new NameItemDelegate(this,m_treeModel.data());
IconCheckboxItemDelegate *showDelegate = new IconCheckboxItemDelegate(this,":/qmldesigner/images/eye_open.png",
":/qmldesigner/images/placeholder.png",m_treeModel.data());
......@@ -191,10 +191,10 @@ void NavigatorView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStr
}
void NavigatorView::nodeOrderChanged(const NodeListProperty &/*listProperty*/, const ModelNode &node, int /*oldIndex*/)
void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &node, int oldIndex)
{
if (m_treeModel->isInTree(node))
m_treeModel->updateItemRowOrder(node);
m_treeModel->updateItemRowOrder(listProperty, node, oldIndex);
}
void NavigatorView::changeSelection(const QItemSelection & /*newSelection*/, const QItemSelection &/*deselected*/)
......@@ -203,7 +203,8 @@ void NavigatorView::changeSelection(const QItemSelection & /*newSelection*/, con
return;
QSet<ModelNode> nodeSet;
foreach (const QModelIndex &index, treeWidget()->selectionModel()->selectedIndexes()) {
nodeSet.insert(m_treeModel->nodeForIndex(index));
if (m_treeModel->data(index, Qt::UserRole).isValid())
nodeSet.insert(m_treeModel->nodeForIndex(index));
}
bool blocked = blockSelectionChangedSignal(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment