Commit a946994b authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[MERGE]

parents ad55670d 7157877b
......@@ -81,23 +81,29 @@ void WProgressCombiner::update()
rlock.unlock();
}
std::string WProgressCombiner::getCombinedNames() const
std::string WProgressCombiner::getCombinedNames( bool excludeFinished ) const
{
// read lock combiner
boost::shared_lock< boost::shared_mutex > rlock = boost::shared_lock< boost::shared_mutex >( m_updateLock );
std::stringstream ss;
ss << "[";
bool addComma = false; // when true, a "," is appended before printing the next name. This is needed as we do not know if an element is the
// last one if excludeFinished == true.
for( std::set< boost::shared_ptr< WProgress > >::const_iterator i = m_children.begin(); i != m_children.end(); ++i )
{
// enforce child to update
ss << ( *i )->getName();
if( boost::next( i ) != m_children.end() )
if( !( !( *i )->isPending() && excludeFinished ) )
{
ss << ", ";
if( addComma )
{
ss << ", ";
}
// enforce child to update
ss << ( *i )->getName();
// in next step, add a comma
addComma = true;
}
}
ss << "]";
// Done. Free lock.
rlock.unlock();
......
......@@ -103,9 +103,11 @@ public:
/**
* Generates a string combined out of every child progress name.
*
* \param excludeFinished if true, the combined name list only contains unfinished progress'
*
* \return One describing string for all child progress names.
*/
std::string getCombinedNames() const;
std::string getCombinedNames( bool excludeFinished = false ) const;
protected:
/**
......
......@@ -73,6 +73,27 @@ namespace string_utils
return ss.str();
}
/**
* Convert a given value to a string. The input value must provide a operator<< or be a standard scalar type. This method additionally allows
* setting width and precision flags of the used std::stringstream.
*
* \tparam T the source type. You do not need to specify this directly as it can be deducted from the given parameter
* \param value the value to cast to string
* \param precision the precision
* \param width the width
*
* \return the string.
*/
template< typename T >
inline std::string toString( const T& value, const size_t width, const size_t precision )
{
std::stringstream ss;
ss.width( width );
ss.precision( precision );
ss << value;
return ss.str();
}
/**
* Convert a given string to a value of a certain type. The target type must provide a operator>> to work or be a standard scalar type.
*
......
......@@ -198,3 +198,15 @@ std::vector< WModuleMetaInformation::Online > WModuleMetaInformation::getOnlineR
return r;
}
std::vector< std::string > WModuleMetaInformation::getTags() const
{
// return a default if not meta data was loaded
if( !m_loaded )
{
return std::vector< std::string >();
}
// find key-value pair
return m_metaData.getValues< std::string >( m_name + "/tag" );
}
......@@ -173,6 +173,12 @@ public:
*/
std::vector< Online > getOnlineResources() const;
/**
* A list of tags provided for the module.
*
* \return the tag list.
*/
std::vector< std::string > getTags() const;
protected:
private:
/**
......
......@@ -66,6 +66,12 @@
what="Bug fixing";
};
// Provide some tags to have modules nicely grouped and ordered.
// NOTE: tags are handled case insesitive.
// IMPORTANT: the order of appearance will be used by OW to classify your tags
tag = "Navigation";
tag = "MRT";
// You can provide online resources. They are shown in the GUI. You should
// additionally provide a description to help the user know what this is.
online
......
......@@ -45,6 +45,10 @@
#include "core/kernel/WModuleContainer.h"
#include "core/kernel/WModuleFactory.h"
#include "core/kernel/WROIManager.h"
#include "../WMainWindow.h"
#include "../WQt4Gui.h"
#include "../WQtCombinerActionList.h"
#include "../WQtModuleConfig.h"
#include "../events/WEventTypes.h"
#include "../events/WModuleAssocEvent.h"
#include "../events/WModuleConnectEvent.h"
......@@ -55,11 +59,8 @@
#include "../events/WModuleRemovedEvent.h"
#include "../events/WRoiAssocEvent.h"
#include "../events/WRoiRemoveEvent.h"
#include "../WMainWindow.h"
#include "../guiElements/WQtModuleMetaInfo.h"
#include "../networkEditor/WQtNetworkEditor.h"
#include "../WQt4Gui.h"
#include "../WQtCombinerActionList.h"
#include "../WQtModuleConfig.h"
#include "WQtBranchTreeItem.h"
#include "WQtColormapper.h"
......@@ -863,6 +864,10 @@ void WQtControlPanel::setActiveModule( WModule::SPtr module, bool forceUpdate )
// remove property tabs
clearAndDeleteTabs();
// update module meta info tab also for crashed modules
WQtModuleMetaInfo* metaInfoWidget = new WQtModuleMetaInfo( module );
m_tabWidget->addTab( metaInfoWidget, "About && Help" );
// set new property tabs if module is not crashed
if( !module->isCrashed() )
{
......@@ -1237,7 +1242,7 @@ void WQtControlPanel::clearAndDeleteTabs()
{
m_tabWidget->setDisabled( true );
QWidget *widget;
while( ( widget = m_tabWidget->widget( 0 ) ))
while( ( widget = m_tabWidget->widget( 0 ) ))
{
m_tabWidget->removeTab( 0 );
delete widget;
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WQtModuleMetaInfo.h"
#include "WQtModuleMetaInfo.moc"
WQtModuleMetaInfo::WQtModuleMetaInfo( WModule::SPtr module, QWidget* parent ):
QTextEdit( parent ),
m_module( module )
{
// initialize members
setText( "Currently in development. Check back soon." );
}
WQtModuleMetaInfo::~WQtModuleMetaInfo()
{
// cleanup
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WQTMODULEMETAINFO_H
#define WQTMODULEMETAINFO_H
#include <QtGui/QTextEdit>
#include "core/kernel/WModule.h"
/**
* Text widget showing the module meta data.
*/
class WQtModuleMetaInfo: public QTextEdit
{
Q_OBJECT
public:
/**
* Default constructor.
*
* \param parent the parent widget
* \param module the module for which to show the meta info
*/
WQtModuleMetaInfo( WModule::SPtr module, QWidget* parent = 0 );
/**
* Destructor.
*/
virtual ~WQtModuleMetaInfo();
protected:
private:
/**
* The module.
*/
WModule::SPtr m_module;
};
#endif // WQTMODULEMETAINFO_H
......@@ -30,13 +30,13 @@
#define WNETWORKPORT_SIZEY 10
// Distance to element border of sub elements
#define WNETWORKITE_MARGINX 3
#define WNETWORKITE_MARGINY 3
#define WNETWORKITEM_MARGINX 3
#define WNETWORKITEM_MARGINY 3
// The minimum width and heigh of items inside the scene
#define WNETWORKITEM_MINIMUM_WIDTH 125
#define WNETWORKITEM_MINIMUM_HEIGHT 50
#define WNETWORKITEM_MAXIMUM_WIDTH 250
#define WNETWORKITEM_MAXIMUM_WIDTH 200
#define WNETWORKITEM_MAXIMUM_HEIGHT 100
#endif // WQTNETWORKEDITORGLOBALS_H
......
......@@ -32,6 +32,8 @@
#include <QtGui/QTextCharFormat>
#include <QtGui/QTextCursor>
#include "core/common/WStringUtils.h"
#include "WQtNetworkArrow.h"
#include "WQtNetworkItem.h"
#include "WQtNetworkItemActivator.h"
......@@ -46,7 +48,8 @@ WQtNetworkItem::WQtNetworkItem( WQtNetworkEditor *editor, boost::shared_ptr< WMo
m_isSelected( false ),
m_busyIsDetermined( false ),
m_busyPercent( 0.0 ),
m_busyIndicatorShow( false )
m_busyIndicatorShow( false ),
m_forceUpdate( true )
{
m_networkEditor = editor;
m_module = module;
......@@ -126,6 +129,8 @@ WQtNetworkItem::WQtNetworkItem( WQtNetworkEditor *editor, boost::shared_ptr< WMo
activate( false );
fitLook();
// this now calculated the optimal size. We keep them for later use
m_itemBestWidth = boundingRect().width();
m_layoutNode = NULL;
}
......@@ -152,42 +157,82 @@ int WQtNetworkItem::type() const
void WQtNetworkItem::updater()
{
bool needUpdate = false;
boost::shared_ptr< WProgressCombiner> p = m_module->getRootProgressCombiner();
// update the progress combiners internal state
p->update();
// it is very important to avoid unnecessary changes to pen/brush and similar stuff to avoid permanent updates of the graphics item.
bool needUpdate = m_forceUpdate;
m_forceUpdate = false;
if( p->isPending() )
// progress indication is only needed for running modules
if( m_currentState != Crashed )
{
// update subtext
m_subtitleFull = "Busy"; // TODO(ebaum): use progress text here
fitLook();
// handle progress indication
boost::shared_ptr< WProgressCombiner> p = m_module->getRootProgressCombiner();
// update indicator
m_busyIndicatorShow = true;
m_busyIsDetermined = p->isDetermined();
if( m_busyIsDetermined )
// update the progress combiners internal state
p->update();
if( p->isPending() )
{
m_busyPercent = p->getProgress() / 100.0;
m_busyIndicatorShow = true;
m_busyIsDetermined = p->isDetermined();
// update subtext
m_subtitleFull = p->getCombinedNames( true );
if( m_subtitleFull.empty() ) // if some lazy programmer did not provide names for the progress -> set one
{
m_subtitleFull = "Busy";
}
// we add the percent-counter to the front because the fitLook method shortens the subtext string if it is too long. This might clip out
// the percentage if the p->getCombinedNames string is quite long.
if(m_busyIsDetermined ) // <- of course only add if we have a known percentage
{
// NOTE: Percentage of a WProgressCombiner always multiplicatively combines all percentages of the children
m_subtitleFull = string_utils::toString( static_cast< uint16_t >( p->getProgress() ) ) + "% - " + m_subtitleFull;
}
// this method ensures the text is shortened and correctly placed in the iem
fitLook( m_itemBestWidth, m_itemBestWidth );
// update indicator
if( m_busyIsDetermined )
{
m_busyPercent = p->getProgress() / 100.0;
}
else
{
m_busyPercent += 0.025;
if( m_busyPercent > 1.0 )
{
m_busyPercent = 0.0;
}
}
needUpdate = true;
}
else
{
m_busyPercent += 0.025;
if( m_busyPercent > 1.0 )
// if busy indication was active -> update to remove it again
needUpdate |= m_busyIndicatorShow;
m_busyIndicatorShow = false;
WDataModule::SPtr dataModule = boost::shared_dynamic_cast< WDataModule >( m_module );
if( dataModule )
{
m_subtitleFull = dataModule->getFilename().filename().string();
}
else
{
m_busyPercent = 0.0;
m_subtitleFull = "Idle";
}
fitLook( m_itemBestWidth, m_itemBestWidth );
}
needUpdate = true;
}
else
// show crash state as text too
if( ( m_currentState == Crashed ) && ( m_subtitleFull != "Crashed" ) )
{
// if busy indication was active -> update to remove it again
needUpdate |= m_busyIndicatorShow;
m_busyIndicatorShow = false;
m_subtitleFull = "Idle";
fitLook();
m_subtitleFull = "Crashed";
// this method ensures the text is shortened and correctly placed in the iem
fitLook( m_itemBestWidth, m_itemBestWidth );
needUpdate = true;
}
if( needUpdate )
......@@ -382,13 +427,13 @@ void clipText( QGraphicsTextItem* item, float maxWidth, std::string fullText )
}
}
void WQtNetworkItem::fitLook()
void WQtNetworkItem::fitLook( float maximumWidth, float minimumWidth )
{
// The purpose of this method is to ensure proper dimensions of the item and the contained text. This method ensures:
// * an item maximum size is WNETWORKITEM_MINIMUM_WIDTH or the width of the connectors!
// * text exceeding size limits is cut
m_width = WNETWORKITEM_MINIMUM_WIDTH;
m_width = minimumWidth;
m_height = WNETWORKITEM_MINIMUM_HEIGHT;
// we need to respect the size minimally needed by ports
......@@ -396,7 +441,7 @@ void WQtNetworkItem::fitLook()
// the item needs a maximum size constraint to avoid enormously large items
// NOTE: the specified size max can only be overwritten by the
float maxWidth = std::max( static_cast< float >( WNETWORKITEM_MAXIMUM_WIDTH ), portWidth );
float maxWidth = std::max( static_cast< float >( maximumWidth ), portWidth );
// the width of the text elements
float textWidth = 0.0;
......@@ -417,14 +462,14 @@ void WQtNetworkItem::fitLook()
{
subtextWidth = static_cast< float >( m_subtitle->boundingRect().width() );
subtextHeight = static_cast< float >( m_subtitle->boundingRect().height() );
subtextMargin = 1.0f * WNETWORKITE_MARGINY;
subtextMargin = 1.0f * WNETWORKITEM_MARGINY;
}
// and another height: the height of text and subtext
float wholeTextHeight = textHeight + subtextHeight + subtextMargin;
// get the required width and height
float maxTextWidth = maxWidth - ( 2.0f * WNETWORKITE_MARGINX );
float maxTextWidth = maxWidth - ( 2.0f * WNETWORKITEM_MARGINX );
// 2: limit sizes of sub elements if needed (especially the subtext)
if( ( m_text != 0 ) )
......@@ -447,12 +492,12 @@ void WQtNetworkItem::fitLook()
subtextWidth = static_cast< float >( m_subtitle->boundingRect().width() );
subtextHeight = static_cast< float >( m_subtitle->boundingRect().height() );
}
float requiredWidth = std::max( portWidth, std::max( subtextWidth, textWidth ) + ( 2.0f * WNETWORKITE_MARGINX ) );
float requiredHeight = wholeTextHeight + ( 2.0f * WNETWORKITE_MARGINY );
float requiredWidth = std::max( portWidth, std::max( subtextWidth, textWidth ) + ( 2.0f * WNETWORKITEM_MARGINX ) );
float requiredHeight = wholeTextHeight + ( 2.0f * WNETWORKITEM_MARGINY );
// 3: set the final sizes
m_height = std::max( requiredHeight, static_cast< float >( WNETWORKITEM_MINIMUM_HEIGHT ) );
m_width = std::min( std::max( requiredWidth, static_cast< float >( WNETWORKITEM_MINIMUM_WIDTH ) ), maxWidth );
m_width = std::min( std::max( requiredWidth, static_cast< float >( minimumWidth ) ), maxWidth );
QRectF rect( 0, 0, m_width, m_height );
m_rect = rect;
......@@ -506,6 +551,7 @@ void WQtNetworkItem::setCrashed()
void WQtNetworkItem::changeState( State state )
{
m_forceUpdate = ( m_currentState != state );
m_currentState = state;
update();
}
......
......@@ -107,8 +107,11 @@ public:
/**
* This method aligns the in- and outports as well as the modulename
* in a regular way.
*
* \param maximumWidth the maximal width of the item.
* \param minimumWidth the minimal width of the item.
*/
void fitLook();
void fitLook( float maximumWidth = WNETWORKITEM_MAXIMUM_WIDTH, float minimumWidth = WNETWORKITEM_MINIMUM_WIDTH );
/**
* Set the QGraphicsTextItem ( the caption ) of the item
......@@ -281,5 +284,15 @@ private:
* If true, the busy indication is active.
*/
bool m_busyIndicatorShow;
/**
* If true, the next call to update() will force a redraw. Avoid setting this to true permanently.
*/
bool m_forceUpdate;
/**
* Optimal width for this module. Calculated during construction.
*/
float m_itemBestWidth;
};
#endif // WQTNETWORKITEM_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment