FreeCAD

Форк
0
/
DlgProjectInformationImp.cpp 
182 строки · 8.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
#include <QApplication>
26
#include <QByteArray>
27
#include <QDesktopServices>
28
#include <QUrl>
29
#endif
30

31
#include <App/Document.h>
32
#include <App/License.h>
33
#include <Base/UnitsApi.h>
34

35
#include "DlgProjectInformationImp.h"
36
#include "ui_DlgProjectInformation.h"
37

38
#include "MainWindow.h"
39

40
#if 0 // needed for Qt's lupdate utility
41
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "All rights reserved");
42
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution");
43
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution-ShareAlike");
44
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution-NoDerivatives");
45
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution-NonCommercial");
46
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution-NonCommercial-ShareAlike");
47
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution-NonCommercial-NoDerivatives");
48
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "Public Domain");
49
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "FreeArt");
50
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "CERN Open Hardware Licence strongly-reciprocal");
51
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "CERN Open Hardware Licence weakly-reciprocal");
52
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "CERN Open Hardware Licence permissive");
53
    qApp->translate("Gui::Dialog::DlgSettingsDocument", "Other");
54
#endif
55

56
using namespace Gui::Dialog;
57

58
/* TRANSLATOR Gui::Dialog::DlgProjectInformationImp */
59

60
/**
61
 *  Constructs a Gui::Dialog::DlgProjectInformationImp as a child of 'parent', with the
62
 *  name 'name' and widget flags set to 'fl'.
63
 *
64
 *  The dialog will by default be modeless, unless you set 'modal' to
65
 *  true to construct a modal dialog.
66
 */
67
DlgProjectInformationImp::DlgProjectInformationImp(App::Document* doc, QWidget* parent, Qt::WindowFlags fl)
68
  : QDialog(parent, fl), _doc(doc), ui(new Ui_DlgProjectInformation)
69
{
70
    ui->setupUi(this);
71
    ui->lineEditName->setText(QString::fromUtf8(doc->Label.getValue()));
72
    ui->lineEditPath->setText(QString::fromUtf8(doc->FileName.getValue()));
73
    ui->lineEditUuid->setText(QString::fromUtf8(doc->Uid.getValueStr().c_str()));
74
    ui->lineEditProgramVersion->setText(QString::fromUtf8(doc->getProgramVersion()));
75
    ui->lineEditCreator->setText(QString::fromUtf8(doc->CreatedBy.getValue()));
76
    ui->lineEditDate->setText(QString::fromUtf8(doc->CreationDate.getValue()));
77
    ui->lineEditLastMod->setText(QString::fromUtf8(doc->LastModifiedBy.getValue()));
78
    ui->lineEditLastModDate->setText(QString::fromUtf8(doc->LastModifiedDate.getValue()));
79
    ui->lineEditCompany->setText(QString::fromUtf8(doc->Company.getValue()));
80

81
    // Load comboBox with unit systems
82
    int num = static_cast<int>(Base::UnitSystem::NumUnitSystemTypes);
83
    for (int i = 0; i < num; i++) {
84
        QString item = Base::UnitsApi::getDescription(static_cast<Base::UnitSystem>(i));
85
        ui->comboBox_unitSystem->addItem(item, i);
86
    }
87
    ui->comboBox_unitSystem->setCurrentIndex(doc->UnitSystem.getValue());
88

89
    // load comboBox with license names
90
    for (const auto& item : App::licenseItems) {
91
        const char* name {item.at(App::posnOfFullName)};
92
        QString translated = QApplication::translate("Gui::Dialog::DlgSettingsDocument", name);
93
        ui->comboLicense->addItem(translated, QByteArray(name));
94
    }
95

96
    // set default position to match document
97
    int index = ui->comboLicense->findData(QByteArray(doc->License.getValue()));
98
    if (index >= 0) {
99
        ui->comboLicense->setCurrentIndex(index);
100
    }
101
    else {
102
        index = ui->comboLicense->count();
103
        QString text = QString::fromUtf8(doc->License.getValue());
104
        ui->comboLicense->addItem(text);
105
        ui->comboLicense->setCurrentIndex(index);
106
    }
107

108
    ui->lineEditLicenseURL->setText(QString::fromUtf8(doc->LicenseURL.getValue()));
109

110
    // When saving the text to XML the newlines get lost. So we store also the newlines as '\n'.
111
    // See also accept().
112
    QString comment = QString::fromUtf8(doc->Comment.getValue());
113
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
114
    QStringList lines = comment.split(QLatin1String("\\n"), Qt::KeepEmptyParts);
115
#else
116
    QStringList lines = comment.split(QLatin1String("\\n"), QString::KeepEmptyParts);
117
#endif
118
    QString text = lines.join(QLatin1String("\n"));
119
    ui->textEditComment->setPlainText( text );
120
    connect(ui->pushButtonOpenURL, &QPushButton::clicked,
121
            this, &DlgProjectInformationImp::open_url);
122
    connect(ui->comboLicense, qOverload<int>(&QComboBox::currentIndexChanged),
123
            this, &DlgProjectInformationImp::onLicenseTypeChanged);
124
}
125

126
/**
127
 *  Destroys the object and frees any allocated resources
128
 */
129
DlgProjectInformationImp::~DlgProjectInformationImp()
130
{
131
    // no need to delete child widgets, Qt does it all for us
132
    delete ui;
133
}
134

135
/**
136
 * Applies the changes to the project information of the given document.
137
 */
138
void DlgProjectInformationImp::accept()
139
{
140
    _doc->CreatedBy.setValue(ui->lineEditCreator->text().toUtf8());
141
    _doc->LastModifiedBy.setValue(ui->lineEditCreator->text().toUtf8());
142
    _doc->Company.setValue(ui->lineEditCompany->text().toUtf8());
143
    getMainWindow()->setUserSchema(ui->comboBox_unitSystem->currentIndex());
144
    QByteArray licenseName {ui->comboLicense->currentData().toByteArray()};
145
    // Is this really necessary?
146
    if (licenseName.isEmpty()) {
147
        licenseName = ui->comboLicense->currentText().toUtf8();
148
    }
149
    _doc->License.setValue(licenseName);
150
    _doc->LicenseURL.setValue(ui->lineEditLicenseURL->text().toUtf8());
151

152
    // Replace newline escape sequence through '\\n' string
153
    QStringList lines = ui->textEditComment->toPlainText().split
154
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
155
        (QLatin1String("\n"), Qt::KeepEmptyParts);
156
#else
157
        (QLatin1String("\n"), QString::KeepEmptyParts);
158
#endif
159
    QString text = lines.join(QLatin1String("\\n"));
160
    _doc->Comment.setValue(text.isEmpty() ? QByteArray() : text.toUtf8());
161

162
    QDialog::accept();
163
}
164

165
void DlgProjectInformationImp::onLicenseTypeChanged(int index)
166
{
167
    const char* url {index >= 0 && index < App::countOfLicenses ? App::licenseItems.at(index).at(App::posnOfUrl)
168
                                                  : _doc->LicenseURL.getValue()};
169

170
    ui->lineEditLicenseURL->setText(QString::fromLatin1(url));
171
}
172

173
/**
174
 * Opens the text in the LicenseURL property in external browser.
175
 */
176
void DlgProjectInformationImp::open_url()
177
{
178
    QString url = ui->lineEditLicenseURL->text();
179
    QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
180
}
181

182
#include "moc_DlgProjectInformationImp.cpp"
183

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.