Commit 8e59aeab authored by jan.koester's avatar jan.koester
Browse files

fixed

parent d6e0c006
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -115,6 +115,15 @@ int DocumentTreeModel::columnCount(const QModelIndex &) const {
    return 1;
}

bool DocumentTreeModel::hasChildren(const QModelIndex &parent) const {
    if (!parent.isValid()) {
        // Root: has children if docRoot is not null
        return _doc->docRoot() != nullptr;
    }
    auto *plugin = static_cast<EditPlugin*>(parent.internalPointer());
    return plugin && plugin->getChildElement() != nullptr;
}

QVariant DocumentTreeModel::data(const QModelIndex &index, int role) const {
    if (!index.isValid())
        return QVariant();
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ public:
    QModelIndex parent(const QModelIndex &child) const override;
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;

+16 −21
Original line number Diff line number Diff line
@@ -27,20 +27,15 @@ ColumnLayout {
        Layout.fillHeight: true
        clip: true
        model: localApi.documentTreeModel()
        selectionBehavior: TableView.SelectRows

        delegate: TreeViewDelegate {
            id: treeDelegate

            required property string uuid
            required property string name
            required property bool nodeHasChildren

            implicitHeight: 30
            implicitWidth: docTreeView.width

            background: Rectangle {
                color: treeRoot.selectedUuid === treeDelegate.uuid
                color: treeRoot.selectedUuid === model.uuid
                    ? Theme.accent
                    : (delegateHover.hovered ? Theme.bgHover : "transparent")
                radius: 4
@@ -52,7 +47,7 @@ ColumnLayout {
                spacing: 6

                Label {
                    text: treeDelegate.nodeHasChildren
                    text: model.nodeHasChildren
                        ? (treeDelegate.expanded ? "" : "")
                        : ""
                    font.pixelSize: 10
@@ -67,9 +62,9 @@ ColumnLayout {
                }

                Label {
                    text: treeDelegate.name
                    text: model.name || ""
                    font.pixelSize: 13
                    color: treeRoot.selectedUuid === treeDelegate.uuid
                    color: treeRoot.selectedUuid === model.uuid
                        ? Theme.bgPrimary : Theme.textPrimary
                    elide: Text.ElideRight
                    Layout.fillWidth: true
@@ -94,7 +89,7 @@ ColumnLayout {
                        verticalAlignment: Text.AlignVCenter
                    }

                    onClicked: localApi.removeElement(treeDelegate.uuid)
                    onClicked: localApi.removeElement(model.uuid)
                }
            }

@@ -105,29 +100,29 @@ ColumnLayout {
                    if (mouse.button === Qt.RightButton) {
                        nodeCtxMenu.popup()
                    } else {
                        treeRoot.selectedUuid = treeDelegate.uuid
                        propPanel.loadProperties(treeDelegate.uuid)
                        treeRoot.selectedUuid = model.uuid
                        propPanel.loadProperties(model.uuid)
                    }
                }
                onDoubleClicked: {
                    if (treeDelegate.nodeHasChildren)
                    if (model.nodeHasChildren)
                        docTreeView.toggleExpanded(treeDelegate.row)
                }
            }

            Menu {
                id: nodeCtxMenu
                MenuItem { text: qsTr("⚙  Settings");  onTriggered: { treeRoot.selectedUuid = treeDelegate.uuid; propPanel.loadProperties(treeDelegate.uuid) } }
                MenuItem { text: qsTr("⚙  Settings");  onTriggered: { treeRoot.selectedUuid = model.uuid; propPanel.loadProperties(model.uuid) } }
                MenuSeparator {}
                MenuItem { text: qsTr("↑  Move up");    onTriggered: localApi.moveUp(treeDelegate.uuid) }
                MenuItem { text: qsTr("↓  Move down");  onTriggered: localApi.moveDown(treeDelegate.uuid) }
                MenuItem { text: qsTr("→  Indent");     onTriggered: localApi.indent(treeDelegate.uuid) }
                MenuItem { text: qsTr("←  Outdent");    onTriggered: localApi.outdent(treeDelegate.uuid) }
                MenuItem { text: qsTr("↑  Move up");    onTriggered: localApi.moveUp(model.uuid) }
                MenuItem { text: qsTr("↓  Move down");  onTriggered: localApi.moveDown(model.uuid) }
                MenuItem { text: qsTr("→  Indent");     onTriggered: localApi.indent(model.uuid) }
                MenuItem { text: qsTr("←  Outdent");    onTriggered: localApi.outdent(model.uuid) }
                MenuSeparator {}
                MenuItem { text: qsTr("⎘  Copy");       onTriggered: { localApi.copyElement(treeDelegate.uuid); root.setStatus("Copied") } }
                MenuItem { text: qsTr("📋 Paste");      onTriggered: localApi.pasteElement(treeDelegate.uuid) }
                MenuItem { text: qsTr("⎘  Copy");       onTriggered: { localApi.copyElement(model.uuid); root.setStatus("Copied") } }
                MenuItem { text: qsTr("📋 Paste");      onTriggered: localApi.pasteElement(model.uuid) }
                MenuSeparator {}
                MenuItem { text: qsTr("✕  Remove");     onTriggered: localApi.removeElement(treeDelegate.uuid) }
                MenuItem { text: qsTr("✕  Remove");     onTriggered: localApi.removeElement(model.uuid) }
            }
        }
    }