1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
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 GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SalomeApp_StudyPropertiesDlg.cxx
25 // Author : Roman NIKOLAEV
27 #include "SalomeApp_StudyPropertiesDlg.h"
28 #include "SalomeApp_Application.h"
29 #include "SalomeApp_Study.h"
31 #include "SUIT_Session.h"
32 #include <SUIT_Desktop.h>
33 #include <SUIT_MessageBox.h>
36 #include <SALOMEconfig.h>
37 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
40 #include <QPushButton>
41 #include <QGridLayout>
42 #include <QHBoxLayout>
49 #include <QTreeWidget>
50 #include <QPushButton>
54 #define DEFAULT_MARGIN 11
55 #define DEFAULT_SPACING 6
57 #define MIN_LIST_WIDTH 300
58 #define MIN_LIST_HEIGHT 150
61 /*!Constructor. Initialize study properties dialog.*/
62 SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent)
63 : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
68 setWindowTitle(tr("TLT_STUDY_PROPERTIES"));
69 setSizeGripEnabled( true );
71 setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint );
74 QLabel* authorLbl = new QLabel(tr("PRP_AUTHOR"),this);
75 myAuthor = new QLineEdit(this);
78 QLabel* dateLbl = new QLabel(tr("PRP_DATE"),this);
79 myDate = new QLabel(this);
82 myLocked = new QCheckBox(tr("PRP_LOCKED"), this);
85 myModification = new QLabel(this);
88 QLabel* unitsLbl = new QLabel(tr("PRP_UNITS"),this);
89 myUnits = new QComboBox(this);
92 QLabel* commentLabel = new QLabel(tr("PRP_COMMENT"),this);
93 myComment = new QTextEdit(this);
94 myComment->setMaximumHeight(80);
97 QLabel* modificationsLabel = new QLabel(tr("PRP_MODIFICATIONS"),this);
98 myModifications = new QTreeWidget(this);
99 myModifications->setRootIsDecorated(false);
100 myModifications->setUniformRowHeights(true);
101 myModifications->setAllColumnsShowFocus(true);
102 myModifications->setColumnCount(2);
103 myModifications->setMaximumHeight(80);
104 QStringList columnNames;
105 columnNames.append(tr("PRP_AUTHOR"));
106 columnNames.append(tr("PRP_DATE_MODIF"));
107 myModifications->setHeaderLabels( columnNames );
110 QLabel* versionsLabel = new QLabel(tr("PRP_VERSIONS"),this);
111 myVersions = new QTreeWidget(this);
112 myVersions->setRootIsDecorated(false);
113 myVersions->setUniformRowHeights(true);
114 myVersions->setAllColumnsShowFocus(true);
115 myVersions->setColumnCount(2);
116 myVersions->setMaximumHeight(80);
118 columnNames.append(tr("PRP_COMPONENT"));
119 columnNames.append(tr("PRP_VERSION"));
120 myVersions->setHeaderLabels( columnNames );
122 QFrame* buttonFrame = new QFrame(this);
124 QHBoxLayout* horizontalLayout = new QHBoxLayout(buttonFrame);
126 myOkButton = new QPushButton(tr("BUT_OK"), buttonFrame);
127 myCancelButton = new QPushButton(tr("BUT_CANCEL"), buttonFrame);
129 horizontalLayout->addWidget(myOkButton);
130 horizontalLayout->addItem( new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum) );
131 horizontalLayout->addWidget(myCancelButton);
133 QGridLayout* gridLayout = new QGridLayout(this);
134 gridLayout->setMargin(DEFAULT_MARGIN);
135 gridLayout->setSpacing(DEFAULT_SPACING);
136 gridLayout->addWidget(authorLbl, 0, 0, 1, 1);
137 gridLayout->addWidget(myAuthor, 0, 1, 1, 1);
138 gridLayout->addWidget(dateLbl, 1, 0, 1, 1);
139 gridLayout->addWidget(myDate, 1, 1, 1, 1);
140 gridLayout->addWidget(myLocked, 2, 0, 1, 1);
141 gridLayout->addWidget(myModification, 2, 1, 1, 1);
142 gridLayout->addWidget(unitsLbl, 3, 0, 1, 1);
143 gridLayout->addWidget(myUnits, 3, 1, 1, 1);
144 gridLayout->addItem(new QSpacerItem(/*72*/0, 0/*20*/, QSizePolicy::Expanding, QSizePolicy::Minimum), 3, 2, 1, 1);
145 gridLayout->addWidget(commentLabel, 4, 0, 1, 1);
146 gridLayout->addWidget(myComment, 4, 1, 1, 2);
147 gridLayout->addWidget(modificationsLabel, 5, 0, 1, 1);
148 gridLayout->addWidget(myModifications, 5, 1, 1, 2);
149 gridLayout->addWidget(versionsLabel, 6, 0, 1, 1);
150 gridLayout->addWidget(myVersions, 6, 1, 1, 2);
151 gridLayout->addWidget(buttonFrame, 7, 0, 1, 3);
153 connect(myOkButton, SIGNAL(clicked()), this, SLOT(clickOnOk()));
154 connect(myCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
162 SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg()
167 Data initializetion for dialog.(Study author's name, date of creation etc.)
169 void SalomeApp_StudyPropertiesDlg::initData()
171 bool hasData = (SalomeApp_Application::getStudy() != NULL);
172 _PTR(AttributeStudyProperties) propAttr;
174 propAttr = SalomeApp_Application::getStudy()->GetProperties();
175 hasData = hasData && propAttr;
178 //Creator and creation date
179 myAuthor->setText(propAttr->GetUserName().c_str());
180 int minutes, hours, day, month, year;
181 if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
183 strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
184 myDate->setText(strDate);
188 myLocked->setChecked(propAttr->IsLocked());
191 bool isModified = false;
192 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>
193 (SUIT_Session::session()->activeApplication()->activeStudy());
194 isModified = study->isModified();
195 if (propAttr->IsModified() != isModified) {
196 propAttr->SetModified((int)isModified);
199 QString modif = propAttr->IsModified() ? tr( "PRP_MODIFIED" ) : tr( "PRP_NOT_MODIFIED" );
200 myModification->setText(modif);
204 theList <<""<<"mm"<<"cm"<<"m"<<"km"<<"inch";
205 myUnits->insertItems(0,theList);
207 QString anUnit = propAttr->GetUnits().c_str();
210 for (int i = 0; i < myUnits->count(); i++) {
211 if ( myUnits->itemText(i) == anUnit ) {
218 myUnits->setCurrentIndex(aFound);
222 myComment->setPlainText(propAttr->GetComment().c_str());
225 std::vector<std::string> aUsers;
226 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
227 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
228 int aCnt = aUsers.size();
229 for ( int i = 0; i < aCnt; i++ ) {
231 date.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
238 aList.append(aUsers[i].c_str());
240 QTreeWidgetItem* item = new QTreeWidgetItem(aList);
241 myModifications->addTopLevelItem(item);
245 std::vector<std::string> aComponents = propAttr->GetStoredComponents();
246 for ( int i = 0; i < aComponents.size(); i++ ) {
247 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
248 std::vector<std::string> aVersions = propAttr->GetComponentVersions(aComponents[i]);
250 aData.append( aComponents[i].c_str() );
251 aData.append( aVersions.empty() || aVersions[0] == "" ? "unknown" : aVersions[0].c_str() );
252 QTreeWidgetItem* item = new QTreeWidgetItem( aData );
253 if ( aVersions.size() > 1 )
254 item->setForeground( 1, Qt::red );
255 myVersions->addTopLevelItem(item);
262 Fill properties attributes.
264 void SalomeApp_StudyPropertiesDlg::clickOnOk()
266 _PTR(AttributeStudyProperties) propAttr = SalomeApp_Application::getStudy()->GetProperties();
267 //Firstly, store locked flag
269 bool bLocked = myLocked->isChecked();
270 if (propAttr->IsLocked() != bLocked) {
271 propAttr->SetLocked(bLocked);
275 bool needWarning = false;
278 if (QString(propAttr->GetUserName().c_str()) != myAuthor->text().trimmed()) {
279 if(!propAttr->IsLocked()) {
280 propAttr->SetUserName(myAuthor->text().trimmed().toStdString());
288 if (QString(propAttr->GetUnits().c_str()) != myUnits->currentText()) {
289 if(!propAttr->IsLocked()) {
290 propAttr->SetUnits(myUnits->currentText().toStdString());
298 if (QString(propAttr->GetComment().c_str()) != myComment->toPlainText()) {
299 if(!propAttr->IsLocked()) {
300 propAttr->SetComment(myComment->toPlainText().toStdString());
308 SUIT_MessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(),
309 QObject::tr("WRN_WARNING"),
310 QObject::tr("WRN_STUDY_LOCKED") );