Skip to content
Permalink
Browse files

fix windows build

  • Loading branch information
jef-n committed May 21, 2011
1 parent d85320b commit 694c3561583a94344e2e4a280cf09627ec458dbc
Showing with 350 additions and 297 deletions.
  1. +84 −83 src/browser/qgsbrowsermodel.cpp
  2. +188 −143 src/core/qgsdataitem.cpp
  3. +78 −71 src/core/qgsdataitem.h
167 src/browser/qgsbrowsermodel.cpp 100644 → 100755
@@ -11,86 +11,89 @@
#include "qgsbrowsermodel.h"


QgsBrowserModel::QgsBrowserModel(QObject *parent) :
QAbstractItemModel(parent)
QgsBrowserModel::QgsBrowserModel( QObject *parent ) :
QAbstractItemModel( parent )
{
QStyle *style = QApplication::style();
mIconDirectory = QIcon( style->standardPixmap( QStyle::SP_DirClosedIcon ) );
mIconDirectory.addPixmap( style->standardPixmap( QStyle::SP_DirOpenIcon ),
QIcon::Normal, QIcon::On );

foreach (QFileInfo drive, QDir::drives())
foreach( QFileInfo drive, QDir::drives() )
{
QString path = drive.absolutePath();
QgsDirectoryItem *item = new QgsDirectoryItem(NULL, path, path);
QgsDirectoryItem *item = new QgsDirectoryItem( NULL, path, path );

connectItem(item);
connectItem( item );
mRootItems << item;
}

// Add non file top level items
foreach ( QString key, QgsProviderRegistry::instance()->providerList() )
foreach( QString key, QgsProviderRegistry::instance()->providerList() )
{
QLibrary *library = QgsProviderRegistry::instance()->getLibrary(key);
QLibrary *library = QgsProviderRegistry::instance()->getLibrary( key );
if ( !library ) continue;

dataCapabilities_t * dataCapabilities = (dataCapabilities_t *) cast_to_fptr( library->resolve ("dataCapabilities") );
if ( !dataCapabilities ) {
QgsDebugMsg ( library->fileName() + " does not have dataCapabilities" );
dataCapabilities_t * dataCapabilities = ( dataCapabilities_t * ) cast_to_fptr( library->resolve( "dataCapabilities" ) );
if ( !dataCapabilities )
{
QgsDebugMsg( library->fileName() + " does not have dataCapabilities" );
continue;
}

int capabilities = dataCapabilities();
if ( capabilities == QgsDataProvider::NoDataCapabilities )
if ( capabilities == QgsDataProvider::NoDataCapabilities )
{
QgsDebugMsg ( library->fileName() + " does not have any dataCapabilities" );
QgsDebugMsg( library->fileName() + " does not have any dataCapabilities" );
continue;
}

dataItem_t * dataItem = (dataItem_t *) cast_to_fptr( library->resolve ("dataItem" ) );
dataItem_t * dataItem = ( dataItem_t * ) cast_to_fptr( library->resolve( "dataItem" ) );
if ( ! dataItem )
{
QgsDebugMsg ( library->fileName() + " does not have dataItem" );
QgsDebugMsg( library->fileName() + " does not have dataItem" );
continue;
}

QgsDataItem * item = dataItem ( "", NULL ); // empty path -> top level
QgsDataItem * item = dataItem( "", NULL ); // empty path -> top level
if ( item )
{
QgsDebugMsg ( "Add new top level item : " + item->name() );
connectItem(item);
QgsDebugMsg( "Add new top level item : " + item->name() );
connectItem( item );
mRootItems << item;
}
}
}

QgsBrowserModel::~QgsBrowserModel()
{
foreach (QgsDataItem* item, mRootItems)
foreach( QgsDataItem* item, mRootItems )
{
delete item;
}
}


Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex & index ) const
{
if (!index.isValid())
if ( !index.isValid() )
return 0;

return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}

QVariant QgsBrowserModel::data( const QModelIndex & index, int role ) const
{
if (!index.isValid())
if ( !index.isValid() )
return QVariant();

QgsDataItem* ptr = (QgsDataItem*) index.internalPointer();
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();

if (role == Qt::DisplayRole)
if ( role == Qt::DisplayRole )
{
return QVariant(ptr->name());
return QVariant( ptr->name() );
}
else if (role == Qt::DecorationRole && index.column() == 0)
else if ( role == Qt::DecorationRole && index.column() == 0 )
{
return QVariant( ptr->icon() );
}
@@ -101,49 +104,47 @@ QVariant QgsBrowserModel::data( const QModelIndex & index, int role ) const

QVariant QgsBrowserModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
{
return QVariant("header");
return QVariant( "header" );
}

return QVariant();
}

