summaryrefslogtreecommitdiff
path: root/src/plugins/qmldesigner/components/annotationeditor/globalannotationeditor.cpp
blob: 17809a40d8d387f21926bdfd7e37dd8eaf81db75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "globalannotationeditor.h"

#include "annotation.h"
#include "globalannotationdialog.h"

#include <coreplugin/icore.h>

#include <QMessageBox>

namespace QmlDesigner {

GlobalAnnotationEditor::GlobalAnnotationEditor(QObject *parent)
    : ModelNodeEditorProxy(parent)
{}

QWidget *GlobalAnnotationEditor::createWidget()
{
    GlobalAnnotationDialog *dialog = new GlobalAnnotationDialog(m_modelNode, Core::ICore::dialogParent());

    dialog->setStatus(m_modelNode.globalStatus());

    dialog->setAnnotation(this->m_modelNode.globalAnnotation());
    QObject::connect(dialog, &GlobalAnnotationDialog::acceptedDialog,
                     this, &GlobalAnnotationEditor::acceptedClicked);
    QObject::connect(dialog, &GlobalAnnotationDialog::rejected,
                     this, &GlobalAnnotationEditor::cancelClicked);
    QObject::connect(dialog, &GlobalAnnotationDialog::appliedDialog,
                     this, &GlobalAnnotationEditor::appliedClicked);
    return dialog;
};

void GlobalAnnotationEditor::removeFullAnnotation()
{
    auto &node = this->m_modelNode;
    if (!node.isValid())
        return;

    const QString dialogTitle = tr("Global Annotation");
    if (QMessageBox::question(Core::ICore::dialogParent(),
                              dialogTitle,
                              tr("Delete this annotation?"))
        == QMessageBox::Yes) {
        node.removeGlobalAnnotation();
        emit annotationChanged();
    }
}

void GlobalAnnotationEditor::acceptedClicked()
{
    applyChanges();

    hideWidget();

    emit accepted();

    emit annotationChanged();
    emit customIdChanged();
}

void GlobalAnnotationEditor::appliedClicked()
{
    applyChanges();

    emit applied();

    emit annotationChanged();
    emit customIdChanged();
}

void GlobalAnnotationEditor::cancelClicked()
{
    hideWidget();

    emit canceled();

    emit annotationChanged();
    emit customIdChanged();
}

void GlobalAnnotationEditor::applyChanges()
{
    if (GlobalAnnotationDialog * const dialog = qobject_cast<GlobalAnnotationDialog *>(widget())) {
        //first save global annotation:
        auto &node = this->m_modelNode;
        const Annotation &annotation = dialog->annotation();

        if (annotation.comments().isEmpty())
            node.removeGlobalAnnotation();
        else
            node.setGlobalAnnotation(annotation);

        const GlobalAnnotationStatus status = dialog->globalStatus();

        if (status.status() == GlobalAnnotationStatus::NoStatus)
            node.removeGlobalStatus();
        else
            node.setGlobalStatus(status);


        //then save annotations list:
        dialog->saveAnnotationListChanges();
    }
}

} //namespace QmlDesigner