Skip to content
Permalink
Browse files

bugfixes to archive management

  • Loading branch information
etiennesky committed Aug 24, 2012
1 parent ebdd1ad commit 3f8a4679825c8f1a2ebf93733a39ed499d6468cc
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<selection cadence="low">
<name short="test">Test</name>
<synopsis>
Test test
</synopsis>
<description>
Test test
</description>
<seealsocollects>
<collect dir="cb">Cynthia Brewer</collect>
<collect dir="grass">Grass></collect>
</seealsocollects>
<gradients>
<gradient file="BrBG_11" dir="cb/div"/>
<gradient file="Blues_06" dir="cb/seq"/>
<gradient file="etopo2" dir="grass"/>
<gradient file="terrain" dir="grass"/>
</gradients>
</selection>
@@ -45,10 +45,13 @@ QMap< QString, QMap< QString, QString > > QgsCptCityArchive::mCopyingInfoMap;
QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
: mArchiveName( archiveName ), mBaseDir( baseDir )
{
QgsDebugMsg( "archiveName = " + archiveName + " baseDir = " + baseDir );
// make root items
QgsCptCityDirectoryItem* dirItem = 0;
foreach ( QString path, QDir( mBaseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name ) )
{
if ( path == "selections" )
continue;
QgsDebugMsg( "path= " + path );
dirItem = new QgsCptCityDirectoryItem( NULL, QFileInfo( path ).baseName(), path );
if ( dirItem->isValid() )
@@ -76,7 +79,14 @@ QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
}

QgsCptCityArchive::~QgsCptCityArchive( )
{}
{
foreach ( QgsCptCityDataItem* item, mRootItems )
delete item;
foreach ( QgsCptCityDataItem* item, mSelectionItems )
delete item;
mRootItems.clear();
mSelectionItems.clear();
}

QString QgsCptCityArchive::baseDir() const
{
@@ -404,6 +414,19 @@ void QgsCptCityArchive::initArchive( QString archiveName, QString archiveBaseDir
mArchiveRegistry[ archiveName ] = archive;
}

void QgsCptCityArchive::initDefaultArchive()
{
QSettings settings;
// use CptCity/baseDir setting if set, default is user dir
QString baseDir = settings.value( "CptCity/baseDir",
QgsApplication::pkgDataPath() + "/resources" ).toString();
// sub-dir defaults to
QString defArchiveName = settings.value( "CptCity/archiveName", DEFAULT_CPTCITY_ARCHIVE ).toString();

if ( ! mArchiveRegistry.contains( defArchiveName ) )
initArchive( defArchiveName, baseDir + QDir::separator() + defArchiveName );
}

void QgsCptCityArchive::initArchives( bool loadAll )
{
QMap< QString, QString > archivesMap;
@@ -1135,19 +1158,20 @@ void QgsCptCityBrowserModel::addRootItems( )
{
mRootItems = mArchive->selectionItems();
}
QgsDebugMsg( QString( "added %1 root items" ).arg( mRootItems.size() ) );
}

void QgsCptCityBrowserModel::removeRootItems()
{
foreach ( QgsCptCityDataItem* item, mRootItems )
{
delete item;
}
// don't remove root items, they belong to the QgsCptCityArchive
// foreach ( QgsCptCityDataItem* item, mRootItems )
// {
// delete item;
// }

mRootItems.clear();
}


Qt::ItemFlags QgsCptCityBrowserModel::flags( const QModelIndex & index ) const
{
if ( !index.isValid() )
@@ -56,9 +56,9 @@ class CORE_EXPORT QgsCptCityArchive
QString archiveName() const { return mArchiveName; }
static void initArchives( bool loadAll = false );
static void initArchive( QString archiveName, QString archiveBaseDir );
static void initDefaultArchive();
static void clearArchives();
static QgsCptCityArchive* defaultArchive();
static QString defaultArchiveName();
static QMap< QString, QgsCptCityArchive* > archiveRegistry();

// items
@@ -334,17 +334,20 @@ bool QgsCptCityColorRampV2Dialog::eventFilter( QObject *obj, QEvent *event )
void QgsCptCityColorRampV2Dialog::showEvent( QShowEvent * e )
{
// setup archives
if ( QgsCptCityArchive::archiveRegistry().isEmpty() )
{
QgsCptCityArchive::initArchives( true );
}
// if ( QgsCptCityArchive::archiveRegistry().isEmpty() )
// {
// QgsCptCityArchive::initArchives( true );
// }
// mArchive = QgsCptCityArchive::defaultArchive();
// // if empty archive, try loading again - this may happen after installing new package
// if ( ! mArchive || mArchive->isEmpty() )
// {
// QgsCptCityArchive::initArchives( true );
// mArchive = QgsCptCityArchive::defaultArchive();
// }

QgsCptCityArchive::initDefaultArchive();
mArchive = QgsCptCityArchive::defaultArchive();
// if empty archive, try loading again - this may happen after installing new package
if ( ! mArchive || mArchive->isEmpty() )
{
QgsCptCityArchive::initArchives( true );
mArchive = QgsCptCityArchive::defaultArchive();
}

// show information on how to install cpt-city files if none are found
if ( ! mArchive || mArchive->isEmpty() )
@@ -406,28 +409,34 @@ void QgsCptCityColorRampV2Dialog::showEvent( QShowEvent * e )
cboVariantName->setIconSize( QSize( 100, 15 ) );
lblPreview->installEventFilter( this ); // mouse click on preview label shows svg render

// populate tree widget - if item not found in selections archive, look for in authors
// try to apply selection to view
QModelIndex modelIndex = mModel->findPath( mRamp->schemeName() );
if ( modelIndex == QModelIndex() )
// look for item, if not found in selections archive, look for in authors
// TODO fix when ramp has a variant
if ( mRamp->schemeName() != "" )
{
modelIndex = mAuthorsModel->findPath( mRamp->schemeName() );
QModelIndex modelIndex = mModel->findPath( mRamp->schemeName() );
if ( modelIndex == QModelIndex() )
{
modelIndex = mAuthorsModel->findPath( mRamp->schemeName() );
if ( modelIndex != QModelIndex() )
{
tabBar->setCurrentIndex( 1 );
mModel = mAuthorsModel;
mBrowserView->setModel( mModel );
}
}
if ( modelIndex != QModelIndex() )
{
tabBar->setCurrentIndex( 1 );
mModel = mAuthorsModel;
mBrowserView->setModel( mModel );
lblSchemeName->setText( mRamp->schemeName() );
mBrowserView->setCurrentIndex( modelIndex );
mBrowserView->scrollTo( modelIndex, QAbstractItemView::PositionAtCenter );
populateVariants( mRamp->variantName() );
// updatePreview();
}
}
if ( modelIndex != QModelIndex() )
{
lblSchemeName->setText( mRamp->schemeName() );
mBrowserView->setCurrentIndex( modelIndex );
mBrowserView->scrollTo( modelIndex, QAbstractItemView::PositionAtCenter );
populateVariants( mRamp->variantName() );
// updatePreview();
}

tabBar->blockSignals( false );

// TODO - remove this when basic archive is complete
if ( mArchive->archiveName() == DEFAULT_CPTCITY_ARCHIVE )
tabBar->setCurrentIndex( 1 );

0 comments on commit 3f8a467

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