Mailinglist Archive: opensuse-packaging (100 mails)

< Previous Next >
Re: [opensuse-packaging] libqinfinity
  • From: "Sascha 'saigkill' Manns" <samannsml@xxxxxxxxxxxxx>
  • Date: Tue, 21 Apr 2009 17:03:15 +0200
  • Message-id: <200904211703.16385@xxxxxxxxxxxxxxxxxxxxx>
On Dienstag 21 April 2009 15:22:17 Pavol Rusnak wrote:
Sascha 'saigkill' Manns wrote:
This is the code from them.
BrowserIter &BrowserIter::operator=( const BrowserIter &other )
{
m_infBrowser = other.infBrowser();
m_infBrowserIter.node_id = other.infBrowserIter()->node_id;
m_infBrowserIter.node = other.infBrowserIter()->node;
return ;
}
What must i change?

Aha! When you overload assignment operator (=), it should end with
"return *this;" so it could be chained (eg. a = b = 3). Just insert
"*this" between "return" and ";".
Now he runs, and i can see the End. He breaks with:
testing for serious compiler warnings
(using /usr/lib/build/checks-data/check_gcc_output)
(using /var/tmp/build-root/.build.log)

I: Program returns random data in a function
E: libqinfinity no-return-in-nonvoid-function
/usr/src/packages/BUILD/libqinfinity-1.0b1/libqinfinity/browseriter.cpp:140,
134, 128, 122, 111, 105, 99, 93, 87, 81, 75, 69, 63, 57
E: libqinfinity no-return-in-nonvoid-function
/usr/src/packages/BUILD/libqinfinity-1.0b1/libqinfinity/browsermodel.cpp:222,
195

Musrt i here place "return *this;" on the End of each functions?
--
Sincereley yours

Sascha Manns
openSUSE Marketing Team
openSUSE Build Service
openSUSE Features Screening Team
Web: http://saschamanns.gulli.to
Project-Blog: http://lizards.opensuse.org/author/saigkill
Private-Blog: http://saschasbacktrace.blogspot.com
#include "browseriter.h"
#include "browser.h"

namespace QInfinity
{

BrowserIter::BrowserIter( const Browser &browser )
: m_infBrowser( INFC_BROWSER(browser.gobject()) )
{
infc_browser_iter_get_root( m_infBrowser, &m_infBrowserIter );
}

BrowserIter::BrowserIter( const InfcBrowserIter *infIter,
InfcBrowser *infBrowser )
: m_infBrowser( infBrowser )
{
m_infBrowserIter.node_id = infIter->node_id;
m_infBrowserIter.node = infIter->node;
}

BrowserIter::BrowserIter( const BrowserIter &other )
: m_infBrowser( other.infBrowser() )
{
m_infBrowserIter.node_id = other.infBrowserIter()->node_id;
m_infBrowserIter.node = other.infBrowserIter()->node;
}

BrowserIter &BrowserIter::operator++()
{
next();
return *this;
}

BrowserIter BrowserIter::operator++( int dummy )
{
next();
return *this;
}

BrowserIter &BrowserIter::operator--()
{
prev();
return *this;
}

BrowserIter BrowserIter::operator--( int dummy )
{
prev();
return *this;
}

BrowserIter &BrowserIter::operator=( const BrowserIter &other )
{
m_infBrowser = other.infBrowser();
m_infBrowserIter.node_id = other.infBrowserIter()->node_id;
m_infBrowserIter.node = other.infBrowserIter()->node;
}

bool BrowserIter::next()
{
if( m_infBrowser )
return infc_browser_iter_get_next( m_infBrowser,
&m_infBrowserIter ) != 0;
}

bool BrowserIter::prev()
{
if( m_infBrowser )
return infc_browser_iter_get_prev( m_infBrowser,
&m_infBrowserIter ) != 0;
}

bool BrowserIter::child()
{
if( m_infBrowser )
return infc_browser_iter_get_child( m_infBrowser,
&m_infBrowserIter ) != 0;
}

bool BrowserIter::parent()
{
if( m_infBrowser )
return infc_browser_iter_get_parent( m_infBrowser,
&m_infBrowserIter ) != 0;
}

bool BrowserIter::isDirectory()
{
if( m_infBrowser )
return infc_browser_iter_is_subdirectory( m_infBrowser,
&m_infBrowserIter ) != 0;
}

InfcExploreRequest *BrowserIter::explore()
{
if( m_infBrowser )
return infc_browser_iter_explore( m_infBrowser,
&m_infBrowserIter );
}

bool BrowserIter::isExplored()
{
if( m_infBrowser )
return infc_browser_iter_get_explored( m_infBrowser,
&m_infBrowserIter ) != 0;
}

QString BrowserIter::name()
{
if( m_infBrowser )
return infc_browser_iter_get_name( m_infBrowser,
&m_infBrowserIter );
}

QString BrowserIter::path()
{
if( m_infBrowser )
return infc_browser_iter_get_path( m_infBrowser,
&m_infBrowserIter );
}

QPointer<Browser> BrowserIter::browser() const
{
return Browser::wrap( infBrowser() );
}

InfcBrowser *BrowserIter::infBrowser() const
{
if( m_infBrowser )
return m_infBrowser;
}

const InfcBrowserIter *BrowserIter::infBrowserIter() const
{
if( m_infBrowser )
return &m_infBrowserIter;
}

InfcBrowserIter *BrowserIter::infBrowserIter()
{
if( m_infBrowser )
return &m_infBrowserIter;
}

QString BrowserIter::noteType()
{
if( m_infBrowser )
return infc_browser_iter_get_note_type( m_infBrowser,
&m_infBrowserIter );
}

}

