1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 <QDialogButtonBox>
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
74 \param objects map of objects names/objects
75 \param deleteAll if True, delete all objects
77 GEOMToolsGUI_DeleteDlg::GEOMToolsGUI_DeleteDlg( QWidget* parent,
78 const QMap<QString, QString>& objects,
83 setObjectName( "GEOMToolsGUI_DeleteDlg" );
85 setWindowTitle( tr( "GEOM_DELETE_OBJECTS" ) );
86 setSizeGripEnabled( true );
88 QGridLayout* topLayout = new QGridLayout( this );
90 topLayout->setSpacing( 6 );
91 topLayout->setMargin( 11 );
93 QLabel* pix = new QLabel( this );
94 pix->setPixmap( SUIT_MessageBox::standardIcon( QMessageBox::Question ) );
95 pix->setScaledContents( false );
96 pix->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
97 topLayout->addWidget( pix, 0, 0, 1, 1 );
99 QLabel* lab = new QLabel( this );
100 lab->setAlignment( Qt::AlignCenter );
101 topLayout->addWidget( lab, 0, 1, 1, 1 );
104 lab->setText( tr( "GEOM_REALLY_DELETE" ).arg( objects.count() ) );
105 QTextBrowser* viewer = new QTextBrowser( this );
106 viewer->setText( QString( " - %1" ).arg( objectsToNames( objects ).join( "\n - " ) ) );
107 topLayout->addWidget( viewer, 1, 0, 1, 2 );
110 lab->setText( tr( "GEOM_REALLY_DELETE_ALL" ) );
113 QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Yes
114 | QDialogButtonBox::No);
115 int rc = topLayout->rowCount();
116 topLayout->addWidget( buttonBox, rc, 1, 1, 1 );
118 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
119 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
122 GEOMToolsGUI_DeleteDlg::~GEOMToolsGUI_DeleteDlg()