Salome HOME
IPAL20954 problem loading help pages
[modules/visu.git] / src / VISUGUI / VisuGUI_EditContainerDlg.cxx
index b79e65d9f103e4a0c9061a482afd953f4951f2ad..abbdc0bf277f0b761829e949f3058fb8806880c5 100644 (file)
@@ -1,27 +1,28 @@
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //  File   : VisuGUI_EditContainerDlg.cxx
 //  Author : VSV
 //  Module : VISU
-
-
+//
 #include "VisuGUI_EditContainerDlg.h"
 
 #include "VisuGUI.h"
 #include "SUIT_MessageBox.h"
 #include "SUIT_ResourceMgr.h"
 
-#include <qlayout.h>
-#include <qcheckbox.h>
-#include <qgroupbox.h>
-#include <qpushbutton.h>
-#include <qlabel.h>
+#include <QLayout>
+#include <QCheckBox>
+#include <QGroupBox>
+#include <QPushButton>
+#include <QLabel>
+#include <QTreeWidget>
+#include <QToolButton>
+#include <QKeyEvent>
+
 
 using namespace std;
 
@@ -210,17 +215,19 @@ static QPixmap MYRightPix(right_xpm);
 
 
 VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (VisuGUI* theModule, bool theIsModal)
-     : QDialog(VISU::GetDesktop(theModule), "VisuGUI_EditContainerDlg", theIsModal,
-               WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+     : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
        myVisuGUI(theModule)
 {
+  setModal( theIsModal );
   if (!theIsModal) {
-    setWFlags(getWFlags() | WDestructiveClose);
+    setAttribute( Qt::WA_DeleteOnClose, true );
   }
-  setCaption("Edit Plot 2D Presentation");
+  setWindowTitle("Edit Plot 2D Presentation");
   setSizeGripEnabled(true);
 
-  QVBoxLayout* TopLayout = new QVBoxLayout (this, 6, 11);
+  QVBoxLayout* TopLayout = new QVBoxLayout (this );
+  TopLayout->setMargin( 6 );
+  TopLayout->setSpacing( 11);
 
   /***************************************************************/
   QFrame* aControlFrame = new QFrame (this);
@@ -229,34 +236,45 @@ VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (VisuGUI* theModule, bool the
   QGridLayout* aControlLay = new QGridLayout (aControlFrame);
   aControlLay->setSpacing(6);
   aControlLay->setMargin(11);
-  aControlLay->addRowSpacing(1, 30);
-  aControlLay->addRowSpacing(4, 30);
+  //aControlLay->addRowSpacing(1, 30);
+  //aControlLay->addRowSpacing(4, 30);
   aControlLay->setRowStretch(1, 1);
   aControlLay->setRowStretch(4, 1);
-  aControlLay->addColSpacing(0, 180);
-  aControlLay->addColSpacing(2, 180);
+  //aControlLay->addColSpacing(0, 180);
+  //aControlLay->addColSpacing(2, 180);
 
   QLabel* aSelectLbl = new QLabel (tr("LBL_STUDY"), aControlFrame);
   aControlLay->addWidget(aSelectLbl, 0, 0);
 
-  myStudyLst = new QListView (aControlFrame);
-  myStudyLst->setSelectionMode(QListView::Extended);
-  myStudyLst->addColumn(tr("TXT_TABLE"), 80);
-  myStudyLst->addColumn(tr("TXT_CURVE"), 50);
-  myStudyLst->addColumn(tr(""), 0);
+  myStudyLst = new QTreeWidget (aControlFrame);
+  myStudyLst->setSelectionMode(QAbstractItemView::ExtendedSelection);
+  myStudyLst->setColumnCount( 3 );
+  QStringList aLabels;
+  aLabels.append( tr("TXT_TABLE") );
+  aLabels.append( tr("TXT_CURVE") );
+  aLabels.append( "" );
+  myStudyLst->setHeaderLabels( aLabels );
+  myStudyLst->setColumnWidth( 0, 80 );
+  myStudyLst->setColumnWidth( 1, 50 );
+  myStudyLst->setColumnWidth( 2, 0 );
+  
+  //myStudyLst->addColumn(tr("TXT_TABLE"), 80);
+  //myStudyLst->addColumn(tr("TXT_CURVE"), 50);
+  //myStudyLst->addColumn(tr(""), 0);
+  
   myStudyLst->setAllColumnsShowFocus(true);
-  myStudyLst->setMinimumHeight(130);
-  connect(myStudyLst, SIGNAL(selectionChanged()), this, SLOT(onLeftSelected()));
-  aControlLay->addMultiCellWidget(myStudyLst, 1, 4, 0, 0);
+  //myStudyLst->setMinimumHeight(130);
+  connect(myStudyLst, SIGNAL(itemSelectionChanged()), this, SLOT(onLeftSelected()));
+  aControlLay->addWidget(myStudyLst, 1, 0, 5, 1);
 
   myRightBtn = new QToolButton (aControlFrame);
-  myRightBtn->setIconSet(MYRightPix);
+  myRightBtn->setIcon(MYRightPix);
   myRightBtn->setEnabled(false);
   connect(myRightBtn, SIGNAL(clicked()), this, SLOT(onRightClicked()));
   aControlLay->addWidget(myRightBtn, 2, 1);
 
   myLeftBtn = new QToolButton(aControlFrame);
-  myLeftBtn->setIconSet(MYLeftPix);
+  myLeftBtn->setIcon(MYLeftPix);
   myLeftBtn->setEnabled(false);
   connect(myLeftBtn, SIGNAL(clicked()), this, SLOT(onLeftClicked()));
   aControlLay->addWidget(myLeftBtn, 3, 1);
@@ -264,39 +282,46 @@ VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (VisuGUI* theModule, bool the
   QLabel* aForceLbl = new QLabel (tr("LBL_CONTAINER"), aControlFrame);
   aControlLay->addWidget(aForceLbl, 0, 2);
 
-  myContainerLst = new QListView(aControlFrame);
-  myContainerLst->setSelectionMode(QListView::Extended);
-  myContainerLst->addColumn(tr("TXT_TABLE"), 80);
-  myContainerLst->addColumn(tr("TXT_CURVE"), 50);
-  myContainerLst->addColumn(tr(""), 0);
-  myContainerLst->setMinimumWidth(130);
-  connect(myContainerLst, SIGNAL(selectionChanged()), this, SLOT(onRightSelected()));
-  aControlLay->addMultiCellWidget(myContainerLst, 1, 4, 2, 2);
+  myContainerLst = new QTreeWidget(aControlFrame);
+  myContainerLst->setSelectionMode(QAbstractItemView::ExtendedSelection);
+  //myContainerLst->addColumn(tr("TXT_TABLE"), 80);
+  //myContainerLst->addColumn(tr("TXT_CURVE"), 50);
+  //myContainerLst->addColumn(tr(""), 0);
+  myContainerLst->setColumnCount( 3 );
+  myContainerLst->setHeaderLabels( aLabels );
+  myContainerLst->setColumnWidth( 0, 80 );
+  myContainerLst->setColumnWidth( 1, 50 );
+  myContainerLst->setColumnWidth( 2, 0 );
+
+  
+  //myContainerLst->setMinimumWidth(130);
+  connect(myContainerLst, SIGNAL(itemSelectionChanged()), this, SLOT(onRightSelected()));
+  aControlLay->addWidget(myContainerLst, 1, 2, 5, 1);
 
   TopLayout->addWidget(aControlFrame);
 
   // Common buttons ===========================================================
-  QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
-  GroupButtons->setColumnLayout(0, Qt::Vertical);
-  GroupButtons->layout()->setSpacing(0);
-  GroupButtons->layout()->setMargin(0);
-  QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
+  QGroupBox* GroupButtons = new QGroupBox(this);
+  //GroupButtons->setColumnLayout(0, Qt::Vertical);
+  //GroupButtons->layout()->setSpacing(0);
+  //GroupButtons->layout()->setMargin(0);
+  QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
   GroupButtonsLayout->setAlignment(Qt::AlignTop);
   GroupButtonsLayout->setSpacing(6);
   GroupButtonsLayout->setMargin(11);
 
-  QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
+  QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons);
   buttonOk->setAutoDefault(TRUE);
   buttonOk->setDefault(TRUE);
   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
   GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding,
                                               QSizePolicy::Minimum), 0, 1);
 
-  QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel");
+  QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons);
   buttonCancel->setAutoDefault(TRUE);
   GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
 
