Skip to content

Commit 063f4de

Browse files
committed
add All Ramps items in tree widget
1 parent 145fca4 commit 063f4de

File tree

3 files changed

+99
-19
lines changed

3 files changed

+99
-19
lines changed

src/core/symbology-ng/qgscptcityarchive.cpp

+70-16
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
4646
: mArchiveName( archiveName ), mBaseDir( baseDir )
4747
{
4848
QgsDebugMsg( "archiveName = " + archiveName + " baseDir = " + baseDir );
49-
// make root items
49+
50+
// make Author items
5051
QgsCptCityDirectoryItem* dirItem = 0;
5152
foreach ( QString path, QDir( mBaseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name ) )
5253
{
@@ -61,21 +62,29 @@ QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
6162
}
6263

6364
// make selection items
64-
QgsCptCitySelectionItem* item = 0;
65+
QgsCptCitySelectionItem* selItem = 0;
6566
QDir seldir( mBaseDir + QDir::separator() + "selections" );
6667
QgsDebugMsg( "populating selection from " + seldir.path() );
6768
foreach ( QString selfile, seldir.entryList( QStringList( "*.xml" ), QDir::Files ) )
6869
{
6970
QgsDebugMsg( "file= " + seldir.path() + "/" + selfile );
70-
item = new QgsCptCitySelectionItem( NULL, QFileInfo( selfile ).baseName(),
71-
seldir.dirName() + QDir::separator() + selfile );
71+
selItem = new QgsCptCitySelectionItem( NULL, QFileInfo( selfile ).baseName(),
72+
seldir.dirName() + QDir::separator() + selfile );
7273
//TODO remove item if there are no children (e.g. esri in qgis-sel)
73-
if ( item->isValid() )
74-
mSelectionItems << item;
74+
if ( selItem->isValid() )
75+
mSelectionItems << selItem;
7576
else
76-
delete item;
77+
delete selItem;
7778
}
7879

80+
// make "All Ramps items" (which will contain all ramps without hierarchy)
81+
QgsCptCityAllRampsItem* allRampsItem;
82+
allRampsItem = new QgsCptCityAllRampsItem( NULL, QObject::tr( "All Ramps" ),
83+
mRootItems );
84+
mRootItems.prepend( allRampsItem );
85+
allRampsItem = new QgsCptCityAllRampsItem( NULL, QObject::tr( "All Ramps" ),
86+
mSelectionItems );
87+
mSelectionItems.prepend( allRampsItem );
7988
}
8089

