OpenWalnut  1.5.0dev
WQtModuleOneToOneCombinerAction.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <memory>
26 #include <string>
27 
28 #include "WQtModuleOneToOneCombinerAction.h"
29 
31  std::shared_ptr< WModuleOneToOneCombiner > combiner,
32  bool advancedText ):
33  QAction( parent ),
34  m_combiner( combiner )
35 {
36  // nice tooltip
37  std::string from = "";
38 
39  // NOTE: all the tooltips and so on for this action are used from the first combiner in the group
40 
41  // use the name property of the modules
42  std::string srcName = "";
43  std::string targetName = m_combiner->getTargetModule()->getProperties()->getProperty( "Name" )->toPropString()->get();
44 
45  // might be null ( for example if a module should be added that does not require an input)
46  if( m_combiner->getSrcModule() )
47  {
48  srcName = m_combiner->getSrcModule()->getProperties()->getProperty( "Name" )->toPropString()->get();
49 
50  // append real module name if it is different from user specified name
51  if( srcName != m_combiner->getSrcModule()->getName() )
52  {
53  srcName += " (" + m_combiner->getSrcModule()->getName() + ")";
54  }
55  }
56 
57  // append real module name if it is different from user specified name
58  if( targetName != m_combiner->getTargetModule()->getName() )
59  {
60  targetName += " (" + m_combiner->getTargetModule()->getName() + ")";
61  }
62 
63  from = srcName + ": <i>" + m_combiner->getSrcConnector() + "</i> &nbsp;&nbsp;&#10140;&nbsp;&nbsp; ";
64  std::string tooltip = "<b>" + targetName + "</b><br><nobr>" + from + targetName + ": <i>" + m_combiner->getTargetConnector() + "</i></nobr>";
65  tooltip += "<br><b>Module Description: </b><br/>" + m_combiner->getTargetModule()->getDescription();
66 
67  // We need this because menu items seem not to support HTML
68  std::string advancedTextString = srcName + ":" + m_combiner->getSrcConnector() + " -> " + targetName + ":" + m_combiner->getTargetConnector();
69 
70  setToolTip( tooltip.c_str() );
71  setText( advancedText ? advancedTextString.c_str() : targetName.c_str() );
72  setIconText( advancedText ? tooltip.c_str() : targetName.c_str() );
73 
74  // get an icon for this module
75  setIcon( iconManager->getIcon( m_combiner->getTargetModule()->getName().c_str(), iconManager->getIcon( "DefaultModuleIcon" ) ) );
76 
77  // we need to use released signal here, as the pushed signal also gets emitted on newly created buttons which are under the mouse pointer with
78  // pressed left button.
79  connect( this, SIGNAL( triggered() ), this, SLOT( applyCombiner() ) );
80 }
81 
83 {
84 }
85 
87 {
88  m_combiner->run();
89 }
90 
Manages icon access.
Definition: WIconManager.h:41
QIcon getIcon(const std::string name)
Searches icons in the internal map and all modules for the given icon name.
void applyCombiner()
Gets called by the action if it was triggered.
std::shared_ptr< WModuleOneToOneCombiner > m_combiner
The combiner of this action.
WQtModuleOneToOneCombinerAction(QWidget *parent, WIconManager *iconManager, std::shared_ptr< WModuleOneToOneCombiner > combiner, bool advancedText=false)
Constructor creating a module application action.