-  QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons, "buttonHelp");
+  QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons);
   buttonHelp->setAutoDefault(TRUE);
   GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
 
@@ -314,20 +339,24 @@ void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContaine
   if (!aVisuSO) {
     return;
   }
-  QValueList<CurveStruct> aStudyCurves;
-  QValueList<CurveStruct> aContainerCurves;
+  QList<CurveStruct> aStudyCurves;
+  QList<CurveStruct> aContainerCurves;
   // Find curves in container
   for (int i = 1; i <= theContainer->GetNbCurves(); i++) {
     VISU::Curve_i* aCurve = theContainer->GetCurve(i);
     if (aCurve == NULL) continue;
     CurveStruct aEntry;
     aEntry.CurveName = aCurve->GetTitle();
-    aEntry.CurveEntry = aCurve->GetEntry();
+    aEntry.CurveEntry = aCurve->GetEntry().c_str();
     _PTR(SObject) aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
     if (!aTableSO) continue;
     aEntry.TableName = getSObjectName(aTableSO);
     aContainerCurves.append(aEntry);
-    new QListViewItem(myContainerLst, aEntry.TableName, aEntry.CurveName, aEntry.CurveEntry);
+    QStringList aList;
+    aList.append( aEntry.TableName );
+    aList.append( aEntry.CurveName );
+    aList.append( aEntry.CurveEntry );
+    new QTreeWidgetItem(myContainerLst, aList);
   }
   // Find curves in study
   _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aVisuSO);
