X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSalomeApp%2FSalomeApp_StudyPropertiesDlg.cxx;h=5e37e61832de2119a098539203ce109be4731367;hb=3a4b698ac7ed25240f496594293eeab6a839c7d6;hp=aa5cd29f3ebcf9e15a1bb4c3f2ae36c0c86f6943;hpb=760c60aa1b1b88de4d66401e93c6737eb40ef6b3;p=modules%2Fgui.git diff --git a/src/SalomeApp/SalomeApp_StudyPropertiesDlg.cxx b/src/SalomeApp/SalomeApp_StudyPropertiesDlg.cxx index aa5cd29f3..5e37e6183 100644 --- a/src/SalomeApp/SalomeApp_StudyPropertiesDlg.cxx +++ b/src/SalomeApp/SalomeApp_StudyPropertiesDlg.cxx @@ -1,296 +1,315 @@ -// SALOME SalomeApp +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// Copyright (C) 2005 CEA/DEN, EDF R&D +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SALOME SalomeApp // File : SalomeApp_StudyPropertiesDlg.cxx -// Author : Sergey ANIKIN -// Module : SALOME -// $Header$ +// Author : Roman NIKOLAEV #include "SalomeApp_StudyPropertiesDlg.h" -#include "SalomeApp_ListView.h" +#include "SalomeApp_Application.h" #include "SalomeApp_Study.h" #include "SUIT_Session.h" +#include +#include -#include CORBA_SERVER_HEADER(SALOMEDS_Attributes) +// CORBA Headers +#include +#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) -#include -#include -using namespace std; +// QT Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #define DEFAULT_MARGIN 11 -#define DEFAULT_SPACING 6 +#define DEFAULT_SPACING 6 #define SPACER_SIZE 5 #define MIN_LIST_WIDTH 300 #define MIN_LIST_HEIGHT 150 -class SalomeApp_PropItem : public SalomeApp_ListViewItem -{ -public: -// constructor - SalomeApp_PropItem(SalomeApp_ListView* parent, - const QString theName, - const bool theEditable, - const int theUserType) : - SalomeApp_ListViewItem( parent, theName, theEditable ) - { - setUserType(theUserType); - } -// constructor - SalomeApp_PropItem(SalomeApp_ListView* parent, - SalomeApp_ListViewItem* after, - const QString theName, - const bool theEditable, - const int theUserType) : - SalomeApp_ListViewItem( parent, after, theName, theEditable ) - { - setUserType(theUserType); - } -// fills widget with initial values (list or single value) - void fillWidgetWithValues( SalomeApp_EntityEdit* theWidget ) - { - QStringList list; - switch(getUserType()) { - case SalomeApp_StudyPropertiesDlg::prpModeId: - { - list << QObject::tr("PRP_MODE_FROM_SCRATCH") << - QObject::tr("PRP_MODE_FROM_COPYFROM"); - theWidget->insertList(list); - break; - } - case SalomeApp_StudyPropertiesDlg::prpLockedId: - { - list << QObject::tr("PRP_NO") << QObject::tr("PRP_YES"); - theWidget->insertList(list, getValue() == QObject::tr("PRP_NO") ? 0 : 1); - break; - } - case SalomeApp_StudyPropertiesDlg::prpModificationsId: - { - SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if (study) { - _PTR(Study) studyDoc = study->studyDS(); - _PTR(AttributeStudyProperties) propAttr; - if ( studyDoc ) { - propAttr = studyDoc->GetProperties(); - if ( propAttr ) { - std::vector aUsers; - std::vector aMins, aHours, aDays, aMonths, aYears; - propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false); - int aCnt = aUsers.size(); - for ( int i = 0; i < aCnt; i++ ) { - QString val; - val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", - aDays [i], - aMonths[i], - aYears [i], - aHours [i], - aMins [i]); - val = val + " : " + QString(aUsers[i].c_str()); - list.prepend(val); - } - theWidget->setDuplicatesEnabled(true); - theWidget->insertList(list); - } - } - } - break; - } - default: - { - SalomeApp_ListViewItem::fillWidgetWithValues(theWidget); - break; - } - } - } -// finishes editing of entity - virtual UpdateType finishEditing( SalomeApp_EntityEdit* theWidget ) { - if ( getUserType() == SalomeApp_StudyPropertiesDlg::prpModificationsId ) - return utCancel; - else - return SalomeApp_ListViewItem::finishEditing(theWidget); - } -}; +/*!Constructor. Initialize study properties dialog.*/ SalomeApp_StudyPropertiesDlg::SalomeApp_StudyPropertiesDlg(QWidget* parent) - : QDialog(parent, "", TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ), - myChanged( false ) + : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ), + myIsChanged(false) { - setCaption(tr("TLT_STUDY_PROPERTIES")); + setModal( true ); + + setWindowTitle(tr("TLT_STUDY_PROPERTIES")); setSizeGripEnabled( true ); - clearWFlags(Qt::WStyle_ContextHelp); + setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint ); - QGridLayout* mainLayout = new QGridLayout(this); - mainLayout->setMargin(DEFAULT_MARGIN); - mainLayout->setSpacing(DEFAULT_SPACING); - - myPropList = new SalomeApp_ListView(this); - myPropList->addColumn(""); - myPropList->addColumn(""); - myPropList->enableEditing(TRUE); - myPropList->setMinimumSize(MIN_LIST_WIDTH, MIN_LIST_HEIGHT); - mainLayout->addMultiCellWidget(myPropList, 0, 0, 0, 2); + //Author + QLabel* authorLbl = new QLabel(tr("PRP_AUTHOR"),this); + myAuthor = new QLineEdit(this); - myOKBtn = new QPushButton(tr("BUT_OK"), this); - mainLayout->addWidget(myOKBtn, 1, 0); + //Creation date + QLabel* dateLbl = new QLabel(tr("PRP_DATE"),this); + myDate = new QLabel(this); - myCancelBtn = new QPushButton(tr("BUT_CANCEL"), this); - mainLayout->addWidget(myCancelBtn, 1, 2); + //Locked flag + myLocked = new QCheckBox(tr("PRP_LOCKED"), this); - QSpacerItem* spacer1 = new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum); - mainLayout->addItem(spacer1, 1, 1); + //Modification flag + myModification = new QLabel(this); - // Display study properties - SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if (study) - myStudyDoc = study->studyDS(); + //Units + QLabel* unitsLbl = new QLabel(tr("PRP_UNITS"),this); + myUnits = new QComboBox(this); - initData(); + //Comment + QLabel* commentLabel = new QLabel(tr("PRP_COMMENT"),this); + myComment = new QTextEdit(this); + myComment->setMaximumHeight(80); + + //Modifications + QLabel* modificationsLabel = new QLabel(tr("PRP_MODIFICATIONS"),this); + myModifications = new QTreeWidget(this); + myModifications->setRootIsDecorated(false); + myModifications->setUniformRowHeights(true); + myModifications->setAllColumnsShowFocus(true); + myModifications->setColumnCount(2); + myModifications->setMaximumHeight(80); + QStringList columnNames; + columnNames.append(tr("PRP_AUTHOR")); + columnNames.append(tr("PRP_DATE_MODIF")); + myModifications->setHeaderLabels( columnNames ); + + //Component versions + QLabel* versionsLabel = new QLabel(tr("PRP_VERSIONS"),this); + myVersions = new QTreeWidget(this); + myVersions->setRootIsDecorated(false); + myVersions->setUniformRowHeights(true); + myVersions->setAllColumnsShowFocus(true); + myVersions->setColumnCount(2); + myVersions->setMaximumHeight(80); + columnNames.clear(); + columnNames.append(tr("PRP_COMPONENT")); + columnNames.append(tr("PRP_VERSION")); + myVersions->setHeaderLabels( columnNames ); + + QFrame* buttonFrame = new QFrame(this); - connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK())); - connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject())); + QHBoxLayout* horizontalLayout = new QHBoxLayout(buttonFrame); + + myOkButton = new QPushButton(tr("BUT_OK"), buttonFrame); + myCancelButton = new QPushButton(tr("BUT_CANCEL"), buttonFrame); + + horizontalLayout->addWidget(myOkButton); + horizontalLayout->addItem( new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum) ); + horizontalLayout->addWidget(myCancelButton); + + QGridLayout* gridLayout = new QGridLayout(this); + gridLayout->setMargin(DEFAULT_MARGIN); + gridLayout->setSpacing(DEFAULT_SPACING); + gridLayout->addWidget(authorLbl, 0, 0, 1, 1); + gridLayout->addWidget(myAuthor, 0, 1, 1, 1); + gridLayout->addWidget(dateLbl, 1, 0, 1, 1); + gridLayout->addWidget(myDate, 1, 1, 1, 1); + gridLayout->addWidget(myLocked, 2, 0, 1, 1); + gridLayout->addWidget(myModification, 2, 1, 1, 1); + gridLayout->addWidget(unitsLbl, 3, 0, 1, 1); + gridLayout->addWidget(myUnits, 3, 1, 1, 1); + gridLayout->addItem(new QSpacerItem(/*72*/0, 0/*20*/, QSizePolicy::Expanding, QSizePolicy::Minimum), 3, 2, 1, 1); + gridLayout->addWidget(commentLabel, 4, 0, 1, 1); + gridLayout->addWidget(myComment, 4, 1, 1, 2); + gridLayout->addWidget(modificationsLabel, 5, 0, 1, 1); + gridLayout->addWidget(myModifications, 5, 1, 1, 2); + gridLayout->addWidget(versionsLabel, 6, 0, 1, 1); + gridLayout->addWidget(myVersions, 6, 1, 1, 2); + gridLayout->addWidget(buttonFrame, 7, 0, 1, 3); + + connect(myOkButton, SIGNAL(clicked()), this, SLOT(clickOnOk())); + connect(myCancelButton, SIGNAL(clicked()), this, SLOT(reject())); + + initData(); } +/*! + Destructor. +*/ SalomeApp_StudyPropertiesDlg::~SalomeApp_StudyPropertiesDlg() { } +/*! + Data initializetion for dialog.(Study author's name, date of creation etc.) +*/ void SalomeApp_StudyPropertiesDlg::initData() { - bool hasData = myStudyDoc; + bool hasData = (SalomeApp_Application::getStudy() != NULL); _PTR(AttributeStudyProperties) propAttr; - if (hasData) - propAttr = myStudyDoc->GetProperties(); - hasData = hasData && propAttr; - - // Study author's name - SalomeApp_PropItem* item = new SalomeApp_PropItem(myPropList, tr("PRP_AUTHOR")+":", true, prpAuthorId); if (hasData) - item->setValue(propAttr->GetUserName().c_str()); - - // Date of creation - item = new SalomeApp_PropItem(myPropList, item, tr("PRP_DATE")+":", false, prpDateId); + propAttr = SalomeApp_Application::getStudy()->GetProperties(); + hasData = hasData && propAttr; + if (hasData) { + //Creator and creation date + myAuthor->setText(propAttr->GetUserName().c_str()); int minutes, hours, day, month, year; if (propAttr->GetCreationDate(minutes, hours, day, month, year)) { QString strDate; strDate.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", day, month, year, hours, minutes); - item->setValue(strDate); + myDate->setText(strDate); } - } - - // Creation mode -// item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODE")+":", true, prpModeId); -// item->setEditingType( SalomeApp_EntityEdit::etComboBox); -// if (hasData) item->setValue(propAttr->GetCreationMode()); + + //Is Locked? + myLocked->setChecked(propAttr->IsLocked()); - // Locked or not - item = new SalomeApp_PropItem(myPropList, item, tr("PRP_LOCKED")+":", true, prpLockedId); - item->setEditingType( SalomeApp_EntityEdit::etComboBox); - if (hasData) (propAttr->IsLocked()) ? item->setValue(tr("PRP_YES")) : item->setValue(tr("PRP_NO")); + //Is Modified? + bool isModified = false; + SalomeApp_Study* study = dynamic_cast + (SUIT_Session::session()->activeApplication()->activeStudy()); + isModified = study->isModified(); + if (propAttr->IsModified() != isModified) { + propAttr->SetModified((int)isModified); + } + + QString modif = propAttr->IsModified() ? tr( "PRP_MODIFIED" ) : tr( "PRP_NOT_MODIFIED" ); + myModification->setText(modif); + + //Units + QStringList theList; + theList <<""<<"mm"<<"cm"<<"m"<<"km"<<"inch"; + myUnits->insertItems(0,theList); - // Saved or not - item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFIED")+":", false, prpSavedId); - if (hasData) { - if (propAttr->IsModified()) - item->setValue(tr("PRP_YES")); - else - item->setValue(tr("PRP_NO")); - } + QString anUnit = propAttr->GetUnits().c_str(); - // Modifications list - item = new SalomeApp_PropItem(myPropList, item, tr("PRP_MODIFICATIONS")+":", true, prpModificationsId); - item->setEditingType( SalomeApp_EntityEdit::etComboBox); - if (hasData) { + int aFound = -1; + for (int i = 0; i < myUnits->count(); i++) { + if ( myUnits->itemText(i) == anUnit ) { + aFound = i; + break; + } + } + + if (aFound >= 0) { + myUnits->setCurrentIndex(aFound); + } + + //Comments + myComment->setPlainText(propAttr->GetComment().c_str()); + + //Modifications std::vector aUsers; - std::vector aMins, aHours, aDays, aMonths, aYears; + std::vector aMins, aHours, aDays, aMonths, aYears; propAttr->GetModificationsList(aUsers, aMins, aHours, aDays, aMonths, aYears, false); - int aLast = aUsers.size()-1; - if (aLast >= 0) { - QString val; - val.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", - aDays [aLast], - aMonths[aLast], - aYears [aLast], - aHours [aLast], - aMins [aLast]); - val = val + " : " + QString(aUsers[aUsers.size()-1].c_str()); - item->setValue(val); + int aCnt = aUsers.size(); + for ( int i = 0; i < (int)aCnt; i++ ) { + QString date; + date.sprintf("%2.2d/%2.2d/%2d %2.2d:%2.2d", + aDays [i], + aMonths[i], + aYears [i], + aHours [i], + aMins [i]); + QStringList aList; + aList.append(aUsers[i].c_str()); + aList.append(date); + QTreeWidgetItem* item = new QTreeWidgetItem(aList); + myModifications->addTopLevelItem(item); + } + + //Component versions + std::vector aComponents = propAttr->GetStoredComponents(); + for ( int i = 0; i < (int)aComponents.size(); i++ ) { + std::vector aMins, aHours, aDays, aMonths, aYears; + std::vector aVersions = propAttr->GetComponentVersions(aComponents[i]); + QStringList aData; + aData.append( aComponents[i].c_str() ); + aData.append( aVersions.empty() || aVersions[0] == "" ? "unknown" : aVersions[0].c_str() ); + QTreeWidgetItem* item = new QTreeWidgetItem( aData ); + if ( aVersions.size() > 1 ) + item->setForeground( 1, Qt::red ); + myVersions->addTopLevelItem(item); } } - - myOKBtn->setEnabled(hasData); -} - -bool SalomeApp_StudyPropertiesDlg::acceptData() -{ - return TRUE; + adjustSize(); } -void SalomeApp_StudyPropertiesDlg::onOK() +/*! + Fill properties attributes. +*/ +void SalomeApp_StudyPropertiesDlg::clickOnOk() { - myPropList->accept(); - - if (acceptData()) { - _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties(); - myChanged = propChanged(); - if ( propAttr && myChanged ) { - QListViewItemIterator it( myPropList ); - // iterate through all items of the listview - for ( ; it.current(); ++it ) { - SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current()); - switch (item->getUserType()) { - case prpAuthorId: - propAttr->SetUserName(item->getValue().stripWhiteSpace().latin1()); - break; - case prpModeId: - propAttr->SetCreationMode(item->getValue().stripWhiteSpace().latin1()); - break; - case prpLockedId: - propAttr->SetLocked(item->getValue().compare(tr("PRP_YES")) == 0); - break; - default: - break; - } + _PTR(AttributeStudyProperties) propAttr = SalomeApp_Application::getStudy()->GetProperties(); + //Firstly, store locked flag + if(propAttr) { + bool bLocked = myLocked->isChecked(); + if (propAttr->IsLocked() != bLocked) { + propAttr->SetLocked(bLocked); + myIsChanged = true; + } + + bool needWarning = false; + + //Author + if (QString(propAttr->GetUserName().c_str()) != myAuthor->text().trimmed()) { + if(!propAttr->IsLocked()) { + propAttr->SetUserName(myAuthor->text().trimmed().toStdString()); + myIsChanged = true; + } else { + needWarning = true; } } - accept(); - } -} -bool SalomeApp_StudyPropertiesDlg::propChanged() { - _PTR(AttributeStudyProperties) propAttr = myStudyDoc->GetProperties(); - if ( propAttr ) { - QListViewItemIterator it( myPropList ); - // iterate through all items of the listview - for ( ; it.current(); ++it ) { - SalomeApp_PropItem* item = (SalomeApp_PropItem*)(it.current()); - switch (item->getUserType()) { - case prpAuthorId: - if ( QString( propAttr->GetUserName().c_str() ) != item->getValue().stripWhiteSpace() ) { - return true; - } - break; - case prpModeId: - if ( QString( propAttr->GetCreationMode().c_str() ) != item->getValue().stripWhiteSpace() ) { - return true; - } - break; - case prpLockedId: - { - bool bLocked = item->getValue().compare( tr( "PRP_YES" ) ) == 0; - if ( propAttr->IsLocked() != bLocked ) { - return true; - } - break; - } - default: - break; + //Unit + if (QString(propAttr->GetUnits().c_str()) != myUnits->currentText()) { + if(!propAttr->IsLocked()) { + propAttr->SetUnits(myUnits->currentText().toStdString()); + myIsChanged = true; + } else { + needWarning = true; + } + } + + //Comment + if (QString(propAttr->GetComment().c_str()) != myComment->toPlainText()) { + if(!propAttr->IsLocked()) { + propAttr->SetComment(myComment->toPlainText().toStdString()); + myIsChanged = true; + } else { + needWarning = true; } } + + if(needWarning) { + SUIT_MessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_STUDY_LOCKED") ); + } + + accept(); } - return false; }