@@ -46,7 +46,8 @@ QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
46
46
: mArchiveName( archiveName ), mBaseDir( baseDir )
47
47
{
48
48
QgsDebugMsg ( " archiveName = " + archiveName + " baseDir = " + baseDir );
49
- // make root items
49
+
50
+ // make Author items
50
51
QgsCptCityDirectoryItem* dirItem = 0 ;
51
52
foreach ( QString path, QDir ( mBaseDir ).entryList ( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name ) )
52
53
{
@@ -61,21 +62,29 @@ QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
61
62
}
62
63
63
64
// make selection items
64
- QgsCptCitySelectionItem* item = 0 ;
65
+ QgsCptCitySelectionItem* selItem = 0 ;
65
66
QDir seldir ( mBaseDir + QDir::separator () + " selections" );
66
67
QgsDebugMsg ( " populating selection from " + seldir.path () );
67
68
foreach ( QString selfile, seldir.entryList ( QStringList ( " *.xml" ), QDir::Files ) )
68
69
{
69
70
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 );
72
73
// 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 ;
75
76
else
76
- delete item ;
77
+ delete selItem ;
77
78
}
78
79
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 );
79
88
}
80
89
81
90
QgsCptCityArchive::~QgsCptCityArchive ( )
@@ -860,7 +869,7 @@ QgsCptCityDirectoryItem::QgsCptCityDirectoryItem( QgsCptCityDataItem* parent,
860
869
: QgsCptCityCollectionItem( parent, name, path )
861
870
{
862
871
mType = Directory;
863
- mValid = QDir ( QgsCptCityArchive::defaultBaseDir () ).exists ();
872
+ mValid = QDir ( QgsCptCityArchive::defaultBaseDir () + QDir::separator () + mPath ).exists ();
864
873
if ( ! mValid )
865
874
{
866
875
QgsDebugMsg ( " created invalid dir item, path = " + QgsCptCityArchive::defaultBaseDir ()
@@ -1140,7 +1149,9 @@ QgsCptCitySelectionItem::QgsCptCitySelectionItem( QgsCptCityDataItem* parent,
1140
1149
: QgsCptCityCollectionItem( parent, name, path )
1141
1150
{
1142
1151
mType = Selection;
1143
- parseXML ();
1152
+ mValid = ! path.isNull ();
1153
+ if ( mValid )
1154
+ parseXML ();
1144
1155
}
1145
1156
1146
1157
QgsCptCitySelectionItem::~QgsCptCitySelectionItem ()
@@ -1257,6 +1268,38 @@ bool QgsCptCitySelectionItem::equal( const QgsCptCityDataItem *other )
1257
1268
return ( path () == other->path () );
1258
1269
}
1259
1270
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
+
1260
1303
// -----------------------------------------------------------------------
1261
1304
1262
1305
QgsCptCityBrowserModel::QgsCptCityBrowserModel ( QObject *parent,
@@ -1343,12 +1386,11 @@ QVariant QgsCptCityBrowserModel::data( const QModelIndex &index, int role ) cons
1343
1386
return item->icon ( mIconSize );
1344
1387
}
1345
1388
else if ( role == Qt::FontRole &&
1346
- ( item->type () == QgsCptCityDataItem::Directory ||
1347
- item->type () == QgsCptCityDataItem::Selection ) )
1389
+ ( dynamic_cast < QgsCptCityCollectionItem* >( item ) != 0 ) )
1348
1390
{
1349
1391
// collectionitems are larger and bold
1350
1392
QFont font;
1351
- // font.setPointSize( font.pointSize() + 1 );
1393
+ font.setPointSize ( 11 ); // FIXME why is the font so small?
1352
1394
font.setBold ( true );
1353
1395
return font;
1354
1396
}
@@ -1418,7 +1460,11 @@ QModelIndex QgsCptCityBrowserModel::findPath( QString path )
1418
1460
{
1419
1461
foundChild = false ; // assume that the next child item will not be found
1420
1462
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++ )
1422
1468
{
1423
1469
QModelIndex idx = index ( i, 0 , theIndex );
1424
1470
QgsCptCityDataItem *item = dataItem ( idx );
@@ -1587,9 +1633,17 @@ bool QgsCptCityBrowserModel::canFetchMore( const QModelIndex & parent ) const
1587
1633
QgsCptCityDataItem* item = dataItem ( parent );
1588
1634
// fetch all items initially so we know which items have children
1589
1635
// (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 () );
1593
1647
}
1594
1648
1595
1649
void QgsCptCityBrowserModel::fetchMore ( const QModelIndex & parent )
0 commit comments