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

List:       kde-commits
Subject:    koffice/kexi/widget
From:       Adam Pigg <adam () piggz ! co ! uk>
Date:       2010-08-11 20:54:25
Message-ID: 20100811205425.87F0AAC84E () svn ! kde ! org
[Download RAW message or body]

SVN commit 1162324 by piggz:

Implement item removing from the model and navigator
staniek: please find bugs ;)
CCMAIL: staniek@kde.org

 M  +37 -2     KexiProjectModel.cpp  
 M  +5 -0      KexiProjectModel.h  
 M  +45 -3     KexiProjectModelItem.cpp  
 M  +5 -1      KexiProjectModelItem.h  
 M  +1 -72     KexiProjectNavigator.cpp  


--- trunk/koffice/kexi/widget/KexiProjectModel.cpp #1162323:1162324
@@ -113,8 +113,6 @@
     }
 }
 
-
-
 QVariant KexiProjectModel::data(const QModelIndex& index, int role) const
 {
     KexiProjectModelItem *item = \
static_cast<KexiProjectModelItem*>(index.internalPointer()); @@ -264,3 +262,40 @@
 {
     return new KexiProjectModelItem(info, item, p);;
 }
+
+void KexiProjectModel::removeItem(const KexiPart::Item& item)
+{
+    QModelIndex idx;
+    KexiProjectModelItem *mitm = modelItemFromItem(item);
+    KexiProjectModelItem *parent =0;
+    
+    if (mitm) {
+        kDebug() << "Got model item from item";
+        parent = mitm->parent();
+    } else {
+        kDebug() << "Unable to get model item from item";
+    }
+    
+    if (parent) {
+        idx = indexFromItem(parent);
+        beginRemoveRows(idx, 0,0);
+        parent->removeChild(item);
+        endRemoveRows();
+    }
+}
+
+QModelIndex KexiProjectModel::indexFromItem(KexiProjectModelItem* item) const
+{
+    if (item && item->parent()) {
+        int row = item->row();
+        //dbgUI << "Node index in image: " << index << ", parent has " << rowCount + \
1 << " rows, inverted index becomes " << row; +        return createIndex(row, 0, \
(void*)item); +    } else {
+            return QModelIndex();
+    }
+}
+
+KexiProjectModelItem* KexiProjectModel::modelItemFromItem(const KexiPart::Item& \
item) +{
+    return m_rootItem->modelItemFromItem(item);
+}
--- trunk/koffice/kexi/widget/KexiProjectModel.h #1162323:1162324
@@ -33,6 +33,7 @@
     
     void setProject(KexiProject* prj, const QString& itemsPartClass, QString* \
partManagerErrorMessages);  QString itemsPartClass() const;
+    void removeItem(const KexiPart::Item &item);
     
     virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) \
                const;
     virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
@@ -43,9 +44,13 @@
     virtual bool setData(const QModelIndex& index, const QVariant& value, int role = \
Qt::EditRole);  virtual Qt::ItemFlags flags(const QModelIndex& index) const;
     
+    
 private:
     void clear();
 
+    QModelIndex indexFromItem(KexiProjectModelItem *item) const;
+    KexiProjectModelItem *modelItemFromItem(const KexiPart::Item &item);
+    
     //!Part class to display
     QString m_itemsPartClass;
 
--- trunk/koffice/kexi/widget/KexiProjectModelItem.cpp #1162323:1162324
@@ -126,11 +126,12 @@
     }
 }
 
-int KexiProjectModelItem::row() const
+int KexiProjectModelItem::row()
 {
      if (m_parentItem)
-         return m_parentItem->m_childItems.indexOf(const_cast<KexiProjectModelItem*>(this));
                
-
+     {
+         return m_parentItem->m_childItems.indexOf(this);
+     }
      return 0;
 }
 
@@ -147,3 +148,44 @@
         return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
     }
 }
+
+void KexiProjectModelItem::removeChild(const KexiPart::Item& item)
+{
+    KexiProjectModelItem *to_delete = 0;
+    int i = 0;
+    if (!m_item) {
+        foreach(KexiProjectModelItem *child, m_childItems) {
+            ++i;
+            if (!to_delete) {
+                if (child->m_item) {
+                    if (child->m_item && child->m_item->identifier() == \
item.identifier()) { +                        to_delete = m_childItems.takeAt(i-1);
+                    }
+                }
+            }
+        }
+    }
+    if (to_delete) {
+        delete to_delete;
+    }
+}
+
+KexiProjectModelItem* KexiProjectModelItem::modelItemFromItem(const KexiPart::Item& \
item) const +{
+    KexiProjectModelItem* itm = 0;
+    
+    if (!m_item) {
+        foreach(KexiProjectModelItem *child, m_childItems) {
+            if (!itm) {
+                if (child->m_item) {
+                    if (child->m_item && child->m_item->identifier() == \
item.identifier()) { +                        itm = child;
+                    }
+                } else {
+                        itm = child->modelItemFromItem(item);
+                }
+            }
+        }
+    }
+    return itm;
+}
--- trunk/koffice/kexi/widget/KexiProjectModelItem.h #1162323:1162324
@@ -70,8 +70,9 @@
     int childCount() const;
     int columnCount() const;
     QVariant data(int column) const;
