Salome HOME
5505932bcd0a40610ebbe7f0266a2ccfc6a3b10f
[samples/atomic.git] / src / ATOMICGUI / ATOMICGUI_RenameOp.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ATOMICGUI_RenameOp.h"
21 #include "ATOMICGUI_DataModel.h"
22 #include "ATOMICGUI_DataObject.h"
23 #include "ATOMICGUI.h"
24
25 #include <LightApp_Application.h>
26 #include <SUIT_Desktop.h>
27
28 #include <qinputdialog.h>
29
30 /*! Constructor */
31 ATOMICGUI_RenameOp::ATOMICGUI_RenameOp()
32 : ATOMICGUI_Operation()
33 {
34 }
35
36 /*! Destructor */
37 ATOMICGUI_RenameOp::~ATOMICGUI_RenameOp()
38 {
39 }
40
41 /*! Operation itself. Renames the selected object. */
42 void ATOMICGUI_RenameOp::startOperation()
43 {
44   ATOMICGUI_DataModel* dm = dataModel();
45   QStringList entries;
46   atomModule()->selected( entries, false );
47
48   if( entries.isEmpty() || !dm )
49   {
50     abort();
51     return;
52   }
53
54   ATOMICGUI_DataObject* obj = dm->findObject( entries.first() );
55   if ( obj && ( obj->isMolecule() || obj->isAtom() ) )
56   {
57     bool bOk;
58     QString name = QInputDialog::getText( module()->getApp()->desktop(),
59                                           tr( "ATOMICGUI_RENAME_OBJECT" ),
60                                           tr( "ATOMICGUI_NEW_NAME"),
61                                           QLineEdit::Normal,
62                                           obj->name(),
63                                           &bOk);
64     if( bOk && !name.toLatin1().trimmed().isEmpty() && dm->renameObj( entries.first(), name ) )
65       commit();
66     else
67       abort();
68   }
69 }