From d19ad9c812f71cbb38c425e9d736f213d83a5b23 Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 14 Nov 2005 11:43:48 +0000 Subject: [PATCH] Fix a bug: an exception is raised when attempting to display root object --- src/LIGHTGUI/LIGHTGUI.cxx | 2 +- src/LIGHTGUI/LIGHTGUI_DataModel.cxx | 17 +++++++++++++---- src/LIGHTGUI/LIGHT_msg_en.po | 5 ++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/LIGHTGUI/LIGHTGUI.cxx b/src/LIGHTGUI/LIGHTGUI.cxx index 05aa062..548b847 100644 --- a/src/LIGHTGUI/LIGHTGUI.cxx +++ b/src/LIGHTGUI/LIGHTGUI.cxx @@ -278,7 +278,7 @@ void LIGHTGUI::onDisplayLine() double aX = 0, aY = 0, aZ = 0; QString aStrId = QString("LIGHTGUI_%1").arg(aPosition); - Handle(LIGHTGUI_TextPrs) aPrs = new LIGHTGUI_TextPrs( aLine, gp_Pnt( aX, aY, aZ ) ); + Handle(LIGHTGUI_TextPrs) aPrs = new LIGHTGUI_TextPrs( aLine.isNull() ? "" : aLine, gp_Pnt( aX, aY, aZ ) ); aPrs->SetOwner(new SALOME_InteractiveObject( aStrId, "" ) ); SOCC_Prs* prs = dynamic_cast( aViewer->CreatePrs() ); // aStringID is an "entry" if ( prs ) { diff --git a/src/LIGHTGUI/LIGHTGUI_DataModel.cxx b/src/LIGHTGUI/LIGHTGUI_DataModel.cxx index 2461565..5d7befe 100644 --- a/src/LIGHTGUI/LIGHTGUI_DataModel.cxx +++ b/src/LIGHTGUI/LIGHTGUI_DataModel.cxx @@ -309,9 +309,10 @@ bool LIGHTGUI_DataModel::insertLineBefore ( const int thePosition, const QString // Insert new line before the item at thePosition in the list, // or at the end() if thePosition is out of range LIGHTGUI_ModuleObject* modelRoot = dynamic_cast( root() ); - if ( !modelRoot ) - return false; + LightApp_Study* study = dynamic_cast( module()->application()->activeStudy() ); if ( thePosition > 0 ) { + if ( !modelRoot ) + return false; LIGHTGUI_DataObject* obj = findObject( thePosition ); if ( !obj || !obj->parent() ) return false; @@ -345,8 +346,16 @@ bool LIGHTGUI_DataModel::insertLineBefore ( const int thePosition, const QString } else { // append new paragraph/line - theText.stripWhiteSpace().isEmpty() ? new LIGHTGUI_DataObject( theText, modelRoot ) : - new LIGHTGUI_DataObject( theText, modelRoot->lastChild() ); + if ( modelRoot ) + theText.stripWhiteSpace().isEmpty() ? new LIGHTGUI_DataObject( theText, modelRoot ) : + new LIGHTGUI_DataObject( theText, modelRoot->lastChild() ); + else { + QStringList lines; + if ( !theText.stripWhiteSpace().isEmpty() ) + lines.append( theText ); + buildTree( study->root(), lines ); + } + } return true; } diff --git a/src/LIGHTGUI/LIGHT_msg_en.po b/src/LIGHTGUI/LIGHT_msg_en.po index 3ea89c2..88ce42d 100644 --- a/src/LIGHTGUI/LIGHT_msg_en.po +++ b/src/LIGHTGUI/LIGHT_msg_en.po @@ -149,6 +149,9 @@ msgstr "Wrong selection!" msgid "WRN_EDIT_FAILED" msgstr "Can't edit line!" +msgid "WRN_ADD_FAILED" +msgstr "Can't insert line!" + msgid "WRN_UNKNOWN_COMMAND" msgstr "Unrecognized command!" @@ -162,4 +165,4 @@ msgid "LIGHT_LINE" msgstr "Line" msgid "LIGHT_ROOT_TOOLTIP" -msgstr "LIGHT module root object" \ No newline at end of file +msgstr "LIGHT module root object" -- 2.39.2