/*!SLOT. Load document.*/
void SalomeApp_Application::onLoadDoc()
{
- QString name, studyname, ext;
-
- SalomeApp_LoadStudiesDlg aDlg( desktop(), TRUE);
+ QString studyName;
std::vector<std::string> List = studyMgr()->GetOpenStudies();
SUIT_Session* aSession = SUIT_Session::session();
QList<SUIT_Application*> 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<SUIT_Application*> 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 );
}
}
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
#include "SalomeApp_LoadStudiesDlg.h"
#include <QLabel>
-#include <QGridLayout>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
#include <QListWidget>
#include <QPushButton>
+#include <QStringList>
#define SPACING_SIZE 6
#define MARGIN_SIZE 11
#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;
+}
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef STD_LOADSTUDIESDLG_H
-#define STD_LOADSTUDIESDLG_H
-#include <STD.h>
+#ifndef SALOMEAPP_LOADSTUDIESDLG_H
+#define SALOMEAPP_LOADSTUDIESDLG_H
+
+#include "SalomeApp.h"
#include <QDialog>
-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