1 // Copyright (C) 2007-2016 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_Study.h"
30 #include "SUIT_Session.h"
31 #include <SUIT_Desktop.h>
32 #include <SUIT_MessageBox.h>
35 #include <SALOMEconfig.h>
36 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
39 #include <QPushButton>
40 #include <QGridLayout>
41 #include <QHBoxLayout>
48 #include <QTreeWidget>
49 #include <QPushButton>
53 #define DEFAULT_MARGIN 11
54 #define DEFAULT_SPACING 6
56 #define MIN_LIST_WIDTH 300
57 #define MIN_LIST_HEIGHT 150
60 /*!Constructor. Initialize study properties dialog.*/
61 SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent)
62 : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
67 setWindowTitle(tr("TLT_STUDY_PROPERTIES"));
68 setSizeGripEnabled( true );
70 setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint );
72 // Display study properties
73 SalomeApp_Study* study =
74 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
76 myStudyDoc = study->studyDS();
79 QLabel* authorLbl = new QLabel(tr("PRP_AUTHOR"),this);
80 myAuthor = new QLineEdit(this);
83 QLabel* dateLbl = new QLabel(tr("PRP_DATE"),this);
84 myDate = new QLabel(this);
87 myLocked = new QCheckBox(tr("PRP_LOCKED"), this);
90 myModification = new QLabel(this);
93 QLabel* unitsLbl = new QLabel(tr("PRP_UNITS"),this);
94 myUnits = new QComboBox(this);
97 QLabel* commentLabel = new QLabel(tr("PRP_COMMENT"),this);
98 myComment = new QTextEdit(this);
99 myComment->setMaximumHeight(80);
102 QLabel* modificationsLabel = new QLabel(tr("PRP_MODIFICATIONS"),this);
103 myModifications = new QTreeWidget(this);
104 myModifications->setRootIsDecorated(false);
105 myModifications->setUniformRowHeights(true);
106 myModifications->setAllColumnsShowFocus(true);
107 myModifications->setColumnCount(2);
108 myModifications->setMaximumHeight(80);
109 QStringList columnNames;
110 columnNames.append(tr("PRP_AUTHOR"));
111 columnNames.append(tr("PRP_DATE_MODIF"));
112 myModifications->setHeaderLabels( columnNames );
115 QLabel* versionsLabel = new QLabel(tr("PRP_VERSIONS"),this);
116 myVersions = new QTreeWidget(this);
117 myVersions->setRootIsDecorated(false);
118 myVersions->setUniformRowHeights(true);
119 myVersions->setAllColumnsShowFocus(true);
120 myVersions->setColumnCount(2);
121 myVersions->setMaximumHeight(80);
123 columnNames.append(tr("PRP_COMPONENT"));
124 columnNames.append(tr("PRP_VERSION"));
125 myVersions->setHeaderLabels( columnNames );
127 QFrame* buttonFrame = new QFrame(this);
129 QHBoxLayout* horizontalLayout = new QHBoxLayout(buttonFrame);
131 myOkButton = new QPushButton(tr("BUT_OK"), buttonFrame);
132 myCancelButton = new QPushButton(tr("BUT_CANCEL"), buttonFrame);
134 horizontalLayout->addWidget(myOkButton);
135 horizontalLayout->addItem( new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum) );
136 horizontalLayout->addWidget(myCancelButton);
138 QGridLayout* gridLayout = new QGridLayout(this);
139 gridLayout->setMargin(DEFAULT_MARGIN);
140 gridLayout->setSpacing(DEFAULT_SPACING);
141 gridLayout->addWidget(authorLbl, 0, 0, 1, 1);
142 gridLayout->addWidget(myAuthor, 0, 1, 1, 1);
143 gridLayout->addWidget(dateLbl, 1, 0, 1, 1);
144 gridLayout->addWidget(myDate, 1, 1, 1, 1);
145 gridLayout->addWidget(myLocked, 2, 0, 1, 1);
146 gridLayout->addWidget(myModification, 2, 1, 1, 1);
147 gridLayout->addWidget(unitsLbl, 3, 0, 1, 1);
148 gridLayout->addWidget(myUnits, 3, 1, 1, 1);
149 gridLayout->addItem(new QSpacerItem(/*72*/0, 0/*20*/, QSizePolicy::Expanding, QSizePolicy::Minimum), 3, 2, 1, 1);
150 gridLayout->addWidget(commentLabel, 4, 0, 1, 1);
151 gridLayout->addWidget(myComment, 4, 1, 1, 2);
152 gridLayout->addWidget(modificationsLabel, 5, 0, 1, 1);
153 gridLayout->addWidget(myModifications, 5, 1, 1, 2);
154 gridLayout->addWidget(versionsLabel, 6, 0, 1, 1);
155 gridLayout->addWidget(myVersions, 6, 1, 1, 2);
156 gridLayout->addWidget(buttonFrame, 7, 0, 1, 3);
158 connect(myOkButton, SIGNAL(clicked()), this, SLOT(clickOnOk()));
159 connect(myCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
167 SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg()
172 Data initializetion for dialog.(Study author's name, date of creation etc.)
174 void SalomeApp_StudyPropertiesDlg::initData()
176 bool hasData = (myStudyDoc != NULL);
177 _PTR(AttributeStudyProperties) propAttr;
179 propAttr = myStudyDoc->GetProperties();
180 hasData = hasData && propAttr;
183 //Creator and creation date
184 myAuthor->setText(propAttr->GetUserName().c_str());
185 int minutes, hours, day, month, year;
186 if (propAttr->GetCreationDate(minutes, hours, day, month, year)) {
188 strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes);
189 myDate->setText(strDate);
193 myLocked->setChecked(propAttr->IsLocked());
196 bool isModified = false;
197 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>
198 (SUIT_Session::session()->activeApplication()->activeStudy());
199 isModified = study->isModified();
200 if (propAttr->IsModified() != isModified) {
201 propAttr->SetModified((int)isModified);
204 QString modif = propAttr->IsModified() ? tr( "PRP_MODIFIED" ) : tr( "PRP_NOT_MODIFIED" );
205 myModification->setText(modif);
209 theList <<""<<"mm"<<"cm"<<"m"<<"km"<<"inch";
210 myUnits->insertItems(0,theList);
212 QString anUnit = propAttr->GetUnits().c_str();
215 for (int i = 0; i < myUnits->count(); i++) {
216 if ( myUnits->itemText(i) == anUnit ) {
223 myUnits->setCurrentIndex(aFound);
227 myComment->setPlainText(propAttr->GetComment().c_str());
230 std::vector<std::string> aUsers;
231 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
232 propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false);
233 int aCnt = aUsers.size();
234 for ( int i = 0; i < aCnt; i++ ) {
236 date.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d",
243 aList.append(aUsers[i].c_str());
245 QTreeWidgetItem* item = new QTreeWidgetItem(aList);
246 myModifications->addTopLevelItem(item);
250 std::vector<std::string> aComponents = propAttr->GetStoredComponents();
251 for ( int i = 0; i < aComponents.size(); i++ ) {
252 std::vector<int> aMins, aHours, aDays, aMonths, aYears;
253 std::vector<std::string> aVersions = propAttr->GetComponentVersions(aComponents[i]);
255 aData.append( aComponents[i].c_str() );
256 aData.append( aVersions.empty() || aVersions[0] == "" ? "unknown" : aVersions[0].c_str() );
257 QTreeWidgetItem* item = new QTreeWidgetItem( aData );
258 if ( aVersions.size() > 1 )
259 item->setForeground( 1, Qt::red );
260 myVersions->addTopLevelItem(item);
267 Fill properties attributes.
269 void SalomeApp_StudyPropertiesDlg::clickOnOk()
271 _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties();
272 //Firstly, store locked flag
274 bool bLocked = myLocked->isChecked();
275 if (propAttr->IsLocked() != bLocked) {
276 propAttr->SetLocked(bLocked);
280 bool needWarning = false;
283 if (QString(propAttr->GetUserName().c_str()) != myAuthor->text().trimmed()) {
284 if(!propAttr->IsLocked()) {
285 propAttr->SetUserName(myAuthor->text().trimmed().toStdString());
293 if (QString(propAttr->GetUnits().c_str()) != myUnits->currentText()) {
294 if(!propAttr->IsLocked()) {
295 propAttr->SetUnits(myUnits->currentText().toStdString());
303 if (QString(propAttr->GetComment().c_str()) != myComment->toPlainText()) {
304 if(!propAttr->IsLocked()) {
305 propAttr->SetComment(myComment->toPlainText().toStdString());
313 SUIT_MessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(),
314 QObject::tr("WRN_WARNING"),
315 QObject::tr("WRN_STUDY_LOCKED") );