Made UnifiedResourcesProvider actually pull ResourceItem's from its
merged databases into its own database (and also keep them up to date). Furthermore added code to properly destroy merged databases and their providers in desctrutor.
This commit is contained in:
@@ -48,7 +48,7 @@ public:
|
||||
void load( const QString & _file );
|
||||
void save( const QString & _file );
|
||||
|
||||
ResourcesProvider * provider( void )
|
||||
inline ResourcesProvider * provider( void )
|
||||
{
|
||||
return m_provider;
|
||||
}
|
||||
@@ -58,6 +58,11 @@ public:
|
||||
return m_items;
|
||||
}
|
||||
|
||||
inline ItemList & items( void )
|
||||
{
|
||||
return m_items;
|
||||
}
|
||||
|
||||
inline ResourcesTreeItem * topLevelNode( void )
|
||||
{
|
||||
return &m_topLevelNode;
|
||||
|
||||
@@ -34,9 +34,7 @@ class UnifiedResourcesProvider : public ResourcesProvider
|
||||
Q_OBJECT
|
||||
public:
|
||||
UnifiedResourcesProvider();
|
||||
virtual ~UnifiedResourcesProvider()
|
||||
{
|
||||
}
|
||||
virtual ~UnifiedResourcesProvider();
|
||||
|
||||
void addDatabase( ResourcesDB * _db );
|
||||
|
||||
@@ -46,6 +44,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void updateDatabase( void );
|
||||
|
||||
virtual int dataSize( const ResourcesItem * _item ) const
|
||||
{
|
||||
if( _item->provider() != this )
|
||||
@@ -54,6 +53,7 @@ public:
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual QByteArray fetchData( const ResourcesItem * _item,
|
||||
int _maxSize = -1 ) const
|
||||
{
|
||||
@@ -64,14 +64,19 @@ public:
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
virtual bool cacheDatabase( void ) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private slots:
|
||||
void remergeItems( void );
|
||||
|
||||
|
||||
private:
|
||||
QList<ResourcesDB *> m_mergedDatabases;
|
||||
|
||||
|
||||
signals:
|
||||
void itemsChanged( void );
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <QtCore/QDir>
|
||||
|
||||
#include "unified_resources_provider.h"
|
||||
#include "resources_db.h"
|
||||
|
||||
@@ -38,6 +36,19 @@ UnifiedResourcesProvider::UnifiedResourcesProvider() :
|
||||
|
||||
|
||||
|
||||
UnifiedResourcesProvider::~UnifiedResourcesProvider()
|
||||
{
|
||||
database()->items().clear();
|
||||
|
||||
foreach( ResourcesDB * db, m_mergedDatabases )
|
||||
{
|
||||
delete db->provider();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void UnifiedResourcesProvider::addDatabase( ResourcesDB * _db )
|
||||
{
|
||||
ResourcesTreeItem * childRoot = _db->topLevelNode()->getChild( 0 );
|
||||
@@ -45,7 +56,9 @@ void UnifiedResourcesProvider::addDatabase( ResourcesDB * _db )
|
||||
{
|
||||
m_mergedDatabases << _db;
|
||||
connect( _db, SIGNAL( itemsChanged() ),
|
||||
this, SIGNAL( itemsChanged() ) );
|
||||
database(), SIGNAL( itemsChanged() ) );
|
||||
connect( _db, SIGNAL( itemsChanged() ),
|
||||
this, SLOT( remergeItems() ) );
|
||||
|
||||
childRoot->setParent( database()->topLevelNode() );
|
||||
database()->topLevelNode()->addChild( childRoot );
|
||||
@@ -66,6 +79,54 @@ void UnifiedResourcesProvider::updateDatabase( void )
|
||||
|
||||
|
||||
|
||||
void UnifiedResourcesProvider::remergeItems( void )
|
||||
{
|
||||
typedef QHash<const ResourcesItem *,
|
||||
const ResourcesItem *> PointerHashMap;
|
||||
PointerHashMap itemsSeen;
|
||||
|
||||
ResourcesDB::ItemList & items = database()->items();
|
||||
for( ResourcesDB::ItemList::Iterator it = items.begin();
|
||||
it != items.end(); ++it )
|
||||
{
|
||||
itemsSeen[*it] = *it;
|
||||
}
|
||||
|
||||
foreach( ResourcesDB * db, m_mergedDatabases )
|
||||
{
|
||||
for( ResourcesDB::ItemList::ConstIterator it =
|
||||
db->items().begin();
|
||||
it != db->items().end(); ++it )
|
||||
{
|
||||
const QString & h = (*it)->hash();
|
||||
if( !items.contains( h ) )
|
||||
{
|
||||
items[(*it)->hash()] = *it;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemsSeen[*it] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( ResourcesDB::ItemList::Iterator it = items.begin();
|
||||
it != items.end(); )
|
||||
{
|
||||
if( itemsSeen[*it] == *it )
|
||||
{
|
||||
it = items.erase( it );
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "moc_unified_resources_provider.cxx"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user