-    int row() const;
+    int row();
     KexiProjectModelItem *parent();
+    void removeChild(const KexiPart::Item &item);
 
     QIcon icon();
 
@@ -79,6 +80,9 @@
     Qt::ItemFlags flags();
     
     void debugPrint();
+
+    KexiProjectModelItem* modelItemFromItem(const KexiPart::Item &item) const;
+
  private:
     QList<KexiProjectModelItem*> m_childItems;
     KexiProjectModelItem *m_parentItem;
--- trunk/koffice/kexi/widget/KexiProjectNavigator.cpp #1162323:1162324
@@ -234,28 +234,9 @@
 
 void KexiProjectNavigator::slotRemoveItem(const KexiPart::Item &item)
 {
-#if 0
-    KexiProjectModelItem *to_remove = m_normalItems.take(item.identifier());
-    if (!to_remove)
-        return;
-
-    KexiProjectModelItem *it = \
                static_cast<KexiProjectModelItem*>(m_list->currentIndex().internalPointer());
                
-
-    Q3ListViewItem *new_item_to_select = 0;
-    if (it == to_remove) {//compute item to select if current one will be removed
-        new_item_to_select = it->itemBelow();//nearest item to select
-        if (!new_item_to_select || new_item_to_select->parent() != it->parent()) {
-            new_item_to_select = it->itemAbove();
+    m_model->removeItem(item);
         }
-    }
-    delete to_remove;
 
-    if (new_item_to_select)
-        m_list->setSelected(new_item_to_select, true);
-#endif
-    
-}
-
 void KexiProjectNavigator::contextMenuEvent(QContextMenuEvent* event)
 {
     if (!m_list->currentIndex().isValid() || !(m_features & ContextMenus))
@@ -383,58 +364,6 @@
     emit selectionChanged(it ? it->partItem() : 0);
 }
 
-#if 0
-bool KexiProjectNavigator::eventFilter(QObject *o, QEvent * e)
-{
-
-    /* if (o==m_list && e->type()==QEvent::Resize) {
-        kDebug() << "resize!";
-      }*/
-    if (o == m_list->renameLineEdit()) {
-        if (e->type() == QEvent::Hide)
-            itemRenameDone();
-    } else if (e->type() == QEvent::KeyPress) {
-        QKeyEvent *ke = static_cast<QKeyEvent*>(e);
-        if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) {
-            if (0 == (ke->modifiers() & (Qt::ShiftButton | Qt::ControlButton | \
                Qt::AltButton))) {
-                Q3ListViewItem *it = m_list->selectedItem();
-                if (it)
-                    slotExecuteItem(it);
-            } else if (Qt::ControlButton == (ke->modifiers() & (Qt::ShiftButton | \
                Qt::ControlButton | Qt::AltButton))) {
-                slotDesignObject();
-            }
-        }
-    } else if (e->type() == QEvent::ShortcutOverride) {
-        QKeyEvent *ke = static_cast<QKeyEvent*>(e);
-        //override delete action
-        if (ke->key() == Qt::Key_Delete && ke->modifiers() == Qt::NoButton) {
-            slotRemove();
-            ke->accept();
-            return true;
-        }
-        //override rename action
-        if (ke->key() == Qt::Key_F2 && ke->modifiers() == Qt::NoButton) {
-            slotRename();
-            ke->accept();
-            return true;
-        }
-        /*  else if (ke->key()==Qt::Key_Enter || ke->key()==Qt::Key_Return) {
-              if (ke->modifiers()==Qt::ControlModifier) {
-                slotDesignObject();
-              }
-              else if (ke->modifiers()==0 && !m_list->renameLineEdit()->isVisible()) \
                {
-                Q3ListViewItem *it = m_list->selectedItem();
-                if (it)
-                  slotExecuteItem(it);
-              }
-              ke->accept();
-              return true;
-            }*/
-    }
-    return false;
-}
-#endif
-
 void KexiProjectNavigator::slotRemove()
 {
     if (!m_deleteAction || !m_deleteAction->isEnabled() || !(m_features & Writable))


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

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