[Kst] branches/work/kst/portto4/kst/src/libkstapp

Nicolas Brisset nicolas.brisset at eurocopter.com
Thu Oct 7 10:28:05 CEST 2010


SVN commit 1183366 by brisset:

Add the delete key as keybord shortcut to quickly delete objects from the data
manager.

BUG: 252875


 M  +11 -1     datamanager.cpp  
 M  +1 -1      datamanager.h  
 M  +3 -0      datamanager.ui  


--- branches/work/kst/portto4/kst/src/libkstapp/datamanager.cpp #1183365:1183366
@@ -57,6 +57,10 @@
   connect(_session, SIGNAL(doubleClicked(const QModelIndex &)),
           this, SLOT(showEditDialog(QModelIndex)));
 
+  // Simple keyboard shortcut for fast object deletion
+  _deleteShortcut = new QShortcut(Qt::Key_Delete, this);
+  connect(_deleteShortcut, SIGNAL(activated()), this, SLOT(deleteObject()));
+
   _contextMenu = new QMenu(this);
 
   connect(_purge, SIGNAL(clicked()), this, SLOT(purge()));
@@ -160,6 +164,7 @@
           }
         }
 
+        // Also add delete action in the menu
         action = new QAction(tr("Delete"), this);
         connect(action, SIGNAL(triggered()), this, SLOT(deleteObject()));
         actions.append(action);
@@ -337,6 +342,9 @@
 
 
 void DataManager::deleteObject() {
+  SessionModel *model = static_cast<SessionModel*>(_session->model());
+  int row = _session->selectionModel()->selectedIndexes()[0].row(); // Single selection mode => only one selected index
+  _currentObject = model->objectList()->at(row);
   if (RelationPtr relation = kst_cast<Relation>(_currentObject)) {
     Data::self()->removeCurveFromPlots(relation);
     _doc->objectStore()->removeObject(relation);
@@ -347,10 +355,12 @@
   }
   _currentObject = 0;
   _doc->session()->triggerReset();
+  // Now select the next item
+  _session->selectionModel()->select(model->index(row,0), QItemSelectionModel::Select);
+  // Cleanup and return
   _doc->objectStore()->cleanUpDataSourceList();
 }
 
-
 void DataManager::addToPlot(QAction* action) {
   PlotItem* plotItem = static_cast<PlotItem*>(qVariantValue<PlotItemInterface*>(action->data()));
   RelationPtr relation = kst_cast<Relation>(_currentObject);
--- branches/work/kst/portto4/kst/src/libkstapp/datamanager.h #1183365:1183366
@@ -73,7 +73,7 @@
     QToolBar *_filters;
 
     ObjectPtr _currentObject;
-
+    QShortcut *_deleteShortcut;
     QMenu *_contextMenu;
 };
 
--- branches/work/kst/portto4/kst/src/libkstapp/datamanager.ui #1183365:1183366
@@ -32,6 +32,9 @@
         <verstretch>0</verstretch>
        </sizepolicy>
       </property>
+      <property name="alternatingRowColors">
+       <bool>true</bool>
+      </property>
      </widget>
     </widget>
    </item>


More information about the Kst mailing list