#include "browsermodel.h"
#include "browser.h"
#include "xmlconnection.h"
#include "tcpconnection.h"
#include "browseritemfactory.h"
#include "noteplugin.h"

#include <QDebug>

#include "browsermodel.moc"

namespace QInfinity
{

ConnectionIndex::ConnectionIndex( XmlConnection &connection,
Browser &browser )
: m_xmlConnection( &connection )
, m_browser( &browser )
{
}

ConnectionIndex::~ConnectionIndex()
{
QInfinity::TcpConnection *tcpConn;
delete m_browser;
tcpConn = m_xmlConnection->tcpConnection();
delete m_xmlConnection;
delete tcpConn;
}

XmlConnection &ConnectionIndex::connection() const
{
return *m_xmlConnection;
}

Browser &ConnectionIndex::browser() const
{
return *m_browser;
}

NodeItem *ConnectionIndex::itemFromIter( const BrowserIter &iter ) const
{
if( nodeIdToNodeItemMap.contains( iter.infBrowserIter()->node_id ) )
return nodeIdToNodeItemMap[iter.infBrowserIter()->node_id];
else
return 0;
}

void ConnectionIndex::indexIter( const BrowserIter &iter,
NodeItem &node )
{
nodeIdToNodeItemMap[iter.infBrowserIter()->node_id] = &node;
}

void ConnectionIndex::removeIter( const BrowserIter &iter )
{
nodeIdToNodeItemMap.remove(iter.infBrowserIter()->node_id);
}

BrowserModel::BrowserModel( QObject *parent )
: QStandardItemModel( parent )
, m_itemFactory( new BrowserItemFactory )
{
QStringList headerlabels;
headerlabels.append( tr("Name") );
setHorizontalHeaderLabels( headerlabels );
}

BrowserModel::BrowserModel( BrowserItemFactory *itemFactory,
QObject *parent )
: QStandardItemModel( parent )
, m_itemFactory( itemFactory )
{
if( !m_itemFactory)
m_itemFactory = new BrowserItemFactory;
m_itemFactory->setParent( this );
}

BrowserModel::~BrowserModel()
{
QList<ConnectionIndex*> connIdexes;
ConnectionIndex *index;
connIdexes = browserToConnectionMap.values();

foreach(index, connIdexes)
delete index;
delete m_itemFactory;
}

void BrowserModel::setItemFactory( BrowserItemFactory *factory )
{
if( !factory )
return;

m_itemFactory = factory;
}

ConnectionItem *BrowserModel::addConnection( XmlConnection &connection,
const QString &name )
{
Browser *browser;
ConnectionIndex *index;
ConnectionItem *connItem;
NodeItem *nodeItem;
NotePlugin* plugin;

connection.setParent( this );

// Create and initialive a new browser
browser = createBrowser( comm_mgr, connection );
foreach( plugin, plugins() )
browser->addPlugin( *plugin );
index = new ConnectionIndex( connection, *browser );
browserToConnectionMap[browser] = index;
connect( browser, SIGNAL(nodeAdded( const BrowserIter&)),
this, SLOT(slotNodeAdded( const BrowserIter&)) );
connect( browser, SIGNAL(nodeRemoved( const BrowserIter& )),
this, SLOT(slotNodeRemoved( const BrowserIter& )) );

connItem = m_itemFactory->createConnectionItem( connection,
*browser,
name );
connItem->setParent( this );
insertRow( 0, connItem );
BrowserIter rootNode( *browser );
nodeItem = m_itemFactory->createRootNodeItem( rootNode );
indexIter( rootNode, *browser, *nodeItem );
connItem->setChild( 0, nodeItem );
return connItem;
}

bool BrowserModel::hasChildren( const QModelIndex &parent ) const
{
if( !parent.isValid() )
return true;
QStandardItem *stdItem = itemFromIndex(parent);
NodeItem *nodeItem;

if( stdItem->type() == BrowserItemFactory::ConnectionItem )
{
return true;
}
if( stdItem->type() == BrowserItemFactory::NodeItem )
{
nodeItem = dynamic_cast<NodeItem*>(stdItem);
return nodeItem->isDirectory();
}

return false;
}

void BrowserModel::addPlugin( NotePlugin &plugin )
{
plugin.setParent( this );
ConnectionIndex *index;
foreach( index, browserToConnectionMap.values() )
index->browser().addPlugin( plugin );
m_plugins.append( &plugin );
}

QList<NotePlugin*> BrowserModel::plugins() const
{
return m_plugins;
}

QList<Browser*> BrowserModel::browsers() const
{
return m_browsers;
}

bool BrowserModel::createDirectory( const QModelIndex &parent,
const QString &name )
{
NodeItem *parentItem;
Browser *browser;

parentItem = indexToNodeItem( parent );
if( !parentItem )
{
qDebug() << "Parent not a node item.";
return false;
}
if( !parentItem->isDirectory() )
{
qDebug() << "Cannot create folder with parent not a directory.";
return false;
}
browser = parentItem->iter().browser();
if( !browser )
{
qDebug() << "Could not find parent items' browser.";
return false;
}
browser->addSubdirectory( parentItem->iter(), name.toAscii() );
}

bool BrowserModel::createNote( const QModelIndex &parent,
NotePlugin &plugin,
const QString &name )
{
NodeItem *parentItem;
Browser *browser;

parentItem = indexToNodeItem( parent );
if( !parentItem )
{
qDebug() << "Parent not a node item.";
return false;
}
if( !parentItem->isDirectory() )
{
qDebug() << "Cannot create note unless parent is a directory.";
return false;
}
browser = parentItem->iter().browser();
if( !browser )
{
qDebug() << "Could not find parent items' browser.";
return false;
}
browser->addNote( parentItem->iter(), name.toAscii(), plugin, false );
}

bool BrowserModel::removeRows( int row, int count,
const QModelIndex &parent )
{
qDebug() << "Remove rows";
int i;
QStandardItem *item, *parentItem;;
parentItem = itemFromIndex( parent );
for( i = 0; i < count; i++ )
{
item = parentItem->child( row + i );
if( item->type() == BrowserItemFactory::ConnectionItem )
removeConnectionItem(
dynamic_cast<ConnectionItem*>(item) );
else
deleteNodeItem( dynamic_cast<NodeItem*>(item) );
}
return true;
}

void BrowserModel::itemActivated( const QModelIndex &parent )
{
if( !parent.isValid() )
return;
QStandardItem *stdItem = itemFromIndex(parent);

if( stdItem->type() == BrowserItemFactory::NodeItem )
dynamic_cast<NodeItem*>(stdItem)->activate();
}

void BrowserModel::slotNodeAdded( const BrowserIter &itr )
{
NodeItem *item, *parentItem;
Browser *browser;
BrowserIter parentItr( itr );

item = m_itemFactory->createNodeItem( itr );
browser = dynamic_cast<Browser*>(sender());
indexIter( itr, *browser, *item );

parentItr.parent();
parentItem = itemFromBrowserIter( parentItr, *browser );
if( !parentItem )
{
qDebug() << "Couldnt find parent to add node to.";
return;
}
parentItem->insertRow( 0, item );
}

void BrowserModel::slotNodeRemoved( const BrowserIter &itr )
{
qDebug() << "Removing node";
NodeItem *nodeItem = itemFromBrowserIter( itr, *itr.browser() );
if( !nodeItem )
{
qDebug() << "Couldnt find item in model to remove! "
<< " The browsing model may be inconsistent!";
return;
}
QStandardItemModel::removeRows( nodeItem->row(), 1,
nodeItem->parent()->index() );
removeIterIndex( itr, *itr.browser() );
}

void BrowserModel::removeConnectionItem( ConnectionItem *item )
{
if( !item )
{
qDebug() << "Cant remove null connection item.";
return;
}
ConnectionIndex *index;
index = browserToConnectionMap[&item->browser()];
browserToConnectionMap.remove(&item->browser());
delete index;
}

void BrowserModel::deleteNodeItem( NodeItem *item )
{
QPointer<Browser> browser = item->iter().browser();
browser->removeNode( item->iter() );
}

void BrowserModel::indexIter( const BrowserIter &iter,
Browser &browser,
NodeItem &item )
{
ConnectionIndex *index;

index = browserToConnectionMap[&browser];
index->indexIter( iter, item );
}

void BrowserModel::removeIterIndex( const BrowserIter &iter,
Browser &browser )
{
ConnectionIndex *index;

index = browserToConnectionMap[&browser];
index->removeIter( iter );
}

NodeItem *BrowserModel::itemFromBrowserIter( const BrowserIter &iter,
Browser &browser )
{
ConnectionIndex *index;

index = browserToConnectionMap[&browser];
return index->itemFromIter( iter );
}

NodeItem *BrowserModel::indexToNodeItem( const QModelIndex &item ) const
{
if( !item.isValid() )
{
qDebug() << "Root item is not a node.";
return 0;
}
QStandardItem *stdItem = itemFromIndex( item );
if( stdItem->type() == BrowserItemFactory::NodeItem )
return dynamic_cast<NodeItem*>(stdItem);
else
{
qDebug() << "Cannot convert to NodeItem non NodeItem type.";
return 0;
}
}

/*
* Creates a browser and adds all plugins to it.
*/
Browser *BrowserModel::createBrowser( CommunicationManager &commMgr,
XmlConnection &connection )
{
Browser *browser = new Browser( commMgr, connection, this );
QList<NotePlugin*> pluginList = plugins();
QList<NotePlugin*>::Iterator itr;
for( itr = pluginList.begin(); itr != pluginList.end(); itr++ )
{
browser->addPlugin( **itr );
}
m_browsers.append( browser );
emit( browserAdded( *browser ) );
return browser;
}

}

< Previous Next >