1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GEOMToolsGUI_DeleteDlg.cxx
23 // Author : Dmitry Matveitchev, Open CASCADE S.A.S.
26 #include "GEOMToolsGUI_DeleteDlg.h"
29 #include <qpushbutton.h>
30 #include <qtextbrowser.h>
31 #include <qstringlist.h>
33 #include <qmessagebox.h>
34 #include <SUIT_MessageBox.h>
36 static bool isEntryLess( const QString& e1, const QString& e2 )
38 QStringList el1 = QStringList::split(":", e1);
39 QStringList el2 = QStringList::split(":", e2);
40 int e1c = el1.count(), e2c = el2.count();
41 for ( int i = 0; i < e1c && i < e2c; i++ ) {
42 int id1 = el1[i].toInt();
43 int id2 = el2[i].toInt();
44 if ( id1 < id2 ) return true;
45 else if ( id2 < id1 ) return false;
47 return el1.count() < el2.count();
50 static QStringList objectsToNames( const QMap<QString, QString>& objects )
53 for ( QMap<QString, QString>::ConstIterator it = objects.begin(); it != objects.end(); ++it ) {
54 QString entry = it.key();
55 QStringList::Iterator it;
57 for ( it = entries.begin(); it != entries.end() && !added; ++it ) {
58 if ( isEntryLess( entry, *it ) ) {
59 entries.insert( it, entry );
64 entries.append( entry );
67 for ( int i = 0; i < entries.count(); i++ ) {
68 int level = entries[i].contains(":")-3;
69 QString prefix; prefix.fill( ' ', level*2 );
70 names.append( prefix + objects[ entries[i] ] );
77 \param parent parent widget
79 GEOMToolsGUI_DeleteDlg::GEOMToolsGUI_DeleteDlg( QWidget* parent,
80 const QMap<QString, QString>& objects,
82 : QDialog( parent, "GEOMToolsGUI_DeleteDlg", true )
84 setCaption( tr( "GEOM_DELETE_OBJECTS" ) );
85 setSizeGripEnabled( true );
87 QGridLayout* topLayout = new QGridLayout( this );
89 topLayout->setSpacing( 6 );
90 topLayout->setMargin( 11 );
92 QLabel* pix = new QLabel( this );
93 pix->setPixmap( QMessageBox::standardIcon( QMessageBox::Question ) );
94 pix->setScaledContents( false );
95 pix->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
96 topLayout->addWidget( pix, 0, 0 );
98 QLabel* lab = new QLabel( this );
99 lab->setAlignment( Qt::AlignCenter );
100 topLayout->addWidget( lab, 0, 1 );
103 lab->setText( tr( "GEOM_REALLY_DELETE" ).arg( objects.count() ) );
104 QTextBrowser* viewer = new QTextBrowser( this );
105 viewer->setText( QString( " - %1" ).arg( objectsToNames( objects ).join( "\n - " ) ) );
106 topLayout->addMultiCellWidget( viewer, 1, 1, 0, 1 );
109 lab->setText( tr( "GEOM_REALLY_DELETE_ALL" ) );
112 QPushButton* buttonYes = new QPushButton( tr( "GEOM_BUT_YES" ), this );
113 QPushButton* buttonNo = new QPushButton( tr( "GEOM_BUT_NO" ), this );
114 QHBoxLayout* btnLayout = new QHBoxLayout;
115 btnLayout->setMargin( 0 );
116 btnLayout->setSpacing( 6 );
117 btnLayout->addWidget( buttonYes );
118 btnLayout->addSpacing( 10 );
119 btnLayout->addStretch();
120 btnLayout->addWidget( buttonNo );
121 int rc = topLayout->numRows();
122 topLayout->addMultiCellLayout( btnLayout, rc, rc, 0, 1 );
124 /* signals and slots connections */
125 connect( buttonYes, SIGNAL( clicked() ), this, SLOT( accept() ) );
126 connect( buttonNo, SIGNAL( clicked() ), this, SLOT( reject() ) );
129 GEOMToolsGUI_DeleteDlg::~GEOMToolsGUI_DeleteDlg()