@@ -347,8 +376,8 @@ void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContaine
     }
   }
   //Show Curves which are not in Curve
-  QValueList<CurveStruct>::iterator it;
-  QValueList<CurveStruct>::iterator it2;
+  QList<CurveStruct>::iterator it;
+  QList<CurveStruct>::iterator it2;
   bool isExist = false;
   for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it) {
     for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2) {
@@ -356,7 +385,13 @@ void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContaine
        break;
     }
     if (!isExist)
-      new QListViewItem(myStudyLst, (*it).TableName, (*it).CurveName, (*it).CurveEntry);
+    {
+      QStringList aList;
+      aList.append( (*it).TableName );
+      aList.append( (*it).CurveName );
+      aList.append( (*it).CurveEntry );
+      new QTreeWidgetItem(myStudyLst, aList );
+    }
   }
 }
 
@@ -365,9 +400,13 @@ void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer
   theContainer->Clear();
 
   _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
-  QListViewItem* anItem = myContainerLst->firstChild();
-  while (anItem) {
-    _PTR(SObject) aCurveSO = aStudy->FindObjectID(anItem->text(2).latin1());
+  QTreeWidgetItem* anItem;
+  for ( int i= 0; i< myContainerLst->topLevelItemCount(); i++  )
+  {
+    anItem = myContainerLst->topLevelItem( i );
+    if ( !anItem )
+      continue;
+    _PTR(SObject) aCurveSO = aStudy->FindObjectID((const char*)anItem->text(2).toLatin1());
     if (aCurveSO) {
       CORBA::Object_var aObject = VISU::ClientSObjectToObject(aCurveSO);
       if (!CORBA::is_nil(aObject)) {
@@ -375,7 +414,6 @@ void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer
        if (aCurve) theContainer->AddCurve(aCurve->_this());
       }
     }
-    anItem = anItem->nextSibling();
   }
 }
 
