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

George Staikos staikos at kde.org
Mon May 28 21:55:41 CEST 2007


SVN commit 669220 by staikos:

separate the tab widget out of the main window and make the naming more
consistent


 M  +1 -0      CMakeLists.txt  
 M  +7 -37     mainwindow.cpp  
 M  +4 -8      mainwindow.h  
 A             tabwidget.cpp   [License: GPL (v2+)]
 A             tabwidget.h   [License: GPL (v2+)]
 M  +2 -1      viewcommand.cpp  
 M  +2 -1      viewitem.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/CMakeLists.txt #669219:669220
@@ -8,6 +8,7 @@
    labelitem.cpp
    lineitem.cpp
    mainwindow.cpp
+   tabwidget.cpp
    vectormodel.cpp
    vectortablemodel.cpp
    viewcommand.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #669219:669220
@@ -15,27 +15,23 @@
 #include "ellipseitem.h"
 #include "labelitem.h"
 #include "lineitem.h"
+#include "tabwidget.h"
 #include "view.h"
 
 #include <QtGui>
 
-
-
 // Temporaries
-#include <QTableView>
 #include "vectortablemodel.h"
 
 namespace Kst {
 
 MainWindow::MainWindow() {
-
-  _tabWidget = new QTabWidget(this);
+  _tabWidget = new TabWidget(this);
   _undoGroup = new QUndoGroup(this);
 
-  connect(_tabWidget, SIGNAL(currentChanged(int)),
-          this, SLOT(currentPlotChanged()));
+  connect(_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentViewChanged()));
 
-  createPlotView();
+  _tabWidget->createView();
 
   setCentralWidget(_tabWidget);
 
@@ -57,43 +53,17 @@
 }
 
 
-QTabWidget *MainWindow::tabWidget() const {
+TabWidget *MainWindow::tabWidget() const {
   return _tabWidget;
 }
 
 
-View *MainWindow::currentPlotView() const {
-  return qobject_cast<View*>(_tabWidget->currentWidget());
-}
 
-
-View *MainWindow::createPlotView() {
-  View *plotView = new View;
-  connect(plotView, SIGNAL(destroyed(QObject*)),
-          this, SLOT(plotViewDestroyed(QObject*)));
-  _undoGroup->addStack(plotView->undoStack());
-  _undoGroup->setActiveStack(plotView->undoStack());
-
-  QString label = plotView->objectName().isEmpty() ?
-                  QString("Plot %1").arg(QString::number(_tabWidget->count())) :
-                  plotView->objectName();
-
-  _tabWidget->addTab(plotView, label);
-  return plotView;
+void MainWindow::currentViewChanged() {
+  _undoGroup->setActiveStack(_tabWidget->currentView()->undoStack());
 }
 
 
-void MainWindow::currentPlotChanged() {
-  _undoGroup->setActiveStack(currentPlotView()->undoStack());
-}
-
-
-void MainWindow::plotViewDestroyed(QObject *object) {
-  View *plotView = qobject_cast<View*>(object);
-  _tabWidget->removeTab(_tabWidget->indexOf(plotView));
-}
-
-
 void MainWindow::aboutToQuit() {
   writeSettings();
 }
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #669219:669220
@@ -16,11 +16,11 @@
 
 class QMenu;
 class QAction;
-class QTabWidget;
 class QUndoGroup;
 
 namespace Kst {
 class View;
+class TabWidget;
 
 class MainWindow : public QMainWindow
 {
@@ -30,16 +30,12 @@
   virtual ~MainWindow();
 
   QUndoGroup *undoGroup() const;
-  QTabWidget *tabWidget() const;
-  View *currentPlotView() const;
+  TabWidget *tabWidget() const;
 
-  View *createPlotView();
-
 private Q_SLOTS:
   void aboutToQuit();
   void about();
-  void currentPlotChanged();
-  void plotViewDestroyed(QObject *object);
+  void currentViewChanged();
 
   void createLabel();
   void createBox();
@@ -58,7 +54,7 @@
   void writeSettings();
 
 private:
-  QTabWidget *_tabWidget;
+  TabWidget *_tabWidget;
   QUndoGroup *_undoGroup;
 
   QMenu *_fileMenu;
--- branches/work/kst/portto4/kst/src/libkstapp/viewcommand.cpp #669219:669220
@@ -11,6 +11,7 @@
 
 #include "viewcommand.h"
 #include "kstapplication.h"
+#include "tabwidget.h"
 #include "view.h"
 
 #include <QDebug>
@@ -18,7 +19,7 @@
 
 namespace Kst {
 ViewCommand::ViewCommand(const QString &text, bool addToStack, QUndoCommand *parent)
-    : QUndoCommand(text, parent), _view(kstApp->mainWindow()->currentPlotView()) {
+    : QUndoCommand(text, parent), _view(kstApp->mainWindow()->tabWidget()->currentView()) {
   if (addToStack)
     _view->undoStack()->push(this);
 }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #669219:669220
@@ -11,6 +11,7 @@
 
 #include "viewitem.h"
 #include "kstapplication.h"
+#include "tabwidget.h"
 
 #include <QDebug>
 #include <QGraphicsItem>
@@ -48,7 +49,7 @@
 
 
 ViewItemCommand::ViewItemCommand(const QString &text, bool addToStack, QUndoCommand *parent)
-    : QUndoCommand(text, parent), _item(kstApp->mainWindow()->currentPlotView()->currentPlotItem()) {
+    : QUndoCommand(text, parent), _item(kstApp->mainWindow()->tabWidget()->currentView()->currentPlotItem()) {
   if (addToStack)
     _item->parentView()->undoStack()->push(this);
 }


More information about the Kst mailing list