[rkward-cvs] SF.net SVN: rkward: [2181] branches/KDE4_port/rkward/dataeditor

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Nov 5 22:22:33 UTC 2007


Revision: 2181
          http://rkward.svn.sourceforge.net/rkward/?rev=2181&view=rev
Author:   tfry
Date:     2007-11-05 14:22:33 -0800 (Mon, 05 Nov 2007)

Log Message:
-----------
Start constructing the new basis for the data editor

Modified Paths:
--------------
    branches/KDE4_port/rkward/dataeditor/CMakeLists.txt

Added Paths:
-----------
    branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp
    branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h

Modified: branches/KDE4_port/rkward/dataeditor/CMakeLists.txt
===================================================================
--- branches/KDE4_port/rkward/dataeditor/CMakeLists.txt	2007-11-05 12:18:08 UTC (rev 2180)
+++ branches/KDE4_port/rkward/dataeditor/CMakeLists.txt	2007-11-05 22:22:33 UTC (rev 2181)
@@ -15,6 +15,7 @@
    editlabelsdialog.cpp
    editformatdialog.cpp
    rkeditordataframepart.cpp
+   rkvareditmodel.cpp
    )
 
 QT4_AUTOMOC(${dataeditor_STAT_SRCS})

Added: branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp	                        (rev 0)
+++ branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp	2007-11-05 22:22:33 UTC (rev 2181)
@@ -0,0 +1,162 @@
+/***************************************************************************
+                          rkvareditmodel  -  description
+                             -------------------
+    begin                : Mon Nov 05 2007
+    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "rkvareditmodel.h"
+
+#include "../core/rkvariable.h"
+#include "../core/rcontainerobject.h"
+#include "../core/rkmodificationtracker.h"
+#include "../rkglobals.h"
+
+#include "../debug.h"
+
+RKVarEditModel::RKVarEditModel (QObject *parent) : QAbstractTableModel (parent) {
+	RK_TRACE (EDITOR);
+
+	meta_model = 0;
+	trailing_rows = trailing_cols = 0;
+	edit_blocks = 0;
+
+	connect (RKGlobals::tracker (), SIGNAL (objectRemoved(RObject*)), this, SLOT (objectRemoved(RObject*)));
+}
+
+RKVarEditModel::~RKVarEditModel () {
+	RK_TRACE (EDITOR);
+}
+
+void RKVarEditModel::addObject (int index, RKVariable* object) {
+	RK_TRACE (EDITOR);
+	RK_ASSERT (object);
+
+	if ((index < 0) || (index >= objects.size ())) index = objects.size ();
+
+	beginInsertColumns (QModelIndex (), index, index);
+	if (meta_model) meta_model->beginAddDataObject (index);
+	objects.insert (index, object);
+	if (meta_model) meta_model->endAddDataObject (index);
+	endInsertColumns ();
+}
+
+void RKVarEditModel::objectRemoved (RObject* object) {
+	RK_TRACE (EDITOR);
+
+	int index = objects.indexOf (static_cast<RKVariable*> (object));	// no check for isVariable needed. we only need to look up, if we have this object, and where.
+	if (index < 0) return;	// none of our buisiness
+
+	beginRemoveColumns (QModelIndex (), index, index);
+	if (meta_model) meta_model->beginRemoveDataObject (index);
+	objects.removeAt (index);
+	if (meta_model) meta_model->endRemoveDataObject (index);
+	endRemoveColumns ();
+}
+
+RKVarEditMetaModel* RKVarEditModel::getMetaModel () {
+	RK_TRACE (EDITOR);
+
+	if (!meta_model) meta_model = new RKVarEditMetaModel (this);
+
+	return meta_model;
+}
+
+bool RKVarEditModel::insertRows (int row, int count, const QModelIndex& parent) {
+	RK_TRACE (EDITOR);
+
+	int lastrow = row+count - 1;
+	if (edit_blocks || parent.isValid () || objects.isEmpty () || (row > objects[0]->getLength ())) {
+		RK_ASSERT (false);
+		return false;
+	}
+	RK_ASSERT (row >= 0);
+	RK_ASSERT (lastrow <= row);
+
+	beginInsertRows (QModelIndex (), row, row+count);
+	for (int i=0; i < objects.size (); ++i) {
+		objects[i]->insertRows (row, count);
+	}
+	endInsertRows ();
+
+	return true;
+}
+
+bool RKVarEditModel::removeRows (int row, int count, const QModelIndex& parent) {
+	RK_TRACE (EDITOR);
+
+	int lastrow = row+count - 1;
+	if (edit_blocks || parent.isValid () || objects.isEmpty () || (lastrow > objects[0]->getLength ())) {
+		RK_ASSERT (false);
+		return false;
+	}
+	RK_ASSERT (row >= 0);
+	RK_ASSERT (lastrow <= row);
+
+	beginRemoveRows (QModelIndex (), row, lastrow);
+	for (int i=0; i < objects.size (); ++i) {
+		objects[i]->removeRows (row, lastrow);
+	}
+	endRemoveRows ();
+
+	return true;
+}
+
+int RKVarEditModel::rowCount (const QModelIndex& parent) const {
+	RK_TRACE (EDITOR);
+
+	if (parent.isValid ()) return 0;
+	if (objects.isEmpty ()) {
+		RK_ASSERT (false);
+		return 0;
+	}
+	return objects[0]->getLength ();
+}
+
+int RKVarEditModel::columnCount (const QModelIndex& parent) const {
+	RK_TRACE (EDITOR);
+
+	if (parent.isValid ()) return 0;
+	return objects.size ();
+}
+
+QVariant RKVarEditModel::data (const QModelIndex& index, int role) const {
+	RK_TRACE (EDITOR);
+#warning implement
+}
+
+Qt::ItemFlags RKVarEditModel::flags (const QModelIndex& index) const {
+	RK_TRACE (EDITOR);
+#warning implement
+}
+
+bool RKVarEditModel::setData (const QModelIndex& index, const QVariant& value, int role) {
+	RK_TRACE (EDITOR);
+#warning implement
+}
+
+QVariant RKVarEditModel::headerData (int section, Qt::Orientation orientation, int role) const {
+	RK_TRACE (EDITOR);
+#warning implement
+}
+
+
+
+
+
+
+
+
+
+
+#include "rkvareditmodel.moc"

Added: branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h	                        (rev 0)
+++ branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h	2007-11-05 22:22:33 UTC (rev 2181)
@@ -0,0 +1,107 @@
+/***************************************************************************
+                          rkvareditmodel  -  description
+                             -------------------
+    begin                : Mon Nov 05 2007
+    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef RKVAREDITMODEL
+#define RKVAREDITMODEL
+
+#include <QAbstractTableModel>
+#include <QList>
+
+class RKVarEditMetaModel;
+class RKVariable;
+class RObject;
+class RContainerObject;
+
+/** This class represents a collection of RKVariables of uniform length (typically a data.frame) suitable for editing in a model/view editor such as QTableView. Probably it will only ever support editing a single RKVariable, though, as it is not possible to ensure uniform length outside of a data.frame. For a data.frame use RKVarEditDataFrameModel . */
+class RKVarEditModel : public QAbstractTableModel {
+	Q_OBJECT
+public:
+	RKVarEditModel (QObject *parent);
+	~RKVarEditModel ();
+
+	void addObject (int index, RKVariable* object);
+	RKVarEditMetaModel* getMetaModel ();
+
+	// QAbstractTableModel implementations
+	bool insertRows (int row, int count, const QModelIndex& parent = QModelIndex());
+	bool removeRows (int row, int count, const QModelIndex& parent = QModelIndex());
+	int rowCount (const QModelIndex& parent = QModelIndex()) const;
+	int columnCount (const QModelIndex& parent = QModelIndex()) const;
+	QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
+	Qt::ItemFlags flags (const QModelIndex& index) const;
+	bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
+	QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+signals:
+	// convenience signal to tell the editor to block editing entirely, without having to set all flags to non-editable.
+	void blockEdit (bool block);
+public slots:
+	virtual void objectRemoved (RObject* object);
+protected:
+friend class RKVarEditMetaModel;
+	QList<RKVariable*> objects;
+
+	int trailing_rows;
+	int trailing_cols;
+
+	int edit_blocks;
+
+	RKVarEditMetaModel* meta_model;
+};
+
+/** Represents the meta information portion belonging to an RKVarEditModel. Implemented in a separate class for technical reasons, only (so this info can be displayed in a separate QTableView) */
+class RKVarEditMetaModel : public QAbstractTableModel {
+	Q_OBJECT
+public:
+	// QAbstractTableModel implementations. Most of these are simply proxies to the corresponding functions in the datamodel
+	int rowCount (const QModelIndex& parent = QModelIndex()) const;
+	int columnCount (const QModelIndex& parent = QModelIndex()) const;
+	QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
+	Qt::ItemFlags flags (const QModelIndex& index) const;
+	bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
+	QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+protected:
+friend class RKVarEditModel;
+	RKVarEditMetaModel (RKVarEditModel* datamodel);
+	~RKVarEditMetaModel ();
+
+	void beginAddDataObject (int index);
+	void endAddDataObject (int index);
+	void beginRemoveDataObject (int index);
+	void endRemoveDataObject (int index);
+
+	RKVarEditModel* data_model;
+};
+
+
+class RKVarEditDataFrameModel : public RKVarEditModel {
+	Q_OBJECT
+public:
+	RKVarEditDataFrameModel (RContainerObject* dataframe, QObject *parent);
+	~RKVarEditDataFrameModel ();
+
+	bool insertColumns (int column, int count, const QModelIndex& parent = QModelIndex());
+	bool removeColumns (int column, int count, const QModelIndex& parent = QModelIndex());
+
+	// reimplemented from RKVarEditModel to list for the dataframe object as well
+	void objectRemoved (RObject* object);
+public slots:
+	void objectAdded (RObject* object);
+protected:
+	RContainerObject* dataframe;
+};
+
+#endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list