Skip to content
Snippets Groups Projects
Select Git revision
  • 41a019dc843b9812e44b8108e7916e0bcb71c71d
  • master default protected
  • cali
  • dev protected
4 results

iprinter.cpp

Blame
  • user avatar
    am0ebe authored
    00b0b837
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    iprinter.cpp 1.89 KiB
    #include "iprinter.h"
    #include <QDebug>
    #ifdef CONSOLE
    #include "cmd/console.h"
    #endif
    
    
    IPrinter::IPrinter(QObject *parent) : QObject(parent)
    {
    #ifdef CONSOLE //defined in .pro
    	//vmb (core, cam) -> ui (controller.console)
    	Console* console = Console::getInstance();
    	connect(this, SIGNAL(error(const QString&, const int&)), console, SLOT(error(const QString&, const int&)), Qt::DirectConnection);
    	connect(this, SIGNAL(error(const int&)), console, SLOT(error(const int&)), Qt::DirectConnection);
    	connect(this, SIGNAL(info(const QString&)), console, SLOT(print(const QString&)), Qt::DirectConnection);
    	connect(this, SIGNAL(info(const QStringList&)), console, SLOT(print(const QStringList&)), Qt::DirectConnection);
    #endif
    
    }
    
    IPrinter::~IPrinter()
    {
    }
    
    void IPrinter::print(const QStringList& name)
    {
    	emit info(name);
    }
    
    
    void IPrinter::print(const QString& name)
    {
    	emit info(name);
    }
    
    void IPrinter::print(const QString& name, const VmbInt64_t& val)
    {
    	if( val != 0 )
    		emit info(QString("%1: %2").arg(name).arg(val));
    	else
    		emit info(name);
    }
    
    void IPrinter::print(const QString& name, const std::string& val)
    {
    	if( val.empty() )
    		emit info(name);
    	else
    		emit info(name + ": " + QString::fromStdString(val));
    }
    
    bool IPrinter::f(const VmbErrorType& ret, const QString& msg)
    {
    	// vimba function wrapper to test return type and potentially emit error message or successmsg
    	// returns true on error
    	// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << " ret:" << ret << " msg:" << msg;
    
    	if ( VmbErrorSuccess == ret )
    	{
    		if (! msg.isEmpty())
    			emit info(msg);
    
    		return false;
    	}
    	else
    	{
    		if (! msg.isEmpty())
    			emit info("Fail! " + msg);
    		emit error(ret);
    		return true;
    	}
    }
    
    void IPrinter::g(const VmbErrorType& ret, const QString& msg)
    {
    	//vimba function wrapper - throws exception on error - to declutter error handling code
    	if( f(ret,msg) )
    		throw std::runtime_error("Error: " + msg.toStdString());
    }