Skip to content

Commit 3f8a467

Browse files
committedAug 24, 2012
bugfixes to archive management
1 parent ebdd1ad commit 3f8a467

File tree

4 files changed

+86
-33
lines changed

4 files changed

+86
-33
lines changed
 
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<selection cadence="low">
3+
<name short="test">Test</name>
4+
<synopsis>
5+
Test test
6+
</synopsis>
7+
<description>
8+
Test test
9+
</description>
10+
<seealsocollects>
11+
<collect dir="cb">Cynthia Brewer</collect>
12+
<collect dir="grass">Grass></collect>
13+
</seealsocollects>
14+
<gradients>
15+
<gradient file="BrBG_11" dir="cb/div"/>
16+
<gradient file="Blues_06" dir="cb/seq"/>
17+
<gradient file="etopo2" dir="grass"/>
18+
<gradient file="terrain" dir="grass"/>
19+
</gradients>
20+
</selection>

‎src/core/symbology-ng/qgscptcityarchive.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ QMap< QString, QMap< QString, QString > > QgsCptCityArchive::mCopyingInfoMap;
4545
QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
4646
: mArchiveName( archiveName ), mBaseDir( baseDir )
4747
{
48+
QgsDebugMsg( "archiveName = " + archiveName + " baseDir = " + baseDir );
4849
// make root items
4950
QgsCptCityDirectoryItem* dirItem = 0;
5051
foreach ( QString path, QDir( mBaseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name ) )
5152
{
53+
if ( path == "selections" )
54+
continue;
5255
QgsDebugMsg( "path= " + path );
5356
dirItem = new QgsCptCityDirectoryItem( NULL, QFileInfo( path ).baseName(), path );
5457
if ( dirItem->isValid() )
@@ -76,7 +79,14 @@ QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
7679
}
7780

7881
QgsCptCityArchive::~QgsCptCityArchive( )
79-
{}
82+
{
83+
foreach ( QgsCptCityDataItem* item, mRootItems )
84+
delete item;
85+
foreach ( QgsCptCityDataItem* item, mSelectionItems )
86+
delete item;
87+
mRootItems.clear();
88+
mSelectionItems.clear();
89+
}
8090

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

417+
void QgsCptCityArchive::initDefaultArchive()
418+
{
419+
QSettings settings;
420+
// use CptCity/baseDir setting if set, default is user dir
421+
QString baseDir = settings.value( "CptCity/baseDir",
422+
QgsApplication::pkgDataPath() + "/resources" ).toString();
423+
// sub-dir defaults to
424+
QString defArchiveName = settings.value( "CptCity/archiveName", DEFAULT_CPTCITY_ARCHIVE ).toString();
425+
426+
if ( ! mArchiveRegistry.contains( defArchiveName ) )
427+
initArchive( defArchiveName, baseDir + QDir::separator() + defArchiveName );
428+
}
429+
407430
void QgsCptCityArchive::initArchives( bool loadAll )
408431
{
409432
QMap< QString, QString > archivesMap;
@@ -1135,19 +1158,20 @@ void QgsCptCityBrowserModel::addRootItems( )
11351158
{
11361159
mRootItems = mArchive->selectionItems();
11371160
}
1161+
QgsDebugMsg( QString( "added %1 root items" ).arg( mRootItems.size() ) );
11381162
}
11391163

11401164
void QgsCptCityBrowserModel::removeRootItems()
11411165
{
1142-
foreach ( QgsCptCityDataItem* item, mRootItems )
1143-
{
1144-
delete item;
1145-
}
1166+
// don't remove root items, they belong to the QgsCptCityArchive
1167+
// foreach ( QgsCptCityDataItem* item, mRootItems )
1168+
// {
1169+
// delete item;
1170+
// }
11461171

11471172
mRootItems.clear();
11481173
}
11491174

1150-
11511175
Qt::ItemFlags QgsCptCityBrowserModel::flags( const QModelIndex & index ) const
11521176
{
11531177
if ( !index.isValid() )

‎src/core/symbology-ng/qgscptcityarchive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class CORE_EXPORT QgsCptCityArchive
5656
QString archiveName() const { return mArchiveName; }
5757
static void initArchives( bool loadAll = false );
5858
static void initArchive( QString archiveName, QString archiveBaseDir );
59+
static void initDefaultArchive();
5960
static void clearArchives();
6061
static QgsCptCityArchive* defaultArchive();
61-
static QString defaultArchiveName();
6262
static QMap< QString, QgsCptCityArchive* > archiveRegistry();
6363

6464
// items

‎src/gui/symbology-ng/qgscptcitycolorrampv2dialog.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,20 @@ bool QgsCptCityColorRampV2Dialog::eventFilter( QObject *obj, QEvent *event )
334334
void QgsCptCityColorRampV2Dialog::showEvent( QShowEvent * e )
335335
{
336336
// setup archives
337-
if ( QgsCptCityArchive::archiveRegistry().isEmpty() )
338-
{
339-
QgsCptCityArchive::initArchives( true );
340-
}
337+
// if ( QgsCptCityArchive::archiveRegistry().isEmpty() )
338+
// {
339+
// QgsCptCityArchive::initArchives( true );
340+
// }
341+
// mArchive = QgsCptCityArchive::defaultArchive();
342+
// // if empty archive, try loading again - this may happen after installing new package
343+
// if ( ! mArchive || mArchive->isEmpty() )
344+
// {
345+
// QgsCptCityArchive::initArchives( true );
346+
// mArchive = QgsCptCityArchive::defaultArchive();
347+
// }
348+
349+
QgsCptCityArchive::initDefaultArchive();
341350
mArchive = QgsCptCityArchive::defaultArchive();
342-
// if empty archive, try loading again - this may happen after installing new package
343-
if ( ! mArchive || mArchive->isEmpty() )
344-
{
345-
QgsCptCityArchive::initArchives( true );
346-
mArchive = QgsCptCityArchive::defaultArchive();
347-
}
348351

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

409-
// populate tree widget - if item not found in selections archive, look for in authors
410-
// try to apply selection to view
411-
QModelIndex modelIndex = mModel->findPath( mRamp->schemeName() );
412-
if ( modelIndex == QModelIndex() )
412+
// look for item, if not found in selections archive, look for in authors
413+
// TODO fix when ramp has a variant
414+
if ( mRamp->schemeName() != "" )
413415
{
414-
modelIndex = mAuthorsModel->findPath( mRamp->schemeName() );
416+
QModelIndex modelIndex = mModel->findPath( mRamp->schemeName() );
417+
if ( modelIndex == QModelIndex() )
418+
{
419+
modelIndex = mAuthorsModel->findPath( mRamp->schemeName() );
420+
if ( modelIndex != QModelIndex() )
421+
{
422+
tabBar->setCurrentIndex( 1 );
423+
mModel = mAuthorsModel;
424+
mBrowserView->setModel( mModel );
425+
}
426+
}
415427
if ( modelIndex != QModelIndex() )
416428
{
417-
tabBar->setCurrentIndex( 1 );
418-
mModel = mAuthorsModel;
419-
mBrowserView->setModel( mModel );
429+
lblSchemeName->setText( mRamp->schemeName() );
430+
mBrowserView->setCurrentIndex( modelIndex );
431+
mBrowserView->scrollTo( modelIndex, QAbstractItemView::PositionAtCenter );
432+
populateVariants( mRamp->variantName() );
433+
// updatePreview();
420434
}
421435
}
422-
if ( modelIndex != QModelIndex() )
423-
{
424-
lblSchemeName->setText( mRamp->schemeName() );
425-
mBrowserView->setCurrentIndex( modelIndex );
426-
mBrowserView->scrollTo( modelIndex, QAbstractItemView::PositionAtCenter );
427-
populateVariants( mRamp->variantName() );
428-
// updatePreview();
429-
}
436+
430437
tabBar->blockSignals( false );
438+
439+
// TODO - remove this when basic archive is complete
431440
if ( mArchive->archiveName() == DEFAULT_CPTCITY_ARCHIVE )
432441
tabBar->setCurrentIndex( 1 );
433442

0 commit comments

Comments
 (0)
Please sign in to comment.