1 // Copyright (C) 2007-2020 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>
39 bool operator () (const std::string& s1, const std::string& s2) const
41 // hope the entries are never empty and never equal
43 const char* p1 = s1.c_str();
44 const char* p2 = s2.c_str();
45 for ( ; ; ++p1, ++p2 )
49 if ( diff21 && !*p1 ) // both numbers ends
54 bool d1 = isdigit( *p1 );
55 bool d2 = isdigit( *p2 );
56 if ( d1 != d2 ) // one number is shorter then another
57 return d2; // is s1 shorter?
58 if ( !d1 && diff21 ) // both numbers ends
60 if ( !diff21 ) // remember the first difference
68 static QStringList objectsToNames( const QMap<QString, QString>& objects )
70 typedef std::map< std::string, QString, NaturalCompare > TSortMap;
71 TSortMap sortedByEntry;
72 for ( QMap<QString, QString>::ConstIterator it = objects.begin(); it != objects.end(); ++it )
73 sortedByEntry.insert( sortedByEntry.end(), std::make_pair( it.key().toStdString(), it.value() ));
76 for ( TSortMap::iterator it = sortedByEntry.begin(); it != sortedByEntry.end(); ++it )
78 const std::string& entry = it->first;
79 int level = std::count( entry.begin(), entry.end(), ':' ) - 3;
80 names.append( QString( level * 2, ' ' ) + it->second );
87 \param parent parent widget
88 \param objects map of objects names/objects
89 \param deleteAll if True, delete all objects
91 GEOMToolsGUI_DeleteDlg::GEOMToolsGUI_DeleteDlg( QWidget* parent,
92 const QMap<QString, QString>& objects,
97 setObjectName( "GEOMToolsGUI_DeleteDlg" );
99 setWindowTitle( tr( "GEOM_DELETE_OBJECTS" ) );
100 setSizeGripEnabled( true );
102 QGridLayout* topLayout = new QGridLayout( this );
104 topLayout->setSpacing( 6 );
105 topLayout->setMargin( 11 );
107 QLabel* pix = new QLabel( this );
108 pix->setPixmap( SUIT_MessageBox::standardIcon( QMessageBox::Question ) );
109 pix->setScaledContents( false );
110 pix->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
111 topLayout->addWidget( pix, 0, 0, 1, 1 );
113 QLabel* lab = new QLabel( this );
114 lab->setAlignment( Qt::AlignCenter );
115 topLayout->addWidget( lab, 0, 1, 1, 1 );
118 lab->setText( tr( "GEOM_REALLY_DELETE" ).arg( objects.count() ) );
119 QTextBrowser* viewer = new QTextBrowser( this );
120 viewer->setText( QString( " - %1" ).arg( objectsToNames( objects ).join( "\n - " ) ) );
121 topLayout->addWidget( viewer, 1, 0, 1, 2 );
124 lab->setText( tr( "GEOM_REALLY_DELETE_ALL" ) );
127 QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Yes
128 | QDialogButtonBox::No);
129 int rc = topLayout->rowCount();
130 topLayout->addWidget( buttonBox, rc, 1, 1, 1 );
132 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
133 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
136 GEOMToolsGUI_DeleteDlg::~GEOMToolsGUI_DeleteDlg()