[rkward-cvs] SF.net SVN: rkward:[4392] trunk/rkward/rkward/plugin

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Oct 25 09:24:00 UTC 2012


Revision: 4392
          http://rkward.svn.sourceforge.net/rkward/?rev=4392&view=rev
Author:   tfry
Date:     2012-10-25 09:23:59 +0000 (Thu, 25 Oct 2012)
Log Message:
-----------
Start implementing the matrix input element.

Modified Paths:
--------------
    trunk/rkward/rkward/plugin/rkmatrixinput.cpp
    trunk/rkward/rkward/plugin/rkmatrixinput.h

Modified: trunk/rkward/rkward/plugin/rkmatrixinput.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkmatrixinput.cpp	2012-10-24 15:07:59 UTC (rev 4391)
+++ trunk/rkward/rkward/plugin/rkmatrixinput.cpp	2012-10-25 09:23:59 UTC (rev 4392)
@@ -15,9 +15,112 @@
  *                                                                         *
  ***************************************************************************/
 
-#include "rkmatrixinput.cpp"
+#include "rkmatrixinput.h"
 
+#include <QVBoxLayout>
+
+#include "klocale.h"
+
+#include "../misc/xmlhelper.h"
+
 #include "../debug.h"
 
+RKMatrixInput::RKMatrixInput (const QDomElement& element, RKComponent* parent_component, QWidget* parent_widget) : RKComponent (parent_component, parent_widget), QAbstractTableModel () {
+	RK_TRACE (PLUGIN);
 
+	// get xml-helper
+	XMLHelper *xml = XMLHelper::getStaticHelper ();
+
+	// create layout
+	QVBoxLayout *vbox = new QVBoxLayout (this);
+	vbox->setContentsMargins (0, 0, 0, 0);
+
+	QLabel *label = new QLabel (xml->getStringAttribute (element, "label", i18n ("Enter data:"), DL_INFO), this);
+	vbox->addWidget (label);
+
+	display = new QTableView (this);
+	vbox->addWidget (display);
+
+	mode = static_cast<Mode> (xml->getMultiChoiceAttribute (element, "mode", "integer;real;string", 1, DL_WARNING));
+	if (mode == Integer) {
+		min = xml->getIntAttribute (element, "min", INT_MIN, DL_INFO) - .1;	// we'll only allow ints anyway. Make sure not to run into floating point precision issues.
+		max = xml->getIntAttribute (element, "max", INT_MAX, DL_INFO) + .1;
+	} else if (mode == Real) {
+		min = xml->getDoubleAttribute (element, "min", -FLT_MAX, DL_INFO);
+		max = xml->getDoubleAttribute (element, "min", FLT_MAX, DL_INFO);
+	} else {
+		min = -FLT_MAX;
+		max = FLT_MAX;
+	}
+
+	allow_missings = xml->getBoolAttribute (element, "allow_missings", false, DL_INFO);
+	allow_user_resize_columns = xml->getBoolAttribute (element, "allow_user_resize_columns", true, DL_INFO);
+	allow_user_resize_rows = xml->getBoolAttribute (element, "allow_user_resize_rows", true, DL_INFO);
+	trailing_rows = allow_user_resize_rows ? 1 :0;
+	trailing_columns = allow_user_resize_columns ? 1 :0;
+
+	row_count = new RKComponentPropertyInt (this, false, xml->getIntAttribute (element, "rows", 2, DL_INFO));
+	column_count = new RKComponentPropertyInt (this, false, xml->getIntAttribute (element, "columns", 2, DL_INFO));
+	tsv_data = new RKComponentPropertyBase (this);
+	row_count->setInternal (true);
+	addChild (row_count);
+	column_count->setInternal (true);
+	addChild (column_count);
+	addChild (tsv_data);
+	connect (row_count, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (dimensionPropertyChanged()));
+	connect (column_count, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (dimensionPropertyChanged()));
+	connect (tsv_data, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (tsvPropertyChanged()));
+	updating_tsv_data = false;
+	updating_dimensions = false;
+
+	display->setModel (this);
+}
+
+
+RKMatrixInput::~RKMatrixInput () {
+	RK_TRACE (PLUGIN);
+}
+
+int RKMatrixInput::columnCount (const QModelIndex& parent) const {
+	if (parent.isValid ()) return 0;
+	return column_count->intValue () + trailing_columns;
+}
+
+int RKMatrixInput::rowCount (const QModelIndex& parent) const {
+	if (parent.isValid ()) return 0;
+	return row_count->intValue () + trailing_rows;
+}
+
+QVariant RKMatrixInput::data (const QModelIndex& index, int role) const {
+	if (!index.isValid ()) return QVariant ();
+
+	int row = index.row ();
+	int column = index.column ();
+
+	bool trailing = false;
+	if (row > row_count->intValue ()) {
+		if ((!allow_user_resize_rows) || (row > row_count->intValue () + TRAILING_ROWS)) {
+			RK_ASSERT (false);
+			return QVariant ();
+		}
+		trailing = true;
+	}
+	if (column > column_count->intValue ()) {
+		if ((!allow_user_resize_columns) || (column > column_count->intValue () + TRAILING_COLS)) {
+			RK_ASSERT (false);
+			return QVariant ();
+		}
+		trailing = true;
+	};
+	if (trailing) {
+		if (role == Qt::BackgroundRole) return QVariant (QBrush (Qt::lightGray));
+		if (role == Qt::ToolTipRole || role == Qt::StatusTipRole) return QVariant (i18n ("Type on these cells to expand the table"));
+		return QVariant ();
+	}
+#error TODO
+}
+
+
+#error TODO
+
 #include "rkmatrixinput.moc"

Modified: trunk/rkward/rkward/plugin/rkmatrixinput.h
===================================================================
--- trunk/rkward/rkward/plugin/rkmatrixinput.h	2012-10-24 15:07:59 UTC (rev 4391)
+++ trunk/rkward/rkward/plugin/rkmatrixinput.h	2012-10-25 09:23:59 UTC (rev 4392)
@@ -37,8 +37,8 @@
 	bool isValid () { return is_valid; };
 	QString value (const QString &modifier);
 private slots:
-	void dimensionPropertyChanged (RKComponentPropertyBase *property);
-	void tsvPropertyChanged (RKComponentPropertyBase *property);
+	void dimensionPropertyChanged ();
+	void tsvPropertyChanged ();
 private:
 	RKComponentPropertyInt *row_count;
 	RKComponentPropertyInt *column_count;
@@ -50,17 +50,19 @@
 	bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); // re-implemented for QAbstractTableModel
 
 	enum Mode {
-		Integer,
+		Integer=0,
 		Real,
 		String
-	};
+	} mode;
 
 	double min;
 	double max;
 
-	bool allow_missings;
-	bool allow_user_resize_rows;
-	bool allow_user_resize_columns;
+	const bool allow_missings;
+	const bool allow_user_resize_rows;
+	const bool allow_user_resize_columns;
+	const int trailing_rows;
+	const int trailing_columns;
 
 	bool isValueValid (const QString &value) const;
 	void updateValidityFlag ();
@@ -76,11 +78,15 @@
 	struct Column {
 		int valid_up_to_row;	// to save validizing the entire table on each change, we keep track of validity per column
 		QStringList storage;
-		QString cached_joined_string;
+		QString cached_tab_joined_string;
 	};
 	QList<Column> columns;
 
 	QTableView *display;
+
+	// these two to avoid recursion:
+	bool updating_dimensions;
+	bool updating_tsv_data;
 };
 
 #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