[Kst] branches/work/kst/portto4/kst/src/libkstapp
Peter Kümmel
syntheticpp at yahoo.com
Wed Apr 28 18:40:42 CEST 2010
SVN commit 1120211 by kuemmel:
Show plot after loading file.
Cleanup TabWidget code.
CCBUG: 234390
M +9 -20 document.cpp
M +3 -6 mainwindow.cpp
M +23 -11 tabwidget.cpp
M +4 -1 tabwidget.h
M +25 -14 view.cpp
M +3 -0 view.h
--- branches/work/kst/portto4/kst/src/libkstapp/document.cpp #1120210:1120211
@@ -169,13 +169,7 @@
// .kst files that contained only data and basically "merge" that data into
// the current session
- // Clear out old tabs. We will be left with one to delete later.
- int i=_win->tabWidget()->count();
- while (i>0) {
- _win->tabWidget()->closeCurrentView();
- i--;
- }
- View *currentView = 0;
+ View *loadedView = 0;
QRectF currentSceneRect;
QXmlStreamReader xml;
@@ -230,13 +224,11 @@
case Graphics:
{
if (n == "view") {
- currentView = _win->tabWidget()->createView();
+ loadedView = new Kst::View(0);
+ _win->tabWidget()->clear();
+ _win->tabWidget()->addView(loadedView);
QXmlStreamAttributes attrs = xml.attributes();
- QStringRef nm = attrs.value("name");
- if (!nm.isNull()) {
- int idx = _win->tabWidget()->indexOf(currentView);
- _win->tabWidget()->setTabText(idx, nm.toString());
- }
+ loadedView->setObjectName(attrs.value("name").toString());
qreal width = 1.0, height = 1.0;
QStringRef string = attrs.value("width");
if (!string.isNull()) {
@@ -255,9 +247,9 @@
break;
case View:
{
- ViewItem *i = GraphicsFactory::parse(xml, objectStore(), currentView);
+ ViewItem *i = GraphicsFactory::parse(xml, objectStore(), loadedView);
if (i) {
- currentView->scene()->addItem(i);
+ loadedView->scene()->addItem(i);
}
}
break;
@@ -283,8 +275,8 @@
}
break;
} else if (n == "view") {
- if (currentView->sceneRect() != currentSceneRect) {
- currentView->forceChildResize(currentSceneRect, currentView->sceneRect());
+ if (loadedView->sceneRect() != currentSceneRect) {
+ loadedView->forceChildResize(currentSceneRect, loadedView->sceneRect());
}
state = Graphics;
} else if (n == "data") {
@@ -320,9 +312,6 @@
_tnum = max_tnum+1;
_mnum = max_mnum+1;
- // delete the empty tab
- _win->tabWidget()->setCurrentIndex(0);
- _win->tabWidget()->closeCurrentView();
UpdateManager::self()->doUpdates(true);
setChanged(false);
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #1120210:1120211
@@ -225,14 +225,9 @@
return;
}
+ tabWidget()->clear();
tabWidget()->createView();
-
- int i=tabWidget()->count()-1;
- while (i>=0) {
- tabWidget()->closeCurrentView();
- i--;
}
-}
void MainWindow::open() {
if (_doc->isChanged() && !promptSave()) {
@@ -439,6 +434,8 @@
}
void MainWindow::currentViewChanged() {
+ if(!_tabWidget->currentView())
+ return;
_undoGroup->setActiveStack(_tabWidget->currentView()->undoStack());
_layoutModeAct->setChecked(_tabWidget->currentView()->viewMode() == View::Layout);
}
--- branches/work/kst/portto4/kst/src/libkstapp/tabwidget.cpp #1120210:1120211
@@ -35,7 +35,12 @@
View *TabWidget::createView() {
View *view = new View;
- connect(view, SIGNAL(destroyed(QObject*)), this, SLOT(viewDestroyed(QObject*)));
+ addView(view);
+ return view;
+}
+
+
+void TabWidget::addView(View* view) {
MainWindow *parent = qobject_cast<MainWindow*>(this->parent());
if (parent) {
parent->undoGroup()->addStack(view->undoStack());
@@ -48,7 +53,6 @@
addTab(view, label);
setCurrentWidget(view);
- return view;
}
@@ -66,22 +70,30 @@
}
-void TabWidget::viewDestroyed(QObject *object) {
- View *view = qobject_cast<View*>(object);
+void TabWidget::deleteView(View* view) {
+ MainWindow *parent = qobject_cast<MainWindow*>(this->parent());
+ if (parent) {
+ parent->undoGroup()->removeStack(view->undoStack());
+ }
removeTab(indexOf(view));
+ delete view;
}
+void TabWidget::clear() {
+ QList<View*> tabs = views();
+ foreach(View* view, tabs) {
+ deleteView(view);
+ }
+ _cnt = 0;
+}
+
+
void TabWidget::closeCurrentView() {
- if (count() == 1) {
- _cnt = 0;
+ deleteView(currentView());
+ if (count() == 0)
createView();
- setCurrentIndex(0);
}
- QWidget* tab = currentView();
- removeTab(indexOf(tab));
- delete tab;
-}
void TabWidget::renameCurrentView() {
--- branches/work/kst/portto4/kst/src/libkstapp/tabwidget.h #1120210:1120211
@@ -28,6 +28,10 @@
View *currentView() const;
QList<View*> views() const;
+ // pass tab name as objectName
+ void addView(View*);
+ void deleteView(View* view);
+ void clear();
public Q_SLOTS:
View *createView();
@@ -35,7 +39,6 @@
void closeCurrentView();
private Q_SLOTS:
- void viewDestroyed(QObject *object);
void contextMenu(const QPoint&);
private:
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #1120210:1120211
@@ -40,20 +40,31 @@
namespace Kst {
-View::View()
- : QGraphicsView(kstApp->mainWindow()),
- _viewMode(Data),
- _mouseMode(Default),
- _layoutBoxItem(0),
- _gridSpacing(QSizeF(20,20)),
- _showGrid(false),
- _snapToGridHorizontal(false),
- _snapToGridVertical(false),
- _plotBordersDirty(false),
- _printing(false),
- _dataMode(false),
- _fontRescale(1.0),
- _childMaximized(false) {
+View::View() : QGraphicsView(kstApp->mainWindow())
+{
+ init();
+}
+
+View::View(QWidget* parent) : QGraphicsView(parent)
+{
+ init();
+}
+
+
+void View::init()
+{
+ _viewMode = Data;
+ _mouseMode = Default;
+ _layoutBoxItem = 0;
+ _gridSpacing = QSizeF(20,20);
+ _showGrid = false;
+ _snapToGridHorizontal = false;
+ _snapToGridVertical = false;
+ _plotBordersDirty = false;
+ _printing = false;
+ _dataMode = false;
+ _fontRescale = 1.0;
+ _childMaximized = false;
_undoStack = new QUndoStack(this);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
--- branches/work/kst/portto4/kst/src/libkstapp/view.h #1120210:1120211
@@ -42,8 +42,11 @@
Q_DECLARE_FLAGS(CreationEvents, CreationEvent)
View();
+ View(QWidget* parent);
virtual ~View();
+ void init();
+
virtual void save(QXmlStreamWriter &xml);
bool useOpenGL() const;
More information about the Kst
mailing list