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

Mike Fenton mike at staikos.net
Tue Nov 13 21:30:36 CET 2007


SVN commit 736280 by fenton:

Add force reload of DataManager to reload data on open.
Add context menu support to DataManager.


 M  +31 -0     datamanager.cpp  
 M  +5 -0      datamanager.h  
 M  +1 -1      datawizard.cpp  
 M  +4 -0      mainwindow.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/datamanager.cpp #736279:736280
@@ -18,8 +18,12 @@
 #include "document.h"
 #include "sessionmodel.h"
 
+#include "objectstore.h"
+#include "dataobject.h"
+
 #include <QHeaderView>
 #include <QToolBar>
+#include <QMenu>
 
 namespace Kst {
 
@@ -29,7 +33,12 @@
   setupUi(this);
   _session->header()->setResizeMode(QHeaderView::ResizeToContents);
   _session->setModel(doc->session());
+  _session->setContextMenuPolicy(Qt::CustomContextMenu);
+  connect(_session, SIGNAL(customContextMenuRequested(const QPoint &)),
+          this, SLOT(showContextMenu(const QPoint &)));
 
+  _contextMenu = new QMenu(this);
+
   _objects->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
   _objects->setStyleSheet("background-color: white;");
 
@@ -106,6 +115,28 @@
 DataManager::~DataManager() {
 }
 
+
+void DataManager::showContextMenu(const QPoint &position) {
+    QList<QAction *> actions;
+    if (_session->indexAt(position).isValid()) {
+      DataObjectPtr p = _doc->objectStore()->getObjects<DataObject>().at(_session->indexAt(position).row());
+      if (p) {
+        QAction *action = new QAction(p->tag().displayString(), this);
+        actions.append(action);
+
+        action = new DataButtonAction(tr("Edit"));
+        connect(action, SIGNAL(triggered()), this, SLOT(showEditDialog()));
+        actions.append(action);
+
+        action = new DataButtonAction(tr("Delete"));
+        connect(action, SIGNAL(triggered()), this, SLOT(deleteObject()));
+        actions.append(action);
+      }
+    }
+    if (actions.count() > 0)
+       QMenu::exec(actions, _session->mapToGlobal(position));
 }
 
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/datamanager.h #736279:736280
@@ -31,6 +31,9 @@
     DataManager(QWidget *parent, Document *doc);
     virtual ~DataManager();
 
+  public Q_SLOTS:
+    void showContextMenu(const QPoint &);
+
   private:
     Document *_doc;
 
@@ -38,6 +41,8 @@
     QToolBar *_dataObjects;
     QToolBar *_fits;
     QToolBar *_filters;
+
+    QMenu *_contextMenu;
 };
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/datawizard.cpp #736279:736280
@@ -372,7 +372,7 @@
   connect(_applyFilters, SIGNAL(toggled(bool)), this, SLOT(applyFilter(bool)));
   connect(_xAxisCreateFromField, SIGNAL(toggled(bool)), this, SLOT(optionsUpdated()));
   connect(_xVector, SIGNAL(currentIndexChanged(int)), this, SLOT(optionsUpdated()));
-  connect(_xVectorExisting, SIGNAL(selectionChanged()), this, SLOT(optionsUpdated()));
+  connect(_xVectorExisting, SIGNAL(selectionChanged(QString)), this, SLOT(optionsUpdated()));
 
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #736279:736280
@@ -687,6 +687,10 @@
 
 
 void MainWindow::showDataManager() {
+  //FIXME  Remove this force re-create of the DataManager when the session model is being reset.
+  delete _dataManager;
+  _dataManager = 0;
+
   if (!_dataManager) {
     _dataManager = new DataManager(this, _doc);
   }


More information about the Kst mailing list