Back to index

salome-geom  6.5.0
GEOMToolsGUI_DeleteDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // GEOM GEOMGUI : GUI for Geometry component
00021 // File   : GEOMToolsGUI_DeleteDlg.cxx
00022 // Author : Dmitry Matveitchev, Open CASCADE S.A.S.
00023 //
00024 #include "GEOMToolsGUI_DeleteDlg.h"
00025 
00026 #include <QLabel>
00027 #include <QDialogButtonBox>
00028 #include <QTextBrowser>
00029 #include <QStringList>
00030 #include <QGridLayout>
00031 #include <SUIT_MessageBox.h>
00032  
00033 static bool isEntryLess( const QString& e1, const QString& e2 )
00034 {
00035   QStringList el1 = e1.split(":");
00036   QStringList el2 = e2.split(":");
00037   int e1c = el1.count(), e2c = el2.count();
00038   for ( int i = 0; i < e1c && i < e2c; i++ ) {
00039     int id1 = el1[i].toInt();
00040     int id2 = el2[i].toInt();
00041     if ( id1 < id2 ) return true;
00042     else if ( id2 < id1 ) return false;
00043   }
00044   return el1.count() < el2.count();
00045 }
00046 
00047 static QStringList objectsToNames( const QMap<QString, QString>& objects )
00048 {
00049   QStringList entries;
00050   for ( QMap<QString, QString>::ConstIterator it = objects.begin(); it != objects.end(); ++it ) {
00051     QString entry = it.key();
00052     QStringList::Iterator iter;
00053     bool added = false;
00054     for ( iter = entries.begin(); iter != entries.end() && !added; ++iter ) {
00055       if ( isEntryLess( entry, *iter ) ) {
00056         entries.insert( iter, entry );
00057         added = true;
00058       }
00059     }
00060     if ( !added ) 
00061       entries.append( entry );
00062   }
00063   QStringList names;
00064   for ( int i = 0; i < entries.count(); i++ ) {
00065     int level = entries[i].count(":")-3;
00066     names.append( QString( level*2, ' ' ) + objects[ entries[i] ] );
00067   }
00068   return names;
00069 }
00070 
00077 GEOMToolsGUI_DeleteDlg::GEOMToolsGUI_DeleteDlg( QWidget* parent, 
00078                                                 const QMap<QString, QString>& objects, 
00079                                                 bool deleteAll )
00080 : QDialog( parent )
00081 {
00082   setModal( true );
00083   setObjectName( "GEOMToolsGUI_DeleteDlg" );
00084 
00085   setWindowTitle( tr( "GEOM_DELETE_OBJECTS" ) );
00086   setSizeGripEnabled( true );
00087 
00088   QGridLayout* topLayout = new QGridLayout( this );
00089 
00090   topLayout->setSpacing( 6 );
00091   topLayout->setMargin( 11 );
00092 
00093   QLabel* pix = new QLabel( this );
00094   pix->setPixmap( SUIT_MessageBox::standardIcon( QMessageBox::Question ) );
00095   pix->setScaledContents( false );
00096   pix->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
00097   topLayout->addWidget( pix, 0, 0, 1, 1 );
00098 
00099   QLabel* lab = new QLabel( this );
00100   lab->setAlignment( Qt::AlignCenter );
00101   topLayout->addWidget( lab, 0, 1, 1, 1 );
00102 
00103   if ( !deleteAll ) {
00104     lab->setText( tr( "GEOM_REALLY_DELETE" ).arg( objects.count() ) );
00105     QTextBrowser* viewer = new QTextBrowser( this );
00106     viewer->setText( QString( " - %1" ).arg( objectsToNames( objects ).join( "\n - " ) ) );
00107     topLayout->addWidget( viewer,    1, 0, 1, 2 );
00108   }
00109   else {
00110     lab->setText( tr( "GEOM_REALLY_DELETE_ALL" ) );
00111   }
00112 
00113   QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Yes
00114                                  | QDialogButtonBox::No);
00115   int rc = topLayout->rowCount();
00116   topLayout->addWidget( buttonBox, rc, 1, 1, 1 );
00117 
00118   connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
00119   connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
00120 }
00121 
00122 GEOMToolsGUI_DeleteDlg::~GEOMToolsGUI_DeleteDlg()
00123 {
00124 }