int QgsBrowserModel::rowCount( const QModelIndex & parent ) const
{
//qDebug("rowCount: idx: (valid %d) %d %d", parent.isValid(), parent.row(), parent.column());
//qDebug("rowCount: idx: (valid %d) %d %d", parent.isValid(), parent.row(), parent.column());

if (!parent.isValid())
{
// root item: its children are top level items
return mRootItems.count(); // mRoot
}
else
{
// ordinary item: number of its children
QgsDataItem* ptr = (QgsDataItem*) parent.internalPointer();
if ( !parent.isValid() )
{
// root item: its children are top level items
return mRootItems.count(); // mRoot
}
else
{
// ordinary item: number of its children
QgsDataItem* ptr = ( QgsDataItem* ) parent.internalPointer();

return ptr->rowCount();
}
return ptr->rowCount();
}
}

bool QgsBrowserModel::hasChildren ( const QModelIndex & parent ) const
bool QgsBrowserModel::hasChildren( const QModelIndex & parent ) const
{
if (!parent.isValid())
if ( !parent.isValid() )
{
return true; // root item: its children are top level items
}
else
{
QgsDataItem* ptr = (QgsDataItem*) parent.internalPointer();
QgsDataItem* ptr = ( QgsDataItem* ) parent.internalPointer();

return ptr->hasChildren();
}

return false;
}

int QgsBrowserModel::columnCount ( const QModelIndex & parent ) const
int QgsBrowserModel::columnCount( const QModelIndex & parent ) const
{
return 1;
}
@@ -152,28 +153,28 @@ QModelIndex QgsBrowserModel::index( int row, int column, const QModelIndex & par
{
//qDebug("index: idx: (valid %d) %d %d", parent.isValid(), parent.row(), parent.column());

if (!parent.isValid())
if ( !parent.isValid() )
{
// this is the root item, parent of the top level items
Q_ASSERT(column == 0 && row >= 0 && row < mRootItems.count());
return createIndex(row,column, mRootItems[row]);
Q_ASSERT( column == 0 && row >= 0 && row < mRootItems.count() );
return createIndex( row, column, mRootItems[row] );
}
else
{
// this is ordinary item: return a valid index if the requested child exists
QgsDataItem* ptr = (QgsDataItem*) parent.internalPointer();
if (ptr->type() == QgsDataItem::Directory || ptr->type() == QgsDataItem::Collection)
QgsDataItem* ptr = ( QgsDataItem* ) parent.internalPointer();
if ( ptr->type() == QgsDataItem::Directory || ptr->type() == QgsDataItem::Collection )
{
// this is a directory: get index of its subdir!
QgsDirectoryItem* di = (QgsDirectoryItem*) ptr;
return createIndex(row, column, di->children().at(row));
QgsDirectoryItem* di = ( QgsDirectoryItem* ) ptr;
return createIndex( row, column, di->children().at( row ) );
}
if (ptr->type() == QgsDataItem::Layer)
if ( ptr->type() == QgsDataItem::Layer )
{
return QModelIndex(); // has no children
}

Q_ASSERT(false && "unknown item in index()");
Q_ASSERT( false && "unknown item in index()" );
}

return QModelIndex(); // if the child does not exist
@@ -196,7 +197,7 @@ QModelIndex QgsBrowserModel::index( QgsDataItem *item )
break;
}
}
QgsDebugMsg( QString ( "row = %1").arg(row) );
QgsDebugMsg( QString( "row = %1" ).arg( row ) );
Q_ASSERT( row >= 0 );
index = createIndex( row, 0, item );

@@ -205,51 +206,51 @@ QModelIndex QgsBrowserModel::index( QgsDataItem *item )

QModelIndex QgsBrowserModel::parent( const QModelIndex & index ) const
{
if (!index.isValid())
if ( !index.isValid() )
return QModelIndex();

// return QModelInde of parent, i.e. where the parent is within its parent :-)

//qDebug("parent of: %d %d", index.row(), index.column());

QgsDataItem* ptr = (QgsDataItem*) index.internalPointer();
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
QgsDataItem* parentItem = ptr->parent();

if (parentItem == NULL)
if ( parentItem == NULL )
{
// parent of our root is invalid index
return QModelIndex();
}

const QVector<QgsDataItem*>& children =
parentItem->parent() ? ((QgsDirectoryItem*)parentItem->parent())->children() : mRootItems;
Q_ASSERT(children.count() > 0);
parentItem->parent() ? (( QgsDirectoryItem* )parentItem->parent() )->children() : mRootItems;
Q_ASSERT( children.count() > 0 );

for (int i = 0; i < children.count(); i++)
for ( int i = 0; i < children.count(); i++ )
{
if (children[i] == parentItem)
return createIndex(i, 0, parentItem);
if ( children[i] == parentItem )
return createIndex( i, 0, parentItem );
}

Q_ASSERT(false && "parent not found!");
Q_ASSERT( false && "parent not found!" );
return QModelIndex();
}