8190
QgsCptCityArchive::~QgsCptCityArchive( )
@@ -860,7 +869,7 @@ QgsCptCityDirectoryItem::QgsCptCityDirectoryItem( QgsCptCityDataItem* parent,
860869
: QgsCptCityCollectionItem( parent, name, path )
861870
{
862871
mType = Directory;
863-
mValid = QDir( QgsCptCityArchive::defaultBaseDir() ).exists();
872+
mValid = QDir( QgsCptCityArchive::defaultBaseDir() + QDir::separator() + mPath ).exists();
864873
if ( ! mValid )
865874
{
866875
QgsDebugMsg( "created invalid dir item, path = " + QgsCptCityArchive::defaultBaseDir()
@@ -1140,7 +1149,9 @@ QgsCptCitySelectionItem::QgsCptCitySelectionItem( QgsCptCityDataItem* parent,
11401149
: QgsCptCityCollectionItem( parent, name, path )
11411150
{
11421151
mType = Selection;
1143-
parseXML();
1152+
mValid = ! path.isNull();
1153+
if ( mValid )
1154+
parseXML();
11441155
}
11451156

11461157
QgsCptCitySelectionItem::~QgsCptCitySelectionItem()
@@ -1257,6 +1268,38 @@ bool QgsCptCitySelectionItem::equal( const QgsCptCityDataItem *other )
12571268
return ( path() == other->path() );
12581269
}
12591270

1271+
//-----------------------------------------------------------------------
1272+
QgsCptCityAllRampsItem::QgsCptCityAllRampsItem( QgsCptCityDataItem* parent,
1273+
QString name, QVector<QgsCptCityDataItem*> items )
1274+
: QgsCptCityCollectionItem( parent, name, QString() ), mItems( items )
1275+
{
1276+
mType = AllRamps;
1277+
mValid = true;
1278+
// populate();
1279+
}
1280+
1281+
QgsCptCityAllRampsItem::~QgsCptCityAllRampsItem()
1282+
{
1283+
}
1284+
1285+
QVector<QgsCptCityDataItem*> QgsCptCityAllRampsItem::createChildren()
1286+
{
1287+
if ( ! mValid )
1288+
return QVector<QgsCptCityDataItem*>();
1289+
1290+
QVector<QgsCptCityDataItem*> children;
1291+
1292+
// add children ramps of each item
1293+
foreach ( QgsCptCityDataItem* item, mItems )
1294+
{
1295+
QgsCptCityCollectionItem* colItem = dynamic_cast< QgsCptCityCollectionItem* >( item );
1296+
if ( colItem )
1297+
children += colItem->childrenRamps( true );
1298+
}
1299+
1300+
return children;
1301+
}
1302+
12601303
//-----------------------------------------------------------------------
12611304

12621305
QgsCptCityBrowserModel::QgsCptCityBrowserModel( QObject *parent,
@@ -1343,12 +1386,11 @@ QVariant QgsCptCityBrowserModel::data( const QModelIndex &index, int role ) cons
13431386
return item->icon( mIconSize );
13441387
}
13451388
else if ( role == Qt::FontRole &&
1346-
( item->type() == QgsCptCityDataItem::Directory ||
1347-
item->type() == QgsCptCityDataItem::Selection ) )
1389+
( dynamic_cast< QgsCptCityCollectionItem* >( item ) != 0 ) )
13481390
{
13491391
// collectionitems are larger and bold
13501392
QFont font;
1351-
// font.setPointSize( font.pointSize() + 1 );
1393+
font.setPointSize( 11 ); //FIXME why is the font so small?
13521394
font.setBold( true );
13531395
return font;
13541396
}
@@ -1418,7 +1460,11 @@ QModelIndex QgsCptCityBrowserModel::findPath( QString path )
14181460
{
14191461
foundChild = false; // assume that the next child item will not be found
14201462

1421-
for ( int i = 0; i < rowCount( theIndex ); i++ )
1463+
int i = 0;
1464+
// if root skip first item "All Ramps"
1465+
if ( itemPath.isEmpty() )
1466+
i = 1;
1467+
for ( ; i < rowCount( theIndex ); i++ )
14221468
{
14231469
QModelIndex idx = index( i, 0, theIndex );
14241470
QgsCptCityDataItem *item = dataItem( idx );
@@ -1587,9 +1633,17 @@ bool QgsCptCityBrowserModel::canFetchMore( const QModelIndex & parent ) const
15871633
QgsCptCityDataItem* item = dataItem( parent );
15881634
// fetch all items initially so we know which items have children
15891635
// (nicer looking and less confusing)
1590-
if ( item )
1591-
item->populate();
1592-
return ( item && ! item->isPopulated() );
1636+
1637+
if ( ! item )
1638+
return false;
1639+
1640+
// except for "All Ramps" - this is populated when clicked on
1641+
if ( item->type() == QgsCptCityDataItem::AllRamps )
1642+
return false;
1643+
1644+
item->populate();
1645+
1646+
return ( ! item->isPopulated() );
15931647
}
15941648

15951649
void QgsCptCityBrowserModel::fetchMore( const QModelIndex & parent )

src/core/symbology-ng/qgscptcityarchive.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class CORE_EXPORT QgsCptCityDataItem : public QObject
9090
ColorRamp,
9191
Collection,
9292
Directory,
93-
Selection
93+
Selection,
94+
AllRamps
9495
};
9596

9697
QgsCptCityDataItem( QgsCptCityDataItem::Type type, QgsCptCityDataItem* parent,
@@ -277,6 +278,20 @@ class CORE_EXPORT QgsCptCitySelectionItem : public QgsCptCityCollectionItem
277278
QStringList mSelectionsList;
278279
};
279280

281+
/** An "All ramps item", which contains all items in a flat hierarchy */
282+
class CORE_EXPORT QgsCptCityAllRampsItem : public QgsCptCityCollectionItem
283+
{
284+
Q_OBJECT
285+
public:
286+
QgsCptCityAllRampsItem( QgsCptCityDataItem* parent, QString name,
287+
QVector<QgsCptCityDataItem*> items );
288+
~QgsCptCityAllRampsItem();
289+
290+
QVector<QgsCptCityDataItem*> createChildren();
291+
292+
protected:
293+
QVector<QgsCptCityDataItem*> mItems;
294+
};
280295

281296

282297
class CORE_EXPORT QgsCptCityBrowserModel : public QAbstractItemModel

src/gui/symbology-ng/qgscptcitycolorrampv2dialog.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*
161161

162162
tabBar->blockSignals( false );
163163

164-
connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished( int ) ) );
164+
connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished() ) );
165165

166166
// TODO - remove this when basic archive is complete
167167
if ( mArchive->archiveName() == DEFAULT_CPTCITY_ARCHIVE )
@@ -264,6 +264,7 @@ void QgsCptCityColorRampV2Dialog::on_mTreeView_clicked( const QModelIndex &index
264264
QgsCptCityDataItem *item = mModel->dataItem( sourceIndex );
265265
if ( ! item )
266266
return;
267+
QgsDebugMsg( QString( "item %1 clicked" ).arg( item->name() ) );
267268
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
268269
updateTreeView( item );
269270
}
@@ -297,6 +298,14 @@ void QgsCptCityColorRampV2Dialog::updateTreeView( QgsCptCityDataItem *item, bool
297298
clearCopyingInfo( );
298299
updateListWidget( item );
299300
}
301+
else if ( item->type() == QgsCptCityDataItem::AllRamps )
302+
{
303+
lblSchemePath->setText( "" );
304+
// lblCollectionName->setText( item->path() );
305+
clearCopyingInfo( );
306+
updateListWidget( item );
307+
lblCollectionInfo->setText( tr( "All Ramps (%1)" ).arg( item->rowCount() ) );
308+
}
300309
else
301310
{
302311
QgsDebugMsg( QString( "item %1 has invalid type %2" ).arg( item->path() ).arg(( int )item->type() ) );
@@ -565,9 +574,11 @@ bool QgsCptCityColorRampV2Dialog::updateRamp()
565574
mListWidget->clear();
566575
mListRamps.clear();
567576
cboVariantName->clear();
568-
updatePreview( true );
569577
clearCopyingInfo( );
578+
lblCollectionInfo->clear();
579+
570580
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
581+
updatePreview( true );
571582

572583
QgsDebugMsg( "schemeName= " + mRamp->schemeName() );
573584
if ( mRamp->schemeName() == "" )

0 commit comments

Comments
 (0)