@@ -393,7 +431,7 @@ QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
 
 void VisuGUI_EditContainerDlg::onLeftClicked()
 {
-  QListViewItem* anItem = myContainerLst->firstChild();
+  /*QListViewItem* anItem = myContainerLst->firstChild();
   while (anItem) {
     if (anItem->isSelected()) {
       QListViewItem* anTmpItem = anItem;
@@ -403,12 +441,24 @@ void VisuGUI_EditContainerDlg::onLeftClicked()
     } else {
       anItem = anItem->nextSibling();
     }
+    }*/
+  QList<QTreeWidgetItem*> selItem = myContainerLst->selectedItems();
+  QList<QTreeWidgetItem*>::Iterator anIt = selItem.begin();
+
+  QList<QTreeWidgetItem*> topSelectedItems;
+  for ( ; anIt != selItem.end(); anIt++  )
+  {
+    int index = myContainerLst->indexOfTopLevelItem( *anIt );
+    if ( index != -1 )
+      topSelectedItems.append( myContainerLst->takeTopLevelItem( index ) );
   }
+
+  myStudyLst->addTopLevelItems(topSelectedItems);
 }
 
 void VisuGUI_EditContainerDlg::onRightClicked()
 {
-  QListViewItem* anItem = myStudyLst->firstChild();
+  /*QListViewItem* anItem = myStudyLst->firstChild();
   while (anItem) {
     if (anItem->isSelected()) {
       QListViewItem* anTmpItem = anItem;
@@ -418,47 +468,60 @@ void VisuGUI_EditContainerDlg::onRightClicked()
     } else {
       anItem = anItem->nextSibling();
     }
+    }*/
+  QList<QTreeWidgetItem*> selItem = myStudyLst->selectedItems();
+  QList<QTreeWidgetItem*>::Iterator anIt = selItem.begin();
+
+  QList<QTreeWidgetItem*> topSelectedItems;
+  for ( ; anIt != selItem.end(); anIt++  )
+  {
+    int index = myStudyLst->indexOfTopLevelItem( *anIt );
+    if ( index != -1 )
+      topSelectedItems.append( myStudyLst->takeTopLevelItem( index ) );
   }
+
+  myContainerLst->addTopLevelItems(topSelectedItems);
 }
 
 void VisuGUI_EditContainerDlg::onLeftSelected()
 {
-  QListViewItem* anItem = myStudyLst->firstChild();
-  bool isSelected = false;
-  while (anItem) {
-    if (anItem->isSelected()) {
-      isSelected = true;
-      break;
-    }
-    anItem = anItem->nextSibling();
-  }
-  myRightBtn->setEnabled(isSelected);
+  myRightBtn->setEnabled( myStudyLst->selectedItems().count() > 0 );
 }
 
 void VisuGUI_EditContainerDlg::onRightSelected()
 {
-  QListViewItem* anItem = myContainerLst->firstChild();
-  bool isSelected = false;
-  while (anItem) {
-    if (anItem->isSelected()) {
-      isSelected = true;
-      break;
-    }
-    anItem = anItem->nextSibling();
-  }
-  myLeftBtn->setEnabled(isSelected);
+  myLeftBtn->setEnabled( myContainerLst->selectedItems().count() > 0 );
 }
 
 void VisuGUI_EditContainerDlg::onHelp()
 {
-  QString aHelpFileName = "/files/creating_xy_plot.htm";
+  QString aHelpFileName = "creating_xy_plot_page.html";
   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
   if (app)
     app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
   else {
-    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
-                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
-                          arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
-                          QObject::tr("BUT_OK"));
+    QString platform;
+#ifdef WIN32
+    platform = "winapplication";
+#else
+    platform = "application";
+#endif
+    SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
+                             QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                             arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
+                             QObject::tr("BUT_OK"));
   }
 }
+
+void VisuGUI_EditContainerDlg::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Qt::Key_F1 )
+    {
+      e->accept();
+      onHelp();
+    }
+}