/* Refresh dir path */
void QgsBrowserModel::refresh( QString path, const QModelIndex& theIndex )
{
QStringList paths = path.split('/');
for ( int i = 0; i < rowCount(theIndex); i++ )
QStringList paths = path.split( '/' );
for ( int i = 0; i < rowCount( theIndex ); i++ )
{
QModelIndex idx = index(i, 0, theIndex);
QgsDataItem* ptr = (QgsDataItem*) idx.internalPointer();
QModelIndex idx = index( i, 0, theIndex );
QgsDataItem* ptr = ( QgsDataItem* ) idx.internalPointer();
if ( ptr->path() == path )
{
QgsDebugMsg( "Arrived " + ptr->path() );
ptr->refresh();
return;
}
if ( path.indexOf ( ptr->path() ) == 0 )
if ( path.indexOf( ptr->path() ) == 0 )
{
refresh( path, idx );
break;
@@ -260,13 +261,13 @@ void QgsBrowserModel::refresh( QString path, const QModelIndex& theIndex )
/* Refresh item */
void QgsBrowserModel::refresh( const QModelIndex& theIndex )
{
if ( !theIndex.isValid () ) // root
if ( !theIndex.isValid() ) // root
{
// Nothing to do I believe, mRootItems are always the same
}
else
{
QgsDataItem* ptr = (QgsDataItem*) theIndex.internalPointer();
QgsDataItem* ptr = ( QgsDataItem* ) theIndex.internalPointer();
QgsDebugMsg( "Refresh " + ptr->path() );
ptr->refresh();
}
@@ -277,13 +278,13 @@ void QgsBrowserModel::beginInsertItems( QgsDataItem* parent, int first, int last
QgsDebugMsg( "parent mPath = " + parent->path() );
QModelIndex idx = index( parent );
if ( !idx.isValid() ) return;
QgsDebugMsg( "valid");
QgsDebugMsg( "valid" );
beginInsertRows( idx, first, last );
QgsDebugMsg( "end");
QgsDebugMsg( "end" );
}
void QgsBrowserModel::endInsertItems()
{
QgsDebugMsg( "Entered");
QgsDebugMsg( "Entered" );
endInsertRows();
}
void QgsBrowserModel::beginRemoveItems( QgsDataItem* parent, int first, int last )
@@ -295,17 +296,17 @@ void QgsBrowserModel::beginRemoveItems( QgsDataItem* parent, int first, int last
}
void QgsBrowserModel::endRemoveItems()
{
QgsDebugMsg( "Entered");
QgsDebugMsg( "Entered" );
endRemoveRows();
}
void QgsBrowserModel::connectItem ( QgsDataItem* item )
void QgsBrowserModel::connectItem( QgsDataItem* item )
{
connect ( item, SIGNAL(beginInsertItems ( QgsDataItem*, int, int )),
this, SLOT(beginInsertItems( QgsDataItem*, int, int )) );
connect ( item, SIGNAL(endInsertItems ()),
this, SLOT(endInsertItems()) );
connect ( item, SIGNAL(beginRemoveItems ( QgsDataItem*, int, int )),
this, SLOT(beginRemoveItems( QgsDataItem*, int, int )) );
connect ( item, SIGNAL(endRemoveItems ()),
this, SLOT(endRemoveItems()) );
connect( item, SIGNAL( beginInsertItems( QgsDataItem*, int, int ) ),
this, SLOT( beginInsertItems( QgsDataItem*, int, int ) ) );
connect( item, SIGNAL( endInsertItems() ),
this, SLOT( endInsertItems() ) );
connect( item, SIGNAL( beginRemoveItems( QgsDataItem*, int, int ) ),
this, SLOT( beginRemoveItems( QgsDataItem*, int, int ) ) );
connect( item, SIGNAL( endRemoveItems() ),
this, SLOT( endRemoveItems() ) );
}

0 comments on commit 694c356

Please sign in to comment.
You can’t perform that action at this time.