[Kst] branches/work/kst/portto4/kst/src
Matthew D Truch
matt at truch.net
Wed Jun 2 17:50:27 CEST 2010
Sweet!
On Wed, Jun 02, 2010 at 05:37:50PM +0200, Barth Netterfield wrote:
> SVN commit 1133829 by netterfield:
>
> Purge option added to the data manager.
>
>
>
> M +4 -0 libkst/object.h
> M +18 -0 libkst/objectstore.cpp
> M +8 -0 libkst/objectstore.h
> M +7 -0 libkst/primitive.cpp
> M +1 -0 libkst/primitive.h
> M +103 -0 libkstapp/datamanager.cpp
> M +3 -0 libkstapp/datamanager.h
> M +33 -6 libkstapp/datamanager.ui
> M +0 -1 libkstapp/plotitem.h
> M +0 -1 libkstapp/plotitemmanager.cpp
> M +10 -0 libkstapp/sessionmodel.cpp
> M +2 -0 libkstapp/view.cpp
> M +3 -0 libkstapp/viewitem.cpp
> M +22 -0 libkstmath/relation.h
>
>
> --- branches/work/kst/portto4/kst/src/libkst/object.h #1133828:1133829
> @@ -71,6 +71,8 @@
>
> virtual void internalUpdate() = 0;
>
> + virtual bool used() const {return _used;}
> + void setUsed(bool used_in) {_used = used_in;}
>
> protected:
> Object();
> @@ -84,6 +86,8 @@
>
> qint64 _serial;
> qint64 _serialOfLastChange;
> + private:
> + bool _used;
> };
>
>
> --- branches/work/kst/portto4/kst/src/libkst/objectstore.cpp #1133828:1133829
> @@ -237,5 +237,23 @@
> return _list;
> }
>
> +void ObjectStore::clearUsedFlags() {
> + foreach (ObjectPtr p, _list) {
> + p->setUsed(false);
> }
> +}
> +
> +bool ObjectStore::deleteUnsetUsedFlags() {
> + QList<ObjectPtr> list = _list;
> + bool some_deleted = false;
> + foreach (ObjectPtr p, list) {
> + if (!p->used()) {
> + removeObject(p);
> + some_deleted = true;
> + }
> + }
> + return some_deleted;
> +}
> +
> +}
> // vim: ts=2 sw=2 et
> --- branches/work/kst/portto4/kst/src/libkst/objectstore.h #1133828:1133829
> @@ -70,6 +70,14 @@
> /** locking */
> KstRWLock& lock() const { return _lock; }
>
> + /** clear the 'used' flag on all objects in list */
> + void clearUsedFlags();
> +
> + /** delete everything that doesn't have the used flag set.
> + * Note: the caller is responsible to make sure that the
> + * used flags are set properly. It is not done here! */
> + bool deleteUnsetUsedFlags();
> +
> private:
> Q_DISABLE_COPY(ObjectStore)
>
> --- branches/work/kst/portto4/kst/src/libkst/primitive.cpp #1133828:1133829
> @@ -85,6 +85,13 @@
> return QString("Base Class Size String");
> }
>
> +bool Primitive::used() const {
> + if (_provider) {
> + return true;
> + } else {
> + return Object::used();
> }
> +}
> +}
>
> // vim: et sw=2 ts=2
> --- branches/work/kst/portto4/kst/src/libkst/primitive.h #1133828:1133829
> @@ -46,6 +46,7 @@
> virtual QString propertyString() const;
> virtual QString sizeString() const;
>
> + virtual bool used() const;
> protected:
> Primitive(ObjectStore *store, Object* provider = 0L);
>
> --- branches/work/kst/portto4/kst/src/libkstapp/datamanager.cpp #1133828:1133829
> @@ -46,6 +46,7 @@
> _session->header()->setResizeMode(QHeaderView::ResizeToContents);
> _session->setModel(doc->session());
> _session->setContextMenuPolicy(Qt::CustomContextMenu);
> + _session->setUniformRowHeights(true);
> connect(_session, SIGNAL(customContextMenuRequested(const QPoint &)),
> this, SLOT(showContextMenu(const QPoint &)));
> connect(_session, SIGNAL(doubleClicked(const QModelIndex &)),
> @@ -145,6 +146,8 @@
> connect(action, SIGNAL(triggered(QString&)), this, SLOT(showPluginDialog(QString&)));
> _filters->addAction(action);
> }
> +
> + connect(_purge, SIGNAL(clicked()), this, SLOT(purge()));
> }
>
>
> @@ -466,6 +469,106 @@
> }
> }
>
> +void DataManager::setUsedFlags() {
> + _doc->objectStore()->clearUsedFlags();
> +
> + // for each relation used in an unhidden plot mark 'used' - O(N)
> + QList<PlotItem*> plotlist = ViewItem::getItems<PlotItem>();
> + foreach (PlotItem *plot, plotlist) {
> + if (plot->isVisible()) {
> + foreach (PlotRenderItem *renderer, plot->renderItems()) {
> + foreach (RelationPtr relation, renderer->relationList()) {
> + relation->setUsed(true);
> }
> + }
> + }
> + }
>
> + // TODO: for each primitive used in an unhidden label mark 'used' - O(N)
> +
> + // for each primitive used by a relation mark 'used' - O(N)
> + ObjectList<Relation> relationList = _doc->objectStore()->getObjects<Relation>();
> + foreach (RelationPtr object, relationList) {
> + object->readLock();
> + //set used all input and output primitives
> + foreach (VectorPtr v, object->inputVectors()) {
> + v->setUsed(true);
> + if (v->provider()) {
> + v->provider()->setUsed(true);
> + }
> + }
> + foreach (VectorPtr v, object->outputVectors()) {
> + v->setUsed(true);
> + }
> + foreach (ScalarPtr s, object->inputScalars()) {
> + s->setUsed(true);
> + if (s->provider()) {
> + s->provider()->setUsed(true);
> + }
> + }
> + foreach (ScalarPtr s, object->outputScalars()) {
> + s->setUsed(true);
> + }
> + foreach (StringPtr s, object->inputStrings()) {
> + s->setUsed(true);
> + if (s->provider()) {
> + s->provider()->setUsed(true);
> + }
> + }
> + foreach (StringPtr s, object->outputStrings()) {
> + s->setUsed(true);
> + }
> + foreach (MatrixPtr m, object->inputMatrices()) {
> + m->setUsed(true);
> + if (m->provider()) {
> + m->provider()->setUsed(true);
> + }
> + }
> + foreach (MatrixPtr m, object->outputMatrices()) {
> + m->setUsed(true);
> + }
> + object->unlock();
> + }
> +
> + ObjectList<DataObject> dataObjectList = _doc->objectStore()->getObjects<DataObject>();
> + foreach (DataObjectPtr object, dataObjectList) {
> + object->readLock();
> + //set used all input and output primitives
> + foreach (VectorPtr v, object->inputVectors()) {
> + v->setUsed(true);
> + }
> + foreach (VectorPtr v, object->outputVectors()) {
> + v->setUsed(true);
> + }
> + foreach (ScalarPtr s, object->inputScalars()) {
> + s->setUsed(true);
> + }
> + foreach (ScalarPtr s, object->outputScalars()) {
> + s->setUsed(true);
> + }
> + foreach (StringPtr s, object->inputStrings()) {
> + s->setUsed(true);
> + }
> + foreach (StringPtr s, object->outputStrings()) {
> + s->setUsed(true);
> + }
> + foreach (MatrixPtr m, object->inputMatrices()) {
> + m->setUsed(true);
> + }
> + foreach (MatrixPtr m, object->outputMatrices()) {
> + m->setUsed(true);
> + }
> + object->unlock();
> + }
> +}
> +
> +void DataManager::purge() {
> + do {
> + setUsedFlags();
> + } while (_doc->objectStore()->deleteUnsetUsedFlags());
> + _session->reset();
> +}
> +
> +}
> +
> // vim: ts=2 sw=2 et
> --- branches/work/kst/portto4/kst/src/libkstapp/datamanager.h #1133828:1133829
> @@ -59,6 +59,9 @@
>
> virtual bool event(QEvent * event);
>
> + void setUsedFlags();
> + void purge();
> +
> private:
> Document *_doc;
>
> --- branches/work/kst/portto4/kst/src/libkstapp/datamanager.ui #1133828:1133829
> @@ -1,3 +1,4 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> <ui version="4.0" >
> <class>DataManager</class>
> <widget class="QDialog" name="DataManager" >
> @@ -6,14 +7,14 @@
> <x>0</x>
> <y>0</y>
> <width>750</width>
> - <height>347</height>
> + <height>235</height>
> </rect>
> </property>
> <property name="windowTitle" >
> <string>Data Manager</string>
> </property>
> - <layout class="QVBoxLayout" >
> - <item>
> + <layout class="QGridLayout" name="gridLayout">
> + <item row="0" column="0" colspan="3">
> <widget class="QSplitter" name="_splitter" >
> <property name="layoutDirection" >
> <enum>Qt::LeftToRight</enum>
> @@ -26,7 +27,7 @@
> </property>
> <widget class="QToolBox" name="_objects" >
> <property name="sizePolicy" >
> - <sizepolicy vsizetype="Preferred" hsizetype="Minimum" >
> + <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
> <horstretch>0</horstretch>
> <verstretch>0</verstretch>
> </sizepolicy>
> @@ -37,7 +38,7 @@
> </widget>
> <widget class="QTreeView" name="_session" >
> <property name="sizePolicy" >
> - <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
> <horstretch>0</horstretch>
> <verstretch>0</verstretch>
> </sizepolicy>
> @@ -45,8 +46,34 @@
> </widget>
> </widget>
> </item>
> - <item>
> + <item row="1" column="0">
> + <spacer name="horizontalSpacer">
> + <property name="orientation">
> + <enum>Qt::Horizontal</enum>
> + </property>
> + <property name="sizeHint" stdset="0">
> + <size>
> + <width>601</width>
> + <height>20</height>
> + </size>
> + </property>
> + </spacer>
> + </item>
> + <item row="1" column="1">
> + <widget class="QPushButton" name="_purge">
> + <property name="text">
> + <string>Purge</string>
> + </property>
> + </widget>
> + </item>
> + <item row="1" column="2">
> <widget class="QDialogButtonBox" name="_buttonBox" >
> + <property name="sizePolicy">
> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
> + <horstretch>0</horstretch>
> + <verstretch>0</verstretch>
> + </sizepolicy>
> + </property>
> <property name="orientation" >
> <enum>Qt::Horizontal</enum>
> </property>
> --- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #1133828:1133829
> @@ -19,7 +19,6 @@
>
> #include <QHash>
>
> -#include "relation.h"
> #include "plotrenderitem.h"
> #include "plotiteminterface.h"
> #include "plotdefines.h"
> --- branches/work/kst/portto4/kst/src/libkstapp/plotitemmanager.cpp #1133828:1133829
> @@ -68,7 +68,6 @@
> void PlotItemManager::removePlot(PlotItem *plotItem) {
> if (!_plotLists.contains(plotItem->parentView()))
> return;
> -
> QList<PlotItem*> list = _plotLists.value(plotItem->parentView());
> list.removeAll(plotItem);
> _plotLists.insert(plotItem->parentView(), list);
> --- branches/work/kst/portto4/kst/src/libkstapp/sessionmodel.cpp #1133828:1133829
> @@ -183,6 +183,10 @@
> rc = p->typeString();
> break;
> case 2:
> + // this is very fragile and depends on how the smart pointers are being carried around.
> + // we should consider a different approach (?). Keep it now for debugging...
> + // It doesn't know, for instance, if a plot has been 'deleted'.
> + rc = QString::number(p.count()-4); //4: object store, session model, cast, local
> break;
> case 3:
> rc = p->sizeString();
> @@ -215,6 +219,9 @@
> p->unlock();
> break;
> case 2:
> + // this is very fragile and depends on how the smart pointers are being carried around.
> + // we should consider a different approach or delete(?). Keep it now for debugging...
> + rc = QString::number(p.count()-4); //4: object store, session model, cast, local
> break;
> case 3:
> p->readLock();
> @@ -251,6 +258,9 @@
> p->unlock();
> break;
> case 2:
> + // this is very fragile and depends on how the smart pointers are being carried around.
> + // we should consider a different approach or delete (?). Keep it now for debugging...
> + rc = QString::number(p.count()-4); //4: object store, session model, cast, local
> break;
> case 3:
> p->readLock();
> --- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #1133828:1133829
> @@ -103,6 +103,8 @@
>
>
> View::~View() {
> + delete _undoStack;
> + delete _layoutBoxItem;
> }
>
>
> --- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #1133828:1133829
> @@ -2125,6 +2125,9 @@
> void RemoveCommand::redo() {
> Q_ASSERT(_item);
> _item->hide();
> + // hmmm... view items aren't really deleted!! if we delete them,
> + // then we run into trouble with the undo stack. If we don't, then
> + // they keep holding onto the curves, preventing purge.
> }
>
>
> --- branches/work/kst/portto4/kst/src/libkstmath/relation.h #1133828:1133829
> @@ -144,6 +144,28 @@
> // Compare the cached the context to the provided one.
> bool redrawRequired(const CurveRenderContext& context);
>
> + // If you use these, you must lock() and unlock() the object as long as you
> + // hold the reference
> + const VectorMap& inputVectors() const { return _inputVectors; }
> + const VectorMap& outputVectors() const { return _outputVectors; }
> + VectorMap& inputVectors() { return _inputVectors; }
> + VectorMap& outputVectors() { return _outputVectors; }
> +
> + const ScalarMap& inputScalars() const { return _inputScalars; }
> + const ScalarMap& outputScalars() const { return _outputScalars; }
> + ScalarMap& inputScalars() { return _inputScalars; }
> + ScalarMap& outputScalars() { return _outputScalars; }
> +
> + const StringMap& inputStrings() const { return _inputStrings; }
> + const StringMap& outputStrings() const { return _outputStrings; }
> + StringMap& inputStrings() { return _inputStrings; }
> + StringMap& outputStrings() { return _outputStrings; }
> +
> + const MatrixMap& inputMatrices() const { return _inputMatrices; }
> + const MatrixMap& outputMatrices() const { return _outputMatrices; }
> + MatrixMap& inputMatrices() { return _inputMatrices; }
> + MatrixMap& outputMatrices() { return _outputMatrices; }
> +
> protected:
> virtual void writeLockInputsAndOutputs() const;
> virtual void unlockInputsAndOutputs() const;
> _______________________________________________
> Kst mailing list
> Kst at kde.org
> https://mail.kde.org/mailman/listinfo/kst
>
--
"No matter where you go, there you are."
--------------------------
Matthew Truch
Department of Physics and Astronomy
University of Pennsylvania
matt at truch.net
http://matt.truch.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kst/attachments/20100602/02311de9/attachment-0001.sig
More information about the Kst
mailing list