summaryrefslogtreecommitdiff
path: root/src/VBox/Frontends/VirtualBox/src/cloud/machinesettings/UICloudMachineSettingsDialogPage.cpp
blob: fb3851e00a4e2c085b12051af989d20baa07d2f4 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* $Id$ */
/** @file
 * VBox Qt GUI - UICloudMachineSettingsDialogPage class implementation.
 */

/*
 * Copyright (C) 2020-2022 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */

/* Qt includes: */
#include <QHeaderView>
#include <QVBoxLayout>

/* GUI includes: */
#include "UICloudMachineSettingsDialog.h"
#include "UICloudMachineSettingsDialogPage.h"

/* Other VBox includes: */
#include "iprt/assert.h"


UICloudMachineSettingsDialogPage::UICloudMachineSettingsDialogPage(QWidget *pParent,
                                                                   bool fFullScale /* = true */)
    : QIWithRetranslateUI<QWidget>(pParent)
    , m_pParent(qobject_cast<UICloudMachineSettingsDialog*>(pParent))
    , m_fFullScale(fFullScale)
{
    prepare();
}

void UICloudMachineSettingsDialogPage::setForm(const CForm &comForm)
{
    m_comForm = comForm;
    updateEditor();
}

void UICloudMachineSettingsDialogPage::setFilter(const QString &strFilter)
{
    m_strFilter = strFilter;
    updateEditor();
}

void UICloudMachineSettingsDialogPage::makeSureDataCommitted()
{
    AssertPtrReturnVoid(m_pFormEditor.data());
    m_pFormEditor->makeSureEditorDataCommitted();
}

void UICloudMachineSettingsDialogPage::retranslateUi()
{
    AssertPtrReturnVoid(m_pFormEditor.data());
    m_pFormEditor->setWhatsThis(UICloudMachineSettingsDialog::tr("Contains a list of cloud machine settings."));
}

void UICloudMachineSettingsDialogPage::prepare()
{
    /* Prepare layout: */
    QVBoxLayout *pLayout = new QVBoxLayout(this);
    if (pLayout)
    {
        pLayout->setContentsMargins(0, 0, 0, 0);

        /* Prepare form editor widget: */
        m_pFormEditor = new UIFormEditorWidget(this, m_pParent ? m_pParent->notificationCenter() : 0);
        if (m_pFormEditor)
        {
            /* Make form-editor fit 12 sections in height by default: */
            const int iDefaultSectionHeight = m_pFormEditor->verticalHeader()
                                            ? m_pFormEditor->verticalHeader()->defaultSectionSize()
                                            : 0;
            if (iDefaultSectionHeight > 0)
            {
                const int iProposedHeight = iDefaultSectionHeight * (m_fFullScale ? 12 : 6);
                const int iProposedWidth = iProposedHeight * 1.66;
                m_pFormEditor->setMinimumSize(iProposedWidth, iProposedHeight);
            }

            /* Add into layout: */
            pLayout->addWidget(m_pFormEditor);
        }
    }

    /* Apply language settings: */
    retranslateUi();
}

void UICloudMachineSettingsDialogPage::updateEditor()
{
    /* Make sure editor present: */
    AssertPtrReturnVoid(m_pFormEditor.data());

    /* Make sure form isn't null: */
    if (m_comForm.isNotNull())
    {
        /* Acquire initial values: */
        const QVector<CFormValue> initialValues = m_comForm.GetValues();

        /* If filter null: */
        if (m_strFilter.isNull())
        {
            /* Push initial values to editor: */
            m_pFormEditor->setValues(initialValues);
        }
        /* If filter present: */
        else
        {
            /* Acquire group fields: */
            const QVector<QString> groupFields = m_comForm.GetFieldGroup(m_strFilter);
            /* Filter out unrelated values: */
            QVector<CFormValue> filteredValues;
            foreach (const CFormValue &comValue, initialValues)
                if (groupFields.contains(comValue.GetLabel()))
                    filteredValues << comValue;
            /* Push filtered values to editor: */
            m_pFormEditor->setValues(filteredValues);
        }
    }

    /* Revalidate: */
    emit sigValidChanged(m_comForm.isNotNull());
}