1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File : GEOMToolsGUI_DeleteDlg.cxx
22 // Author : Dmitry Matveitchev, Open CASCADE S.A.S.
24 #include "GEOMToolsGUI_DeleteDlg.h"
27 #include <QPushButton>
28 #include <QTextBrowser>
29 #include <QStringList>
30 #include <QGridLayout>
31 #include <SUIT_MessageBox.h>
33 static bool isEntryLess( const QString& e1, const QString& e2 )
35 QStringList el1 = e1.split(":");
36 QStringList el2 = e2.split(":");
37 int e1c = el1.count(), e2c = el2.count();
38 for ( int i = 0; i < e1c && i < e2c; i++ ) {
39 int id1 = el1[i].toInt();
40 int id2 = el2[i].toInt();
41 if ( id1 < id2 ) return true;
42 else if ( id2 < id1 ) return false;
44 return el1.count() < el2.count();
47 static QStringList objectsToNames( const QMap<QString, QString>& objects )
50 for ( QMap<QString, QString>::ConstIterator it = objects.begin(); it != objects.end(); ++it ) {
51 QString entry = it.key();
52 QStringList::Iterator iter;
54 for ( iter = entries.begin(); iter != entries.end() && !added; ++iter ) {
55 if ( isEntryLess( entry, *iter ) ) {
56 entries.insert( iter, entry );
61 entries.append( entry );
64 for ( int i = 0; i < entries.count(); i++ ) {
65 int level = entries[i].count(":")-3;
66 names.append( QString( level*2, ' ' ) + objects[ entries[i] ] );
73 \param parent parent widget
75 GEOMToolsGUI_DeleteDlg::GEOMToolsGUI_DeleteDlg( QWidget* parent,
76 const QMap<QString, QString>& objects,
81 setObjectName( "GEOMToolsGUI_DeleteDlg" );
83 setWindowTitle( tr( "GEOM_DELETE_OBJECTS" ) );
84 setSizeGripEnabled( true );
86 QGridLayout* topLayout = new QGridLayout( this );
88 topLayout->setSpacing( 6 );
89 topLayout->setMargin( 11 );
91 QLabel* pix = new QLabel( this );
92 pix->setPixmap( SUIT_MessageBox::standardIcon( QMessageBox::Question ) );
93 pix->setScaledContents( false );
94 pix->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
95 topLayout->addWidget( pix, 0, 0, 1, 1 );
97 QLabel* lab = new QLabel( this );
98 lab->setAlignment( Qt::AlignCenter );
99 topLayout->addWidget( lab, 0, 1, 1, 1 );
102 lab->setText( tr( "GEOM_REALLY_DELETE" ).arg( objects.count() ) );
103 QTextBrowser* viewer = new QTextBrowser( this );
104 viewer->setText( QString( " - %1" ).arg( objectsToNames( objects ).join( "\n - " ) ) );
105 topLayout->addWidget( viewer, 1, 0, 1, 2 );
108 lab->setText( tr( "GEOM_REALLY_DELETE_ALL" ) );
111 QPushButton* buttonYes = new QPushButton( tr( "GEOM_BUT_YES" ), this );
112 QPushButton* buttonNo = new QPushButton( tr( "GEOM_BUT_NO" ), this );
113 QHBoxLayout* btnLayout = new QHBoxLayout;
114 btnLayout->setMargin( 0 );
115 btnLayout->setSpacing( 6 );
116 btnLayout->addWidget( buttonYes );
117 btnLayout->addSpacing( 10 );
118 btnLayout->addStretch();
119 btnLayout->addWidget( buttonNo );
120 int rc = topLayout->rowCount();
121 topLayout->addLayout( btnLayout, rc, 0, 1, 2 );
123 /* signals and slots connections */
124 connect( buttonYes, SIGNAL( clicked() ), this, SLOT( accept() ) );
125 connect( buttonNo, SIGNAL( clicked() ), this, SLOT( reject() ) );
128 GEOMToolsGUI_DeleteDlg::~GEOMToolsGUI_DeleteDlg()