0031939: Coding - correction of spelling errors in comments [part 2]
[occt.git] / tools / VInspector / VInspector_ToolBar.cxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #include <inspector/VInspector_ToolBar.hxx>
17
18 #include <Standard_WarningsDisable.hxx>
19 #include <QHBoxLayout>
20 #include <QPushButton>
21 #include <QWidget>
22 #include <Standard_WarningsRestore.hxx>
23
24 // =======================================================================
25 // function : Constructor
26 // purpose :
27 // =======================================================================
28 VInspector_ToolBar::VInspector_ToolBar (QWidget* theParent)
29 : QObject (theParent)
30 {
31   myActionsMap[VInspector_ToolActionType_UpdateId] = new QPushButton (theParent);
32   myActionsMap[VInspector_ToolActionType_UpdateId]->setIcon (QIcon (":/icons/treeview_update.png"));
33   myActionsMap[VInspector_ToolActionType_UpdateId]->setText (tr ("Update Tree Model"));
34   myActionsMap[VInspector_ToolActionType_UpdateId]->setToolTip (tr ("Update Tree Model"));
35
36   myActionsMap[VInspector_ToolActionType_UpdateId]->setText ("Update");
37
38   myMainWindow = new QWidget (theParent);
39
40   QHBoxLayout* aLay = new QHBoxLayout (myMainWindow);
41   aLay->setMargin(0);
42   for (QMap<VInspector_ToolActionType, QPushButton*>::ConstIterator anActionsIt = myActionsMap.begin();
43        anActionsIt != myActionsMap.end(); anActionsIt++)
44   {
45     QPushButton* aBtn = anActionsIt.value();
46     connect (aBtn, SIGNAL (clicked()), this, SLOT (onActionClicked()));
47     aLay->addWidget (aBtn);
48   }
49   aLay->addStretch(1);
50 }
51
52 // =======================================================================
53 // function : GetToolButton
54 // purpose :
55 // =======================================================================
56 QPushButton* VInspector_ToolBar::GetToolButton (const VInspector_ToolActionType& theActionId ) const
57 {
58   return myActionsMap.contains (theActionId) ? myActionsMap[theActionId] : 0;
59 }
60
61 // =======================================================================
62 // function : onActionClicked
63 // purpose :
64 // =======================================================================
65 void VInspector_ToolBar::onActionClicked()
66 {
67   int anId = -1;
68   QPushButton* aSenderBtn = (QPushButton*)sender();
69
70   for (QMap<VInspector_ToolActionType, QPushButton*>::ConstIterator anActionsIt = myActionsMap.begin();
71        anActionsIt != myActionsMap.end(); anActionsIt++)
72   {
73     if (anActionsIt.value() != aSenderBtn)
74       continue;
75     anId = anActionsIt.key();
76     break;
77   }
78
79   if (anId != -1)
80     emit actionClicked (anId);
81 }