From: vsr Date: Mon, 25 Jun 2007 11:55:05 +0000 (+0000) Subject: Porting to Qt 4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dac7648ef3df12c816386da8e139cb4c1a19de00;p=modules%2Fgui.git Porting to Qt 4 --- diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 61c7bb715..f3c982f2e 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -385,52 +385,46 @@ bool SalomeApp_Application::onOpenDoc( const QString& aName ) /*!SLOT. Load document.*/ void SalomeApp_Application::onLoadDoc() { - QString name, studyname, ext; - - SalomeApp_LoadStudiesDlg aDlg( desktop(), TRUE); + QString studyName; std::vector List = studyMgr()->GetOpenStudies(); SUIT_Session* aSession = SUIT_Session::session(); QList aAppList = aSession->applications(); - SUIT_Application* aApp = 0; - for (unsigned int ind = 0; ind < List.size(); ind++) { - studyname = List[ind].c_str(); - //Add to list only unloaded studies + QStringList unloadedStudies; + + for ( unsigned int ind = 0; ind < List.size(); ind++ ) { + studyName = List[ind].c_str(); + // Add to list only unloaded studies bool isAlreadyOpen = false; QListIterator it( aAppList ); - while ( it.hasNext() && !isAlreadyOpen ) - { - aApp = it.next(); - if(!aApp || !aApp->activeStudy()) continue; - if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true; - } + while ( it.hasNext() && !isAlreadyOpen ) { + SUIT_Application* aApp = it.next(); + if( !aApp || !aApp->activeStudy() ) + continue; + if ( aApp->activeStudy()->studyName() == studyName ) + isAlreadyOpen = true; + } - if ( !isAlreadyOpen ) aDlg.ListComponent->addItem( studyname ); + if ( !isAlreadyOpen ) + unloadedStudies << studyName; } - int retVal = aDlg.exec(); - studyname = aDlg.ListComponent->currentItem()->text(); - - if (retVal == QDialog::Rejected) - return; - - if ( studyname.isNull() || studyname.isEmpty() ) + studyName = SalomeApp_LoadStudiesDlg::selectStudy( desktop(), unloadedStudies ); + if ( studyName.isEmpty() ) return; - name = studyname; #ifndef WIN32 - //this code replace marker of windows drive and path become invalid therefore + // this code replaces marker of windows drive and path become invalid therefore // defines placed there - name.replace( QRegExp(":"), "/" ); + studyName.replace( QRegExp(":"), "/" ); #endif - if( LightApp_Application::onLoadDoc( name ) ) - { - updateWindows(); - updateViewManagers(); - updateObjectBrowser(true); + if( LightApp_Application::onLoadDoc( studyName ) ) { + updateWindows(); + updateViewManagers(); + updateObjectBrowser( true ); } } diff --git a/src/SalomeApp/SalomeApp_LoadStudiesDlg.cxx b/src/SalomeApp/SalomeApp_LoadStudiesDlg.cxx index 9105ab16f..1d44048ef 100644 --- a/src/SalomeApp/SalomeApp_LoadStudiesDlg.cxx +++ b/src/SalomeApp/SalomeApp_LoadStudiesDlg.cxx @@ -16,12 +16,15 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "SalomeApp_LoadStudiesDlg.h" #include -#include +#include +#include #include #include +#include #define SPACING_SIZE 6 #define MARGIN_SIZE 11 @@ -29,62 +32,103 @@ #define MIN_LISTBOX_HEIGHT 100 /*! -* \brief creates a Load study dialog box -* \param parent a parent widget -* \param modal bool argument, if true the dialog box is a modal dialog box -* \param f style flags + \class SalomeApp_LoadStudiesDlg + \brief Dialog box which allows selecting study to be loaded + from the list. */ -SalomeApp_LoadStudiesDlg::SalomeApp_LoadStudiesDlg( QWidget* parent, bool modal, Qt::WindowFlags fl ) -: QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ) +/*! + \brief Constructor + \param parent a parent widget + \param studies list of study names +*/ +SalomeApp_LoadStudiesDlg::SalomeApp_LoadStudiesDlg( QWidget* parent, const QStringList& studies ) +: QDialog( parent ) { - setObjectName( "SalomeApp_LoadStudiesDlg" ); - setModal( modal ); + setModal( true ); - resize( 321, 181 ); - setWindowTitle( tr("DLG_LOAD_STUDY_CAPTION") ); - setSizeGripEnabled( TRUE ); + setWindowTitle( tr("DLG_LOAD_STUDY_CAPTION") ); + setSizeGripEnabled( true ); - QGridLayout* aTopLayout = new QGridLayout(this); - aTopLayout->setMargin(MARGIN_SIZE); - aTopLayout->setSpacing(SPACING_SIZE); + QVBoxLayout* topLayout = new QVBoxLayout( this ); + topLayout->setMargin( MARGIN_SIZE ); + topLayout->setSpacing( SPACING_SIZE ); + + QLabel* lab = new QLabel( tr( "MEN_STUDIES_CHOICE" ), this ); + + myButtonOk = new QPushButton( tr( "BUT_OK" ), this ); + myButtonOk->setAutoDefault( true ); + myButtonOk->setDefault( true ); + + QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ), this ); + + QHBoxLayout* btnLayout = new QHBoxLayout; + btnLayout->setSpacing( SPACING_SIZE ); + btnLayout->setMargin( 0 ); + btnLayout->addWidget( myButtonOk ); + btnLayout->addStretch(); + btnLayout->addWidget( buttonCancel ); - TextLabel1 = new QLabel( this ); - TextLabel1->setObjectName( "TextLabel1" ); - TextLabel1->setGeometry( QRect( 11, 12, 297, 16 ) ); - TextLabel1->setText( tr( "MEN_STUDIES_CHOICE" ) ); + myList = new QListWidget( this ); + myList->setMinimumSize( MIN_LISTBOX_WIDTH, MIN_LISTBOX_HEIGHT ); + myList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, + QSizePolicy::Expanding ) ); + myList->setSelectionMode( QAbstractItemView::SingleSelection ); - QHBoxLayout* aBtnLayout = new QHBoxLayout; - aBtnLayout->setSpacing( SPACING_SIZE ); - aBtnLayout->setMargin( 0 ); - - buttonOk = new QPushButton( this ); - buttonOk->setObjectName( "buttonOk" ); - buttonOk->setText( tr( "BUT_OK" ) ); - buttonOk->setAutoDefault( true ); - buttonOk->setDefault( true ); - - buttonCancel = new QPushButton( this ); - buttonCancel->setObjectName( "buttonCancel" ); - buttonCancel->setText( tr( "BUT_CANCEL" ) ); - buttonCancel->setAutoDefault( true ); + topLayout->addWidget( lab ); + topLayout->addWidget( myList ); + topLayout->addLayout( btnLayout ); - aBtnLayout->addWidget( buttonOk ); - aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); - aBtnLayout->addWidget( buttonCancel ); + connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); + connect( myList, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ), + this, SLOT( accept() ) ); + connect( myList, SIGNAL( itemSelectionChanged() ), + this, SLOT( updateState() ) ); + myList->addItems( studies ); + + updateState(); +} - ListComponent = new QListWidget( this ); - ListComponent->setObjectName( "ListComponent" ); - ListComponent->setMinimumSize(MIN_LISTBOX_WIDTH, MIN_LISTBOX_HEIGHT); - ListComponent->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); - ListComponent->setSelectionMode(QAbstractItemView::SingleSelection); +/*! + \brief Destructor +*/ +SalomeApp_LoadStudiesDlg::~SalomeApp_LoadStudiesDlg() +{ +} - aTopLayout->addWidget(TextLabel1, 0, 0); - aTopLayout->addWidget(ListComponent, 1, 0); - aTopLayout->addLayout(aBtnLayout, 2, 0); +/*! + \brief Updates buttons state. +*/ +void SalomeApp_LoadStudiesDlg::updateState() +{ + myButtonOk->setEnabled( myList->currentItem() != 0 ); +} - // signals and slots connections - connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); - connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); +/*! + \brief Get selected study name + \return selected study name or null string if study is not selected +*/ +QString SalomeApp_LoadStudiesDlg::selectedStudy() +{ + QString study; + if ( myList->currentItem() ) + study = myList->currentItem()->text(); + return study; } +/*! + \brief Executes dialog box to select study from the list + and returns the study selected. + \param parent parent widget + \param studies list of study names + \return select study (or null string if dialog box is rejected) +*/ +QString SalomeApp_LoadStudiesDlg::selectStudy( QWidget* parent, const QStringList& studies ) +{ + SalomeApp_LoadStudiesDlg dlg( parent, studies ); + QString study; + if ( dlg.exec() == QDialog::Accepted ) + study = dlg.selectedStudy(); + return study; +} diff --git a/src/SalomeApp/SalomeApp_LoadStudiesDlg.h b/src/SalomeApp/SalomeApp_LoadStudiesDlg.h index a523d034e..35c9a9847 100644 --- a/src/SalomeApp/SalomeApp_LoadStudiesDlg.h +++ b/src/SalomeApp/SalomeApp_LoadStudiesDlg.h @@ -16,49 +16,38 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef STD_LOADSTUDIESDLG_H -#define STD_LOADSTUDIESDLG_H -#include +#ifndef SALOMEAPP_LOADSTUDIESDLG_H +#define SALOMEAPP_LOADSTUDIESDLG_H + +#include "SalomeApp.h" #include -class QLabel; class QListWidget; class QPushButton; +class QStringList; -/*!\class SalomeApp_LoadStudiesDlg - * \brief Describes a dialog box that gives a list of opened studies. - * - */ -class STD_EXPORT SalomeApp_LoadStudiesDlg : public QDialog +class SALOMEAPP_EXPORT SalomeApp_LoadStudiesDlg : public QDialog { - Q_OBJECT + Q_OBJECT + +private: + SalomeApp_LoadStudiesDlg( QWidget*, const QStringList& ); public: - SalomeApp_LoadStudiesDlg( QWidget* parent = 0, bool modal = FALSE, Qt::WindowFlags fl = 0 ); - ~SalomeApp_LoadStudiesDlg() {} + ~SalomeApp_LoadStudiesDlg(); - /*!\var TextLabel1 - * \brief stores a dialog text label - */ - QLabel* TextLabel1; - - /*!\var buttonOk - * \brief stores a dialog button OK - */ - QPushButton* buttonOk; + static QString selectStudy( QWidget*, const QStringList& ); - /*!\var buttonCancel - * \brief stores a dialog button Cancel - */ - QPushButton* buttonCancel; + QString selectedStudy(); - /*!\var ListComponent - * \brief stores a dialog list compoent - */ - QListWidget* ListComponent; +private slots: + void updateState(); +private: + QListWidget* myList; + QPushButton* myButtonOk; }; #endif // STD_LOADSTUDIESDLG_H