[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/runtime/nepomuk/services/backupsync/gui
From:       Vishesh Handa <handa.vish () gmail ! com>
Date:       2010-11-24 15:17:03
Message-ID: 20101124151703.8FF54AC8A2 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1200296 by vhanda:

Huge IdentifierModel cleanup


 M  +32 -12    guitest/testwidget.cpp  
 M  +1 -0      guitest/testwidget.h  
 M  +30 -77    identifiermodel.cpp  
 M  +0 -10     identifiermodel.h  
 M  +0 -11     identifiermodeltree.cpp  
 M  +0 -1      identifiermodeltree.h  


--- trunk/KDE/kdebase/runtime/nepomuk/services/backupsync/gui/guitest/testwidget.cpp \
#1200295:1200296 @@ -22,6 +22,10 @@
 
 #include <QtGui/QBoxLayout>
 
+#include <Nepomuk/Vocabulary/NFO>
+#include <Nepomuk/Vocabulary/NIE>
+#include <Soprano/Vocabulary/RDF>
+
 #include <KDebug>
 
 TestWidget::TestWidget(QWidget* parent, Qt::WindowFlags f)
@@ -46,23 +50,39 @@
 {
 }
 
+void TestWidget::notIdentified(const QString& resUri, const QString& nieUrl)
+{
+    Soprano::Statement st( Soprano::Node( QUrl(resUri) ),
+                           Soprano::Node( Nepomuk::Vocabulary::NIE::url() ),
+                           Soprano::Node( QUrl(nieUrl) ) );
+    QList<Soprano::Statement> stList;
+    stList.append( st );
+    if( nieUrl.endsWith('/') ) {
+        stList << Soprano::Statement( QUrl(resUri), \
Soprano::Vocabulary::RDF::type(), Nepomuk::Vocabulary::NFO::Folder() ); +    }
+    else {
+        stList << Soprano::Statement( QUrl(resUri), \
Soprano::Vocabulary::RDF::type(), Nepomuk::Vocabulary::NFO::FileDataObject() ); +    \
}  
+    m_model->notIdentified( 0, stList );
+}
+
 void TestWidget::slotOnButtonClick()
 {
 
-    m_model->debug_notIdentified( "nepomuk:/res/1", "/home/vishesh/" );
-    m_model->debug_notIdentified( "nepomuk:/res/2", "/home/vishesh/file1" );
-    m_model->debug_notIdentified( "nepomuk:/res/3", "/home/vishesh/folder/" );
-    m_model->debug_notIdentified( "nepomuk:/res/4", "/home/vishesh/file2" );
-    m_model->debug_notIdentified( "nepomuk:/res/5", "/home/vishesh/folder/fol-file1" \
                );
-    m_model->debug_notIdentified( "nepomuk:/res/6", "/home/vishesh/folder/fol-file2" \
); +    notIdentified( "nepomuk:/res/1", "/home/vishesh/" );
+    notIdentified( "nepomuk:/res/2", "/home/vishesh/file1" );
+    notIdentified( "nepomuk:/res/3", "/home/vishesh/folder/" );
+    notIdentified( "nepomuk:/res/4", "/home/vishesh/file2" );
+    notIdentified( "nepomuk:/res/5", "/home/vishesh/folder/fol-file1" );
+    notIdentified( "nepomuk:/res/6", "/home/vishesh/folder/fol-file2" );
 
-    m_model->debug_notIdentified( "nepomuk:/res/-1", "/home/user/" );
-    m_model->debug_notIdentified( "nepomuk:/res/-2", "/home/user/file1" );
-    m_model->debug_notIdentified( "nepomuk:/res/-3", "/home/user/folder/" );
-    m_model->debug_notIdentified( "nepomuk:/res/-4", "/home/user/file2" );
-    m_model->debug_notIdentified( "nepomuk:/res/-5", "/home/user/folder/fol-file1" \
                );
-    m_model->debug_notIdentified( "nepomuk:/res/-6", "/home/user/folder/fol-file2" \
); +    notIdentified( "nepomuk:/res/-1", "/home/user/" );
+    notIdentified( "nepomuk:/res/-2", "/home/user/file1" );
+    notIdentified( "nepomuk:/res/-3", "/home/user/folder/" );
+    notIdentified( "nepomuk:/res/-4", "/home/user/file2" );
+    notIdentified( "nepomuk:/res/-5", "/home/user/folder/fol-file1" );
+    notIdentified( "nepomuk:/res/-6", "/home/user/folder/fol-file2" );
 
     m_model->identified(0, "nepomuk:/res/-5", "nepomuk:/res/-5-identified" );
 }
--- trunk/KDE/kdebase/runtime/nepomuk/services/backupsync/gui/guitest/testwidget.h \
#1200295:1200296 @@ -38,6 +38,7 @@
     Nepomuk::IdentifierModel * m_model;
     MergeConflictDelegate * m_delegate;
 
+    void notIdentified( const QString& resUri, const QString& nieUrl );
 private slots:
     void slotOnButtonClick();
 };
