From: stv Date: Fri, 8 Sep 2006 12:49:58 +0000 (+0000) Subject: Slot onDeleteView() renamed as onClosingView(). X-Git-Tag: LAST_STABLE_VERSION_21_09_2006_ON_3_2_0~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=368ae91645916edada4660ddaec846d602599a2c;p=modules%2Fgui.git Slot onDeleteView() renamed as onClosingView(). Handler QWidget::closeEvent() not invoked for SUIT_ViewWindow. View window hides and removes by the virtual method SUIT_ViewManager::closeView(). User can define own behavior of window closing. Identificator assignment moved on the base level - SUIT_ViewManager. Useless id's removed from inherit classes. Title mechanism in the SUIT_ViewManager was changed. Now view manager support title for views with specific tags: %M - view manager number, %V - view number. --- diff --git a/src/SUIT/SUIT_ViewManager.cxx b/src/SUIT/SUIT_ViewManager.cxx index 619b9c488..9d2e7e186 100755 --- a/src/SUIT/SUIT_ViewManager.cxx +++ b/src/SUIT/SUIT_ViewManager.cxx @@ -23,12 +23,15 @@ #include "SUIT_Study.h" #include +#include #include #ifdef WNT #include #endif +QMap SUIT_ViewManager::_ViewMgrId; + /*!\class SUIT_ViewManager. * Class provide manipulation with view windows. */ @@ -39,17 +42,20 @@ SUIT_ViewManager::SUIT_ViewManager( SUIT_Study* theStudy, SUIT_ViewModel* theViewModel ) : QObject( 0 ), myDesktop( theDesktop ), -myTitle( "Default viewer" ), +myTitle( "Default: %M - viewer %V" ), myStudy( NULL ) { myViewModel = 0; myActiveView = 0; - setViewModel(theViewModel); - connect(theDesktop, SIGNAL(windowActivated(SUIT_ViewWindow*)), - this, SLOT(onWindowActivated(SUIT_ViewWindow*))); + setViewModel( theViewModel ); + + myId = useNewId( getType() ); + + connect( theDesktop, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) ); myStudy = theStudy; - if( myStudy ) + if ( myStudy ) connect( myStudy, SIGNAL( destroyed() ), this, SLOT( onDeleteStudy() ) ); } @@ -63,6 +69,26 @@ SUIT_ViewManager::~SUIT_ViewManager() } } +int SUIT_ViewManager::useNewId( const QString& type ) +{ + if ( !_ViewMgrId.contains( type ) ) + _ViewMgrId.insert( type, 0 ); + + int id = _ViewMgrId[type]; + _ViewMgrId[type]++; + return id; +} + +void SUIT_ViewManager::setTitle( const QString& theTitle ) +{ + if ( myTitle == theTitle ) + return; + + myTitle = theTitle; + for ( uint i = 0; i < myViews.count(); i++ ) + setViewName( myViews[i] ); +} + /*!Sets view model \a theViewModel to view manager.*/ void SUIT_ViewManager::setViewModel(SUIT_ViewModel* theViewModel) { @@ -76,10 +102,31 @@ void SUIT_ViewManager::setViewModel(SUIT_ViewModel* theViewModel) } /*!Sets view name for view window \a theView.*/ -void SUIT_ViewManager::setViewName(SUIT_ViewWindow* theView) +void SUIT_ViewManager::setViewName( SUIT_ViewWindow* theView ) { - int aPos = myViews.find(theView); - theView->setCaption(myTitle + QString(":%1").arg(aPos+1)); + QString title = prepareTitle( getTitle(), myId + 1, myViews.find( theView ) + 1 ); + theView->setCaption( title ); +} + +QString SUIT_ViewManager::prepareTitle( const QString& title, const int mId, const int vId ) +{ + QString res = title; + QRegExp re( "%[%MV]" ); + int i = 0; + while ( ( i = re.search( res, i ) ) != -1 ) + { + QString rplc; + QString str = res.mid( i, re.matchedLength() ); + if ( str == QString( "%%" ) ) + rplc = QString( "%" ); + else if ( str == QString( "%M" ) ) + rplc = QString::number( mId ); + else if ( str == QString( "%V" ) ) + rplc = QString::number( vId ); + res.replace( i, re.matchedLength(), rplc ); + i += rplc.length(); + } + return res; } /*! Creates View, adds it into list of views and returns just created view window*/ @@ -131,7 +178,7 @@ bool SUIT_ViewManager::insertView(SUIT_ViewWindow* theView) } connect(theView, SIGNAL(closing(SUIT_ViewWindow*)), - this, SLOT(onDeleteView(SUIT_ViewWindow*))); + this, SLOT(onClosingView(SUIT_ViewWindow*))); connect(theView, SIGNAL(mousePressed(SUIT_ViewWindow*, QMouseEvent*)), this, SLOT(onMousePressed(SUIT_ViewWindow*, QMouseEvent*))); @@ -168,10 +215,31 @@ bool SUIT_ViewManager::insertView(SUIT_ViewWindow* theView) /*!Emit delete view. Remove view window \a theView from view manager. */ -void SUIT_ViewManager::onDeleteView(SUIT_ViewWindow* theView) +void SUIT_ViewManager::onClosingView( SUIT_ViewWindow* theView ) { - emit deleteView(theView); - removeView(theView); + closeView( theView ); +} + +/*! + Remove the view window \a theView from view manager and destroy it. +*/ +void SUIT_ViewManager::closeView( SUIT_ViewWindow* theView ) +{ + if ( !theView ) + return; + + QGuardedPtr view( theView ); + + view->hide(); + + if ( !view->testWFlags( WDestructiveClose ) ) + return; + + emit deleteView( view ); + removeView( view ); + + if ( view ) + delete view; } /*!Remove view window \a theView from view manager. @@ -188,6 +256,26 @@ void SUIT_ViewManager::removeView(SUIT_ViewWindow* theView) emit lastViewClosed(this); } +/*! + Set or clear flag Qt::WDestructiveClose for all views +*/ +void SUIT_ViewManager::setDestructiveClose( const bool on ) +{ + for ( uint i = 0; i < myViews.count(); i++ ) + myViews[i]->setDestructiveClose( on ); +} + +/*! + Returns 'true' if any of views (view windows) is visible. +*/ +bool SUIT_ViewManager::isVisible() const +{ + bool res = false; + for ( uint i = 0; i < myViews.count() && !res; i++ ) + res = myViews[i]->isVisibleTo( myViews[i]->parentWidget() ); + return res; +} + /*! Show or hide all views (view windows) */ @@ -223,17 +311,15 @@ void SUIT_ViewManager::onWindowActivated(SUIT_ViewWindow* view) */ void SUIT_ViewManager::closeAllViews() { - unsigned int aSize = myViews.size(); - for (uint i = 0; i < aSize; i++) { - if (myViews[i]) - myViews[i]->close(); - } + for ( uint i = 0; i < myViews.size(); i++ ) + delete myViews[i]; + myViews.clear(); } /*! *\retval QString - type of view model. */ -QString SUIT_ViewManager::getType() const +QString SUIT_ViewManager::getType() const { return (!myViewModel)? "": myViewModel->getType(); } diff --git a/src/SUIT/SUIT_ViewManager.h b/src/SUIT/SUIT_ViewManager.h index 8cacbe253..9fdd2ecd8 100755 --- a/src/SUIT/SUIT_ViewManager.h +++ b/src/SUIT/SUIT_ViewManager.h @@ -59,12 +59,14 @@ public: int getViewsCount() { return myViews.count(); } QPtrVector getViews() { return myViews; } - QString getTitle() const { return myTitle;} - void setTitle(QString theTitle) { myTitle = theTitle; } + QString getTitle() const { return myTitle; } + virtual void setTitle( const QString& ); SUIT_ViewWindow* createViewWindow(); + bool isVisible() const; virtual void setShown( const bool ); + virtual void setDestructiveClose( const bool ); public slots: void createView(); @@ -85,8 +87,8 @@ signals: protected slots: void onWindowActivated(SUIT_ViewWindow*); - void onDeleteView(SUIT_ViewWindow* theView); - void onMousePressed(SUIT_ViewWindow* theView, QMouseEvent* theEvent); + void onClosingView( SUIT_ViewWindow* ); + void onMousePressed(SUIT_ViewWindow*, QMouseEvent* ); void onDeleteStudy(); private slots: @@ -101,8 +103,14 @@ protected: /*! Removes the View from internal Views Vector.*/ virtual void removeView(SUIT_ViewWindow* theView); + /*! Close the specified View.*/ + virtual void closeView(SUIT_ViewWindow* theView); + /*! Used to set unique name for the view.*/ virtual void setViewName(SUIT_ViewWindow* theView); + QString prepareTitle( const QString&, const int, const int ); + + static int useNewId( const QString& ); protected: SUIT_Desktop* myDesktop; @@ -110,8 +118,11 @@ protected: QPtrVector myViews; SUIT_ViewWindow* myActiveView; + int myId; QString myTitle; SUIT_Study* myStudy; + + static QMap _ViewMgrId; }; #ifdef WIN32 diff --git a/src/SUIT/SUIT_ViewWindow.cxx b/src/SUIT/SUIT_ViewWindow.cxx index 0df3081c3..faf064fb5 100755 --- a/src/SUIT/SUIT_ViewWindow.cxx +++ b/src/SUIT/SUIT_ViewWindow.cxx @@ -111,11 +111,22 @@ bool SUIT_ViewWindow::dumpViewToFormat( const QString& fileName, const QString& return dumpViewToFormat( dumpView(), fileName, format ); } +/*! + Set or clear flag Qt::WDestructiveClose +*/ +void SUIT_ViewWindow::setDestructiveClose( const bool on ) +{ + if ( on ) + setWFlags( WDestructiveClose ); + else + clearWFlags( WDestructiveClose ); +} + /*! Close event \a theEvent. */ void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent) { - QMainWindow::closeEvent( theEvent ); +// QMainWindow::closeEvent( theEvent ); emit closing( this ); } diff --git a/src/SUIT/SUIT_ViewWindow.h b/src/SUIT/SUIT_ViewWindow.h index 2e5eb7804..6a6a6f869 100755 --- a/src/SUIT/SUIT_ViewWindow.h +++ b/src/SUIT/SUIT_ViewWindow.h @@ -54,6 +54,8 @@ public: virtual QString getVisualParameters(); virtual void setVisualParameters( const QString& parameters ); + void setDestructiveClose( const bool ); + public slots: virtual void onDumpView();