+
+/*!
+ Internal method.
+ Returns all top level toolbars.
+ Note : Result list contains only main window toolbars, not including toolbars from viewers.
+*/
+QList<QToolBar*> LightApp_Application::findToolBars() {
+ QList<QToolBar*> aResult;
+ QList<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
+ for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit ) {
+ QToolBar* tb = *tit;
+ QObject* po = Qtx::findParent( tb, "QMainWindow" );
+ if ( po != desktop() )
+ continue;
+ aResult.append(tb);
+ }
+ return aResult;
+}
+
+/*!
+ Internal method to parse toolbars and dockable windows state.
+ */
+QByteArray LightApp_Application::processState(QByteArray& input,
+ const bool processWin,
+ const bool processTb,
+ const bool isRestoring,
+ QByteArray defaultState) {
+
+ QByteArray aRes;
+ bool hasDefaultState = !defaultState.isEmpty();
+ bool isDockWinWriten = false;
+ int nbDocWin = -1;
+ //Write date from users settings
+ if(isRestoring){
+ QDataStream tmpInputData(&input, QIODevice::ReadOnly);
+ int marker, version;
+ uchar dockmarker;
+ tmpInputData >> marker;
+ tmpInputData >> version;
+ tmpInputData >> dockmarker;
+ tmpInputData >> nbDocWin;
+ }
+ if(processWin && processTb && !isRestoring) {
+ aRes = input;
+ } else if(!processWin && !processTb ) {
+ if(hasDefaultState)
+ aRes = defaultState;
+ } else {
+ QDataStream aData(&aRes, QIODevice::WriteOnly);
+ QList<QToolBar*> aToolBars = findToolBars();
+
+ QStringList aNames;
+ for ( QList<QToolBar*>::iterator tit = aToolBars.begin(); tit != aToolBars.end(); ++tit ) {
+ QToolBar* tb = *tit;
+ aNames.append(tb->objectName());
+ }
+
+ int toolBarMarkerIndex = getToolbarMarkerIndex(input,aNames);
+ QDataStream anInputData(&input, QIODevice::ReadOnly);
+ if(toolBarMarkerIndex < 0)
+ return aRes;
+
+ int toolBarMarkerIndexDef;
+ if(hasDefaultState) {
+ toolBarMarkerIndexDef = getToolbarMarkerIndex(defaultState, aNames);
+ if(toolBarMarkerIndexDef < 0)
+ return aRes;
+ }
+ QDataStream anInputDataDef(&defaultState, QIODevice::ReadOnly);
+
+ QDataStream* aTargetData = 0;
+ int aTargetIndex = -1;
+
+ QByteArray currentArr = desktop()->saveState();
+ QDataStream anInputDataCur(¤tArr, QIODevice::ReadOnly);
+ bool useInputData = !isRestoring || (isRestoring && nbDocWin > 0);
+ if(processWin && useInputData) {
+ aTargetData = &anInputData;
+ aTargetIndex = toolBarMarkerIndex;
+ } else {
+ //Write date from default settings
+ if(hasDefaultState) {
+ aTargetData = &anInputDataDef;
+ aTargetIndex = toolBarMarkerIndexDef;
+ } else {
+ //If no default state, write current snapshot of the dockable windows
+ if(isRestoring) {
+ aTargetData = &anInputDataCur;
+ int toolBarMarkerIndexCur = getToolbarMarkerIndex(currentArr, aNames);
+ aTargetIndex = toolBarMarkerIndexCur;
+ }
+ }
+ }
+
+ if(aTargetData && aTargetIndex >= 0 ) {
+ aTargetData->device()->seek(0);
+ while( aTargetData->device()->pos() < aTargetIndex ) {
+ uchar ch;
+ *aTargetData >> ch;
+ aData<<ch;
+ }
+ isDockWinWriten = true;
+ }
+
+ aTargetData = 0;
+ aTargetIndex = -1;
+
+ if(processTb) {
+ aTargetData = &anInputData;
+ aTargetIndex = toolBarMarkerIndex;
+ } else {
+ if(hasDefaultState) {
+ aTargetData = &anInputDataDef;
+ aTargetIndex = toolBarMarkerIndexDef;
+ }
+ }
+
+ if(aTargetData && aTargetIndex >= 0) {
+ int index;
+ if(!isDockWinWriten ) {
+ //Write version marker
+ int marker, version;
+ aTargetData->device()->seek(0);
+ *aTargetData >> marker;
+ *aTargetData >> version;
+ aData << marker;
+ aData << version;
+ aData << (uchar) QDockWidgetMarker;
+ aData << (int) 0;
+ int shift = 4*sizeof(int) + sizeof(QSize);
+ index = aTargetIndex - shift;
+ } else {
+ index = aTargetIndex;
+ }
+
+ aTargetData->device()->seek(index);
+ while(!aTargetData->atEnd()) {
+ uchar ch;
+ *aTargetData >> ch;
+ aData << ch;
+ }
+ } else { // Not treat toolbars
+ aData << (uchar) QToolBarMarker;
+ aData << (int) 0; //Nb toolbars = 0
+ }
+ }
+ return aRes;
+}
+
+/*!
+ \brief Emits operationFinished signal.
+ \param theModuleName the name of the module which perfomed the operation
+ \param theOperationName the operation name
+ \param theEntryList the list of the created objects entries
+*/
+void LightApp_Application::emitOperationFinished( const QString& theModuleName,
+ const QString& theOperationName,
+ const QStringList& theEntryList )
+{
+ emit operationFinished( theModuleName, theOperationName, theEntryList );
+}