--- trunk/KDE/kdebase/runtime/nepomuk/services/backupsync/gui/identifiermodel.cpp \
#1200295:1200296 @@ -51,15 +51,11 @@
 
 QVariant Nepomuk::IdentifierModel::data(const QModelIndex& index, int role) const
 {
-    IdentifierModelTreeItem *item;// = static_cast<IdentifierModelTreeItem *> \
                (m_tree->root());
-    if( index.isValid() ) {
-        item = static_cast<IdentifierModelTreeItem *>(index.internalPointer());
-        kDebug() << "Called for : "<< item->url();
-    }
-    else {
-        kDebug() << "Index is not VALID!!! What to do?";
-    }
+    if( !index.isValid() )
+        return QVariant();
 
+    IdentifierModelTreeItem *item = static_cast<IdentifierModelTreeItem \
*>(index.internalPointer()); +
     switch(role) {
         case LabelRole:
         case Qt::DisplayRole:
@@ -100,22 +96,12 @@
         return 0;
     
     if( !parent.isValid() ) {
-        //kDebug() << "NOT VALID - Probably root";
-        int r = m_tree->isEmpty() ? 0 : m_tree->rootNodes().size();
-        //kDebug() << r;
-        return r;
+        return ( m_tree->isEmpty() ? 0 : m_tree->rootNodes().size() );
     }
     
-    IdentifierModelTreeItem * parentItem;
+    IdentifierModelTreeItem * parentItem = static_cast<IdentifierModelTreeItem \
*>(parent.internalPointer());  
-    //kDebug() << "Else cluase !!";
-    parentItem = static_cast<IdentifierModelTreeItem *>(parent.internalPointer());
-    //if( parentItem == m_tree->root() )
-    //    kDebug() << "ROOT!! :-D";
-
-    int r = parentItem->numChildren();
-    //kDebug() << r;
-    return r;
+    return parentItem->numChildren();
 }
 
 
@@ -124,64 +110,57 @@
     if( !index.isValid() )
         return QModelIndex();
 
-    IdentifierModelTreeItem *childItem = static_cast<IdentifierModelTreeItem*>( \
                index.internalPointer() );
-    if( childItem->parent() == 0 )
+    IdentifierModelTreeItem *child = static_cast<IdentifierModelTreeItem*>( \
index.internalPointer() ); +    IdentifierModelTreeItem *parent = static_cast< \
IdentifierModelTreeItem*>( child->parent() ); +    if( parent == 0 )
         return QModelIndex();
 
-    FileSystemTreeItem *parentItem = static_cast< IdentifierModelTreeItem*>( \
                childItem->parent() );
-    if( !parentItem )
+    if( parent->parent() == 0 ) {
+        // Its parent is one of the root nodes
+        int rootPos = m_tree->rootNodes().indexOf( parent );
+        if( rootPos == -1 )
         return QModelIndex();
 
-    int rootPos = m_tree->rootNodes().indexOf( parentItem );
-    if( rootPos != -1 ) {
-        return createIndex( rootPos, 0, parentItem );
+        return createIndex( rootPos, 0, parent );
     }
     
-    //if( parentItem == m_tree->root() )
-    //    return createIndex( 0, 0, m_tree->root() );
-    
-    return createIndex( parentItem->parentRowNum(), 0, parentItem );
+    return createIndex( parent->parentRowNum(), 0, parent );
 }
 
 
 QModelIndex Nepomuk::IdentifierModel::index(int row, int column, const QModelIndex& \
parent) const  {
-    if( column > 0 ) {
-        kDebug() << "Column greater than zero!!";
+    if( column > 0 )
         return QModelIndex();
-    }
     
     if (!parent.isValid()) {
-//         IdentifierModelTreeItem * root = dynamic_cast<IdentifierModelTreeItem*>( \
                );
-
+        // One of the root nodes
         if( m_tree->isEmpty() || row >= m_tree->rootNodes().size() )
             return QModelIndex();
 
-        kDebug() << "------------- Returning index for row column : " << row << " " \
                << column;
-        kDebug() << "-------- " << m_tree->rootNodes().at( row );
         return createIndex( row, column, m_tree->rootNodes().at( row ) );
     }
-    else {
-        IdentifierModelTreeItem *parentItem = static_cast<IdentifierModelTreeItem \
                *>( parent.internalPointer() );
-        FileSystemTreeItem *childItem = static_cast<IdentifierModelTreeItem *>( \
                parentItem->child(row) );
-        kDebug() << "creating index from parent : "<< parentItem->url() << "for \
                child : "<< childItem->url();
-        return createIndex(row, column, childItem);
-    }
 
+    IdentifierModelTreeItem *parentItem = static_cast<IdentifierModelTreeItem *>( \
parent.internalPointer() ); +    if( row >= parentItem->numChildren() )
     return QModelIndex();
+    
+    return createIndex(row, column, parentItem->child( row ) );
 }
 
 
 void Nepomuk::IdentifierModel::identified(int id, const QString& oldUri, const \
QString& newUri)  {
     Q_UNUSED( id );
-    kDebug() << oldUri << " -----> " << newUri;
+    //kDebug() << oldUri << " -----> " << newUri;
     
     emit layoutAboutToBeChanged();
  
     IdentifierModelTreeItem* item = m_tree->findByUri( QUrl(oldUri) );
-    if( item )
+    if( item ) {
+        kDebug() << item->url() << " -----> " << newUri;
         item->setIdentified( QUrl(newUri) );
+    }
     
     emit layoutChanged();
 }
