Salome HOME
0016756: EDF 545 GEOM : Extrusion, give the coordinates of the vector as input
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_DeleteDlg.cxx
index 20fd8d847dc2862d41f046f432cb3f7009d80c09..4cde20102489d1d677a33887248156293a42fc43 100644 (file)
 #include <QTextBrowser>
 #include <QStringList>
 #include <QGridLayout>
+#include <SUIT_MessageBox.h>
+static bool isEntryLess( const QString& e1, const QString& e2 )
+{
+  QStringList el1 = e1.split(":");
+  QStringList el2 = e2.split(":");
+  int e1c = el1.count(), e2c = el2.count();
+  for ( int i = 0; i < e1c && i < e2c; i++ ) {
+    int id1 = el1[i].toInt();
+    int id2 = el2[i].toInt();
+    if ( id1 < id2 ) return true;
+    else if ( id2 < id1 ) return false;
+  }
+  return el1.count() < el2.count();
+}
+
+static QStringList objectsToNames( const QMap<QString, QString>& objects )
+{
+  QStringList entries;
+  for ( QMap<QString, QString>::ConstIterator it = objects.begin(); it != objects.end(); ++it ) {
+    QString entry = it.key();
+    QStringList::Iterator it;
+    bool added = false;
+    for ( it = entries.begin(); it != entries.end() && !added; ++it ) {
+      if ( isEntryLess( entry, *it ) ) {
+       entries.insert( it, entry );
+       added = true;
+      }
+    }
+    if ( !added ) 
+      entries.append( entry );
+  }
+  QStringList names;
+  for ( int i = 0; i < entries.count(); i++ ) {
+    int level = entries[i].count(":")-3;
+    names.append( QString( level*2, ' ' ) + objects[ entries[i] ] );
+  }
+  return names;
+}
 
 /*!
   \brief Constructor.
   \param parent parent widget
 */
-GEOMToolsGUI_DeleteDlg::GEOMToolsGUI_DeleteDlg( QWidget* parent, const QStringList& objects )
+GEOMToolsGUI_DeleteDlg::GEOMToolsGUI_DeleteDlg( QWidget* parent, 
+                                               const QMap<QString, QString>& objects, 
+                                               bool deleteAll )
 : QDialog( parent )
 {
   setModal( true );
@@ -49,18 +90,37 @@ GEOMToolsGUI_DeleteDlg::GEOMToolsGUI_DeleteDlg( QWidget* parent, const QStringLi
   topLayout->setSpacing( 6 );
   topLayout->setMargin( 11 );
 
-  QLabel* lab = new QLabel( tr( "GEOM_REALLY_DELETE" ).arg( objects.count() ), this );
+  QLabel* pix = new QLabel( this );
+  pix->setPixmap( SUIT_MessageBox::standardIcon( QMessageBox::Question ) );
+  pix->setScaledContents( false );
+  pix->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
+  topLayout->addWidget( pix, 0, 0, 1, 1 );
 
-  QTextBrowser* viewer = new QTextBrowser( this );
-  viewer->setText( QString( "-%1" ).arg( objects.join( "<br> -" ) ) );
+  QLabel* lab = new QLabel( this );
+  lab->setAlignment( Qt::AlignCenter );
+  topLayout->addWidget( lab, 0, 1, 1, 1 );
+
+  if ( !deleteAll ) {
+    lab->setText( tr( "GEOM_REALLY_DELETE" ).arg( objects.count() ) );
+    QTextBrowser* viewer = new QTextBrowser( this );
+    viewer->setText( QString( " - %1" ).arg( objectsToNames( objects ).join( "\n - " ) ) );
+    topLayout->addWidget( viewer,    1, 0, 1, 2 );
+  }
+  else {
+    lab->setText( tr( "GEOM_REALLY_DELETE_ALL" ) );
+  }
 
   QPushButton* buttonYes = new QPushButton( tr( "GEOM_BUT_YES" ), this );
   QPushButton* buttonNo  = new QPushButton( tr( "GEOM_BUT_NO" ),  this );
-
-  topLayout->addWidget( lab,       0, 0, 1, 3 );
-  topLayout->addWidget( viewer,    1, 0, 1, 3 );
-  topLayout->addWidget( buttonYes, 2, 0 );
-  topLayout->addWidget( buttonNo,  2, 2 );
+  QHBoxLayout* btnLayout = new QHBoxLayout;
+  btnLayout->setMargin( 0 );
+  btnLayout->setSpacing( 6 );
+  btnLayout->addWidget( buttonYes );
+  btnLayout->addSpacing( 10 );
+  btnLayout->addStretch();
+  btnLayout->addWidget( buttonNo );
+  int rc = topLayout->rowCount();
+  topLayout->addLayout( btnLayout, rc, 0, 1, 2 );
 
   /* signals and slots connections */
   connect( buttonYes, SIGNAL( clicked() ), this, SLOT( accept() ) );
@@ -70,6 +130,3 @@ GEOMToolsGUI_DeleteDlg::GEOMToolsGUI_DeleteDlg( QWidget* parent, const QStringLi
 GEOMToolsGUI_DeleteDlg::~GEOMToolsGUI_DeleteDlg()
 {
 }
-
-
-