@@ -192,51 +171,25 @@
     if( sts.isEmpty() )
         return;
     
-    kDebug();
+    //kDebug();
     emit layoutAboutToBeChanged();
 
     // If already exists - Remove it
     QUrl resUri = sts.first().subject().uri();
     IdentifierModelTreeItem* it = m_tree->findByUri( resUri );
     if( it ) {
-        m_tree->FileSystemTree::remove( it );
+        kDebug() << "ALREADY EXISTS!! REMOVING!!";
+        m_tree->remove( it );
     }
 
     // Insert into the tree
     IdentifierModelTreeItem* item = IdentifierModelTreeItem::fromStatementList( sts \
                );
-    item->setUnidentified();;
+    item->setUnidentified();
     m_tree->add( item );
 
     emit layoutChanged();
 }
 
-
-void Nepomuk::IdentifierModel::debug_identified(int id, const QString& nieUrl)
-{/*
-    Q_UNUSED( id )
-    emit layoutAboutToBeChanged();
-    m_tree->remove( nieUrl );
-    emit layoutChanged();*/
-}
-
-
-void Nepomuk::IdentifierModel::debug_notIdentified( const QString& resUri, const \
                QString& nieUrl )
-{
-    Soprano::Statement st( Soprano::Node( QUrl(resUri) ),
-                           Soprano::Node( Nepomuk::Vocabulary::NIE::url() ),
-                           Soprano::Node( QUrl(nieUrl) ) );
-    QList<Soprano::Statement> stList;
-    stList.append( st );
-    if( nieUrl.endsWith('/') ) {
-        stList << Soprano::Statement( QUrl(resUri), \
                Soprano::Vocabulary::RDF::type(), Nepomuk::Vocabulary::NFO::Folder() \
                );
-    }
-    else {
-        stList << Soprano::Statement( QUrl(resUri), \
                Soprano::Vocabulary::RDF::type(), \
                Nepomuk::Vocabulary::NFO::FileDataObject() );
-    }
-    
-    notIdentified( 0, stList );
-}
-
 Qt::ItemFlags Nepomuk::IdentifierModel::flags(const QModelIndex& index) const
 {
     Q_UNUSED( index );
--- trunk/KDE/kdebase/runtime/nepomuk/services/backupsync/gui/identifiermodel.h \
#1200295:1200296 @@ -56,17 +56,7 @@
         virtual QModelIndex index(int row, int column, const QModelIndex& parent = \
QModelIndex()) const;  virtual Qt::ItemFlags flags(const QModelIndex& index) const;
         
-    public Q_SLOTS:
-        /**
-         * Used for debugging & testing.
-         */
-        void debug_notIdentified( const QString& resUri, const QString& nieUrl );
 
-        /**
-         * Used for debugging & testing.
-         */
-        void debug_identified( int id, const QString & nieUrl );
-
     public Q_SLOTS:
 //         void resolveResource( const QUrl& resource, const QUrl& identified );
 //         void discardResource( const QUrl& resource );
--- trunk/KDE/kdebase/runtime/nepomuk/services/backupsync/gui/identifiermodeltree.cpp \
#1200295:1200296 @@ -96,9 +96,7 @@
             // FIXME: This may not be totally accurate
             Types::Class oldClass( type );
             Types::Class newClass( objectUri );
-            kDebug() << "Object uri : " << objectUri;
             if( newClass.isSubClassOf( oldClass ) ) {
-                kDebug() << "SETTING";
                 type = objectUri;
             }
         }
@@ -156,15 +154,6 @@
     FileSystemTree::add(item);
 }
 
-
-void Nepomuk::IdentifierModelTree::remove(const QString& resUri)
-{
-    QHash<QUrl, QString>::const_iterator it = m_resUrlHash.constFind( resUri );
-    if( it != m_resUrlHash.constEnd() ) {
-        FileSystemTree::remove( it.value() );
-    }
-}
-
 Nepomuk::IdentifierModelTreeItem* Nepomuk::IdentifierModelTree::findByUri(const \
QUrl& uri)  {
     QHash<QUrl, QString>::const_iterator it = m_resUrlHash.constFind( uri );
--- trunk/KDE/kdebase/runtime/nepomuk/services/backupsync/gui/identifiermodeltree.h \
#1200295:1200296 @@ -69,7 +69,6 @@
         virtual void add(IdentifierModelTreeItem* item);
         IdentifierModelTreeItem* findByUri( const QUrl& uri );
         
-        virtual void remove(const QString& resUri);
     private:
         QHash<QUrl, QString> m_resUrlHash;
         friend class IdentifierModelTreeItem;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic