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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sun Nov 11 21:28:08 UTC 2007


Revision: 2200
          http://rkward.svn.sourceforge.net/rkward/?rev=2200&view=rev
Author:   tfry
Date:     2007-11-11 13:28:08 -0800 (Sun, 11 Nov 2007)

Log Message:
-----------
Make format editor dialog work again

Modified Paths:
--------------
    branches/KDE4_port/rkward/core/rkvariable.cpp
    branches/KDE4_port/rkward/core/rkvariable.h
    branches/KDE4_port/rkward/dataeditor/celleditor.cpp
    branches/KDE4_port/rkward/dataeditor/celleditor.h
    branches/KDE4_port/rkward/dataeditor/editformatdialog.cpp
    branches/KDE4_port/rkward/dataeditor/editformatdialog.h
    branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h
    branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp
    branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h
    branches/KDE4_port/rkward/dataeditor/twintable.cpp
    branches/KDE4_port/rkward/dataeditor/twintablemember.cpp
    branches/KDE4_port/rkward/dataeditor/twintablemember.h

Modified: branches/KDE4_port/rkward/core/rkvariable.cpp
===================================================================
--- branches/KDE4_port/rkward/core/rkvariable.cpp	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/core/rkvariable.cpp	2007-11-11 21:28:08 UTC (rev 2200)
@@ -75,10 +75,10 @@
 		int num_listeners = data->num_listeners;
 		ValueLabels *value_labels = data->value_labels;
 		data->value_labels = 0;	// prevent destruction
-		FormattingOptions *formatting_options = data->formatting_options;
-		data->formatting_options = 0;	// prevent destruction
+		FormattingOptions formatting_options = data->formatting_options;
 
 		// destroy and re-allocate edit data
+		data->num_listeners = 0;	// to avoid the otherwise useful assert in discardEditData
 		discardEditData ();
 		setDataType (new_type);
 		allocateEditData ();
@@ -263,7 +263,9 @@
 	data->immediate_sync = true;
 	data->changes = 0;
 	data->value_labels = 0;
-	data->formatting_options = 0;
+	data->formatting_options.alignment = FormattingOptions::AlignDefault;
+	data->formatting_options.precision_mode = FormattingOptions::PrecisionDefault;
+	data->formatting_options.precision = 0;
 	data->previously_valid = true;
 	data->invalid_fields.setAutoDelete (true);
 	data->num_listeners = 0;
@@ -292,7 +294,6 @@
 
 	RK_ASSERT (!(data->changes));
 	delete data->value_labels;
-	delete data->formatting_options;
 	delete data;
 	data = 0;
 }
@@ -491,11 +492,11 @@
 		return (data->cell_strings[row]);
 	} else {
 		RK_ASSERT (data->cell_doubles != 0);
-		if (pretty && data->formatting_options && (data->formatting_options->precision_mode != FormattingOptions::PrecisionDefault)) {
-			if (data->formatting_options->precision_mode == FormattingOptions::PrecisionRequired) {
+		if (pretty && (data->formatting_options.precision_mode != FormattingOptions::PrecisionDefault)) {
+			if (data->formatting_options.precision_mode == FormattingOptions::PrecisionRequired) {
 				return QString::number (data->cell_doubles[row], 'g', MAX_PRECISION);
 			}
-			return QString::number (data->cell_doubles[row], 'f', data->formatting_options->precision);
+			return QString::number (data->cell_doubles[row], 'f', data->formatting_options.precision);
 		}
 		return QString::number (data->cell_doubles[row], 'g', MAX_PRECISION);
 	}
@@ -888,44 +889,21 @@
 	setValueLabels (new_labels);
 }
 
-RKVariable::FormattingOptions *RKVariable::getFormattingOptions () const {
+RKVariable::FormattingOptions RKVariable::getFormattingOptions () const {
 	RK_TRACE (OBJECTS);
 	RK_ASSERT (data);
 
 	return data->formatting_options;
 }
 
-void RKVariable::setFormattingOptions (FormattingOptions *formatting_options) {
+void RKVariable::setFormattingOptions (FormattingOptions new_options) {
 	RK_TRACE (OBJECTS);
 	RK_ASSERT (data);
-	
-	if (formatting_options != data->formatting_options) {
-		delete data->formatting_options;
-	}
 
-	data->formatting_options = formatting_options;
+	if ((new_options.alignment == data->formatting_options.alignment) && (new_options.precision_mode == data->formatting_options.precision_mode) && (new_options.precision == data->formatting_options.precision)) return;
 
-	if (!formatting_options) {
-		setMetaProperty ("format", QString::null);
-	} else {
-		QString format_string;
-		if (formatting_options->alignment != (int) FormattingOptions::AlignDefault) {
-			format_string.append ("align:");
-			format_string.append (QString::number (formatting_options->alignment));
-		}
-	
-		if (formatting_options->precision_mode != (int) FormattingOptions::PrecisionDefault) {
-			if (!format_string.isEmpty ()) format_string.append ("#");
-			format_string.append ("prec:");
-			if (formatting_options->precision_mode == (int) FormattingOptions::PrecisionRequired) {
-				format_string.append ("v");
-			} else {
-				format_string.append (QString::number (formatting_options->precision));
-			}
-		}
-	
-		setMetaProperty ("format", format_string);
-	}
+	data->formatting_options = new_options;
+	setMetaProperty ("format", formattingOptionsToString (new_options));
 
 	// also update display of all values:
 	ChangeSet *set = new ChangeSet;
@@ -949,13 +927,35 @@
 }
 
 // static
-RKVariable::FormattingOptions *RKVariable::parseFormattingOptionsString (const QString &string) {
+QString RKVariable::formattingOptionsToString (const FormattingOptions& options) {
 	RK_TRACE (OBJECTS);
 
-	FormattingOptions *formatting_options = new FormattingOptions;
-	formatting_options->alignment = FormattingOptions::AlignDefault;
-	formatting_options->precision_mode = FormattingOptions::PrecisionDefault;
-	formatting_options->precision = 0;
+	QString format_string;
+	if (options.alignment != (int) FormattingOptions::AlignDefault) {
+		format_string.append ("align:" + QString::number (options.alignment));
+	}
+
+	if (options.precision_mode != (int) FormattingOptions::PrecisionDefault) {
+		if (!format_string.isEmpty ()) format_string.append ("#");
+		format_string.append ("prec:");
+		if (options.precision_mode == (int) FormattingOptions::PrecisionRequired) {
+			format_string.append ("v");
+		} else {
+			format_string.append (QString::number (options.precision));
+		}
+	}
+
+	return format_string;
+}
+
+// static
+RKVariable::FormattingOptions RKVariable::parseFormattingOptionsString (const QString &string) {
+	RK_TRACE (OBJECTS);
+
+	FormattingOptions formatting_options;
+	formatting_options.alignment = FormattingOptions::AlignDefault;
+	formatting_options.precision_mode = FormattingOptions::PrecisionDefault;
+	formatting_options.precision = 0;
 	bool empty = true;
 
 	QStringList list = QStringList::split ("#", string);
@@ -970,21 +970,21 @@
 			int al = parameter.toInt ();
 			if ((al >= (int) FormattingOptions::AlignDefault) && (al <= (int) FormattingOptions::AlignRight)) {
 				empty = false;
-				formatting_options->alignment = (FormattingOptions::Alignment) al;
+				formatting_options.alignment = (FormattingOptions::Alignment) al;
 			}
 		} else if (option == "prec") {
 			if (parameter == "d") {
 				empty = false;
-				formatting_options->precision_mode = FormattingOptions::PrecisionDefault;
+				formatting_options.precision_mode = FormattingOptions::PrecisionDefault;
 			} else if (parameter == "v") {
 				empty = false;
-				formatting_options->precision_mode = FormattingOptions::PrecisionRequired;
+				formatting_options.precision_mode = FormattingOptions::PrecisionRequired;
 			} else {
-				int dig = parameter.toInt ();
-				if ((dig >= 0) && (dig <= 15)) {
+				int digits = parameter.toInt ();
+				if ((digits >= 0) && (digits <= 15)) {
 					empty = false;
-					formatting_options->precision_mode = FormattingOptions::PrecisionFixed;
-					formatting_options->precision = dig;
+					formatting_options.precision_mode = FormattingOptions::PrecisionFixed;
+					formatting_options.precision = digits;
 				}
 			}
 		} else {
@@ -992,19 +992,14 @@
 		}
 	}
 	
-	if (empty) {
-		delete formatting_options;
-		return 0;
-	} else {
-		return formatting_options;
-	}
+	return formatting_options;
 }
 
 RKVariable::CellAlign RKVariable::getAlignment () const {
 	RK_ASSERT (data);
 	
-	if (data->formatting_options && (data->formatting_options->alignment != FormattingOptions::AlignDefault)) {
-		if (data->formatting_options->alignment == FormattingOptions::AlignLeft) return AlignCellLeft;
+	if (data->formatting_options.alignment != FormattingOptions::AlignDefault) {
+		if (data->formatting_options.alignment == FormattingOptions::AlignLeft) return AlignCellLeft;
 		return AlignCellRight;
 	} else {
 	// TODO: use global (configurable) defaults, if not specified

Modified: branches/KDE4_port/rkward/core/rkvariable.h
===================================================================
--- branches/KDE4_port/rkward/core/rkvariable.h	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/core/rkvariable.h	2007-11-11 21:28:08 UTC (rev 2200)
@@ -117,13 +117,13 @@
 		int precision;
 	};
 
-/** returns the formatting options, or 0 if no options specified (i.e. all set to default). Does _not_ return a copy, but the real thing. Do not delete! */
-	FormattingOptions *getFormattingOptions () const;
 /** assigns new formatting options. Ownership of the FormattingOptions -struct is transferred to the variable. Use setFormatting (0) to remove all options */
-	void setFormattingOptions (FormattingOptions *formatting_options);
-/** get formatting options as a string (for display) */
+	void setFormattingOptions (FormattingOptions new_options);
+/** get the formatting options for this variable */
+	FormattingOptions getFormattingOptions () const;
+/** get formatting options as a string (for display) TODO: redundant -> remove */
 	QString getFormattingOptionsString () const;
-/** parse formatting options from the given string */
+/** parse formatting options from the given string TODO: redundant -> remove */
 	void setFormattingOptionsString (const QString &string);
 
 /** This enum describes the alignment of text inside a table cell */
@@ -136,6 +136,10 @@
 /// an unknown value
 	static QString *unknown_char;
 
+/** creates/parses formatting options from the stored meta-property string. See also: getFormattingOptions () */
+	static FormattingOptions parseFormattingOptionsString (const QString &string);
+/** inverse of parseFormattingOptionsString () */
+	static QString formattingOptionsToString (const FormattingOptions& options);
 protected:
 /** reimplemented from RObject to change the internal data storage mode, if the var is being edited */
 	bool updateType (RData *new_data);
@@ -163,7 +167,7 @@
 /// the value-labels or factor levels assigned to this variable. 0 if no values/levels given
 		ValueLabels *value_labels;
 /// the formatting options set for this var (see FormattingOptions) */
-		FormattingOptions *formatting_options;
+		FormattingOptions formatting_options;
 /// storage for invalid fields
 		Q3IntDict<QString> invalid_fields;
 /// how many models need our data?
@@ -189,8 +193,6 @@
 	void writeInvalidField (int row, RCommandChain *chain=0);
 /** writes the values labels to the backend */
 	void writeValueLabels (RCommandChain *chain) const;
-/** creates/parses formatting options from the stored meta-property string. See also: getFormattingOptions () */
-	static FormattingOptions *parseFormattingOptionsString (const QString &string);
 /** tries to match a value-label to the value in the given cell. Returns the label, or - if there is no label - the original value in textual representation */
 	QString getLabeled (int row) const;
 

Modified: branches/KDE4_port/rkward/dataeditor/celleditor.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/celleditor.cpp	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/dataeditor/celleditor.cpp	2007-11-11 21:28:08 UTC (rev 2200)
@@ -16,13 +16,9 @@
  ***************************************************************************/
 #include "celleditor.h"
 
-#include <qapplication.h>
 #include <QMenu>
 #include <QTimer>
-
-//Added by qt3to4:
 #include <QEvent>
-#include <QTimerEvent>
 #include <QKeyEvent>
 
 #include "../debug.h"
@@ -47,10 +43,8 @@
 	value_list = new QMenu (this);
 	value_list->setFont (font ());
 	value_list->setPalette (palette ());
-//	value_list->setFrameStyle (Q3Frame::Box | Q3Frame::Plain);
-//	value_list->setLineWidth (1);
 	value_list->setFocusProxy (this);
-	value_list->installEventFilter (this);
+	value_list->installEventFilter (this);	// somehow setting us as a focus proxy is not enough to continue to receive the key-presses
 
 	for (RObject::ValueLabels::const_iterator it = labels->constBegin (); it != labels->constEnd (); ++it) {
 		value_list->addAction (it.key () + ": " + it.data ())->setData (it.key ());
@@ -64,7 +58,7 @@
 	RK_TRACE (EDITOR);
 	RK_ASSERT (action);
 
-	setText (action->data ().toString ());	// which is an int, really
+	setText (action->data ().toString ());	// which is a string representation of an int, really
 }
 
 void CellEditor::setText (const QString& text) {

Modified: branches/KDE4_port/rkward/dataeditor/celleditor.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/celleditor.h	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/dataeditor/celleditor.h	2007-11-11 21:28:08 UTC (rev 2200)
@@ -17,17 +17,16 @@
 #ifndef CELLEDITOR_H
 #define CELLEDITOR_H
 
-#include <qlineedit.h>
+#include <QLineEdit>
 #include <QList>
-//Added by qt3to4:
-#include <QKeyEvent>
-#include <QEvent>
 
 #include "../core/robject.h"
 #include "twintablemember.h"
 
 class QStringList;
 class QMenu;
+class QEvent;
+class QKeyEvent;
 
 /**
 This is the main editor used in the TwinTableMembers

Modified: branches/KDE4_port/rkward/dataeditor/editformatdialog.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/editformatdialog.cpp	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/dataeditor/editformatdialog.cpp	2007-11-11 21:28:08 UTC (rev 2200)
@@ -16,49 +16,43 @@
  ***************************************************************************/
 #include "editformatdialog.h"
 
-#include "../core/rkvariable.h"
-#include "../rkglobals.h"
-#include "../debug.h"
-
 #include <q3buttongroup.h>
 #include <qradiobutton.h>
-#include <qpushbutton.h>
 #include <qspinbox.h>
-#include <qlayout.h>
-#include <qstring.h>
 #include <qstringlist.h>
-//Added by qt3to4:
-#include <Q3VBoxLayout>
+#include <QVBoxLayout>
+#include <QTimer>
 
 #include <klocale.h>
+#include <kvbox.h>
 
-EditFormatDialog::EditFormatDialog (QWidget *parent, RKVariable *var, int mode) : QDialog (parent) {
+#include "../core/rkvariable.h"
+#include "../rkglobals.h"
+#include "../debug.h"
+
+EditFormatDialog::EditFormatDialog (QWidget *parent) : KDialog (parent) {
 	RK_TRACE (EDITOR);
-	RK_ASSERT (var);
-//	RK_ASSERT (var->objectOpened ());
 
-	EditFormatDialog::var = var;
-	EditFormatDialog::mode = mode;
-	EditFormatDialog::options = var->getFormattingOptions ();
-
-	Q3VBoxLayout *vbox = new Q3VBoxLayout (this, RKGlobals::marginHint (), RKGlobals::spacingHint ());
+	KVBox *vbox = new KVBox ();
+	setMainWidget (vbox);
 	
-	alignment_group = new Q3ButtonGroup (i18n ("Alignment"), this);
+	alignment_group = new Q3ButtonGroup (i18n ("Alignment"), vbox);
 	alignment_group->setColumnLayout (0, Qt::Vertical);
 	alignment_group->layout()->setSpacing (RKGlobals::spacingHint ());
 	alignment_group->layout()->setMargin (RKGlobals::marginHint ());
-	Q3VBoxLayout *group_layout = new Q3VBoxLayout (alignment_group->layout());
-	group_layout->addWidget (new QRadioButton (i18n ("Default for type '%1'", RObject::typeToText (var->getDataType ())), alignment_group));
+	QVBoxLayout *group_layout = new QVBoxLayout (alignment_group->layout());
+	group_layout->setContentsMargins (0, 0, 0, 0);
+	group_layout->addWidget (new QRadioButton (i18n ("Default"), alignment_group));
 	group_layout->addWidget (new QRadioButton (i18n ("Left"), alignment_group));
 	group_layout->addWidget (new QRadioButton (i18n ("Right"), alignment_group));
 	alignment_group->setButton ((int) RKVariable::FormattingOptions::AlignDefault);
-	vbox->addWidget (alignment_group);
 
-	precision_group = new Q3ButtonGroup (i18n ("Decimal Places"), this);
+	precision_group = new Q3ButtonGroup (i18n ("Decimal Places"), vbox);
 	precision_group->setColumnLayout (0, Qt::Vertical);
 	precision_group->layout()->setSpacing (RKGlobals::spacingHint ());
 	precision_group->layout()->setMargin (RKGlobals::marginHint ());
-	group_layout = new Q3VBoxLayout (precision_group->layout());
+	group_layout = new QVBoxLayout (precision_group->layout());
+	group_layout->setContentsMargins (0, 0, 0, 0);
 	group_layout->addWidget (new QRadioButton (i18n ("Default setting"), precision_group));
 	group_layout->addWidget (new QRadioButton (i18n ("As required"), precision_group));
 	group_layout->addWidget (new QRadioButton (i18n ("Fixed precision:"), precision_group));
@@ -66,72 +60,39 @@
 	connect (precision_field, SIGNAL (valueChanged (int)), this, SLOT (precisionFieldChanged (int)));
 	group_layout->addWidget (precision_field);
 	precision_group->setButton ((int) RKVariable::FormattingOptions::PrecisionDefault);
-	vbox->addWidget (precision_group);
 
-	QPushButton *ok_button = new QPushButton (i18n ("Ok"), this);
-	connect (ok_button, SIGNAL (clicked ()), this, SLOT (accept ()));
-	vbox->addWidget (ok_button);
-
-	initialize ();
-
-	setCaption (i18n ("Formatting options for '%1'", var->getShortName ()));
+	setButtons (KDialog::Ok | KDialog::Cancel);
 }
 
 EditFormatDialog::~EditFormatDialog () {
 	RK_TRACE (EDITOR);
 }
 
-void EditFormatDialog::initialize () {
+void EditFormatDialog::initialize (const RKVariable::FormattingOptions& options, const QString& varname) {
 	RK_TRACE (EDITOR);
 
-	if (!options) return;
-	
-	alignment_group->setButton ((int) options->alignment);
-	precision_group->setButton ((int) options->precision_mode);
-	precision_field->setValue (options->precision);
+	setCaption (i18n ("Formatting options for '%1'", varname));
+
+	EditFormatDialog::options = options;
+
+	alignment_group->setButton ((int) options.alignment);
+	precision_group->setButton ((int) options.precision_mode);
+	precision_field->setValue (options.precision);
 }
 
 void EditFormatDialog::accept () {
 	RK_TRACE (EDITOR);
 
-	RKVariable::FormattingOptions *new_options = new RKVariable::FormattingOptions;
-	new_options->alignment = RKVariable::FormattingOptions::AlignDefault;
-	new_options->precision_mode = RKVariable::FormattingOptions::PrecisionDefault;
-	new_options->precision = 0;
-	bool empty = true;
-#if QT_VERSION < 0x030200
-	int al = alignment_group->id (button_group->selected ());
-#else
-	int al = alignment_group->selectedId ();
-#endif
-	if (al != (int) RKVariable::FormattingOptions::AlignDefault) {
-		new_options->alignment = (RKVariable::FormattingOptions::Alignment) al;
-		empty = false;
-	}
+	options.alignment = (RKVariable::FormattingOptions::Alignment) alignment_group->selectedId ();
 
-#if QT_VERSION < 0x030200
-	int prec = precision_group->id (button_group->selected ());
-#else
-	int prec = precision_group->selectedId ();
-#endif
-	if (prec != (int) RKVariable::FormattingOptions::PrecisionDefault) {
-		empty = false;
-		if (prec == (int) RKVariable::FormattingOptions::PrecisionRequired) {
-			new_options->precision_mode = RKVariable::FormattingOptions::PrecisionRequired;
-		} else {
-			new_options->precision_mode = RKVariable::FormattingOptions::PrecisionFixed;
-			new_options->precision = precision_field->value ();
-		}
-	}
-
-	if (empty) {
-		delete new_options;
-		var->setFormattingOptions (0);
+	options.precision_mode = (RKVariable::FormattingOptions::Precision) precision_group->selectedId ();
+	if (options.precision_mode == RKVariable::FormattingOptions::PrecisionFixed) {
+		options.precision = precision_field->value ();
 	} else {
-		var->setFormattingOptions (new_options);
+		options.precision = 0;
 	}
 
-	QDialog::accept ();
+	KDialog::accept ();
 }
 
 void EditFormatDialog::precisionFieldChanged (int) {
@@ -140,4 +101,42 @@
 	precision_group->setButton ((int) RKVariable::FormattingOptions::PrecisionFixed);
 }
 
+
+///////////// EditFormatDialogProxy ////////////////////
+
+EditFormatDialogProxy::EditFormatDialogProxy (QWidget* parent) : QWidget (parent) {
+	RK_TRACE (EDITOR);
+
+	dialog = 0;
+}
+
+EditFormatDialogProxy::~EditFormatDialogProxy () {
+	RK_TRACE (EDITOR);
+}
+
+void EditFormatDialogProxy::initialize (const RKVariable::FormattingOptions& options, const QString& varname) {
+	RK_TRACE (EDITOR);
+
+	EditFormatDialogProxy::options = options;
+	dialog = new EditFormatDialog (this);
+	dialog->initialize (options, varname);
+
+	connect (dialog, SIGNAL (finished(int)), this, SLOT (dialogDone(int)));
+	QTimer::singleShot (0, dialog, SLOT (exec()));
+}
+
+void EditFormatDialogProxy::dialogDone (int result) {
+	RK_TRACE (EDITOR);
+	RK_ASSERT (dialog);
+
+	if (result == QDialog::Accepted) {
+		options = dialog->options;
+		emit (done (this, RKItemDelegate::EditorExit));
+	} else {
+		emit (done (this, RKItemDelegate::EditorReject));
+	}
+	dialog->deleteLater ();
+	dialog = 0;
+}
+
 #include "editformatdialog.moc"

Modified: branches/KDE4_port/rkward/dataeditor/editformatdialog.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/editformatdialog.h	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/dataeditor/editformatdialog.h	2007-11-11 21:28:08 UTC (rev 2200)
@@ -17,40 +17,58 @@
 #ifndef EDITFORMATDIALOG_H
 #define EDITFORMATDIALOG_H
 
-#include <qdialog.h>
+#include <kdialog.h>
 
 #include "../core/rkvariable.h"
+#include "twintablemember.h"
 
 class Q3ButtonGroup;
 class QSpinBox;
 
 /**
-Allows editing of format-attributes for an (edited) RKVariable
+Allows editing of format-attributes for an RKVariable
 
 @author Thomas Friedrichsmeier
 */
-class EditFormatDialog : public QDialog {
-Q_OBJECT
-public:
-	EditFormatDialog (QWidget *parent, RKVariable *var, int mode=0);
-
-	~EditFormatDialog ();
+class EditFormatDialog : public KDialog {
+	Q_OBJECT
 public slots:
 	void precisionFieldChanged (int);
 protected:
-/// reimplemented to submit the changes to the backend
+/** reimplemented to make the newly selected options available */
 	void accept ();
+
+friend class EditFormatDialogProxy;
+/** ctor */
+	EditFormatDialog (QWidget *parent);
+/** dtor */
+	~EditFormatDialog ();
+
+/** initializes the GUI-options from the settings for the variable */
+	void initialize (const RKVariable::FormattingOptions& options, const QString& varname);
 private:
 	Q3ButtonGroup *alignment_group;
 	Q3ButtonGroup *precision_group;
 	QSpinBox *precision_field;
-	RKVariable::FormattingOptions *options;
-	
-	RKVariable *var;
-	int mode;
+	RKVariable::FormattingOptions options;
+};
 
-/** initializes the GUI-options from the settings for the variable */
-	void initialize ();
+/** Simple proxy wrapper to allow using a model EditFormatDialog in a QTableView */
+class EditFormatDialogProxy : public QWidget {
+	Q_OBJECT
+public:
+	EditFormatDialogProxy (QWidget* parent);
+	~EditFormatDialogProxy ();
+
+	void initialize (const RKVariable::FormattingOptions& options, const QString& varname);
+	RKVariable::FormattingOptions getOptions () const { return options; };
+signals:
+	void done (QWidget* widget, RKItemDelegate::EditorDoneReason reason);
+protected slots:
+	void dialogDone (int result);
+private:
+	RKVariable::FormattingOptions options;
+	EditFormatDialog* dialog;
 };
 
 #endif

Modified: branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/dataeditor/editlabelsdialog.h	2007-11-11 21:28:08 UTC (rev 2200)
@@ -86,6 +86,7 @@
 protected:
 /// reimplemented to submit the changes to the backend
 	void accept ();
+	void reject ();
 private:
 	RKVarLevelsTable *table;
 	RKVariable *var;

Modified: branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/dataeditor/rkvareditmodel.cpp	2007-11-11 21:28:08 UTC (rev 2200)
@@ -229,6 +229,10 @@
 	RKVariable::Status status = var->cellStatus (row);
 	if ((role == Qt::BackgroundRole) && (status == RKVariable::ValueInvalid)) return (Qt::red);
 	if ((role == Qt::ForegroundRole) && (status == RKVariable::ValueUnknown)) return (Qt::lightGray);
+	if (role == Qt::TextAlignmentRole) {
+		if (var->getAlignment () == RKVariable::AlignCellLeft) return ((int) Qt::AlignLeft | Qt::AlignVCenter);
+		else return ((int) Qt::AlignRight | Qt::AlignVCenter);
+	}
 
 	return QVariant ();
 }

Modified: branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/dataeditor/rkvareditmodel.h	2007-11-11 21:28:08 UTC (rev 2200)
@@ -143,6 +143,7 @@
 	int trueRows () const { return RowCount; };
 
 	RKVariable* getObject (int index) const { return data_model->getObject (index); };
+	RKVarEditModel* getDataModel () const { return data_model; };
 protected:
 friend class RKVarEditModel;
 	RKVarEditMetaModel (RKVarEditModel* data_model);

Modified: branches/KDE4_port/rkward/dataeditor/twintable.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintable.cpp	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/dataeditor/twintable.cpp	2007-11-11 21:28:08 UTC (rev 2200)
@@ -94,6 +94,7 @@
 	dataview->setRKModel (model);
 	metaview->setRKModel (model->getMetaModel ());
 	dataview->seRKItemDelegate (new RKItemDelegate (this, datamodel));
+	metaview->seRKItemDelegate (new RKItemDelegate (this, datamodel->getMetaModel ()));
 
 	metaview->setMinimumHeight (metaview->horizontalHeader ()->height ());
 	metaview->setMaximumHeight (metaview->rowHeight (0) * 5 + metaview->horizontalHeader ()->height () + 5);

Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.cpp
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.cpp	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.cpp	2007-11-11 21:28:08 UTC (rev 2200)
@@ -22,6 +22,7 @@
 #include <QHeaderView>
 
 #include "celleditor.h"
+#include "editformatdialog.h"
 #include "twintable.h"
 #include "rktextmatrix.h"
 #include "rkvareditmodel.h"
@@ -257,15 +258,25 @@
 QWidget* RKItemDelegate::createEditor (QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const {
 	RK_TRACE (EDITOR);
 
+	QWidget* ed = 0;
 	if (datamodel) {
-		CellEditor* ced = new CellEditor (parent);
-		ced->setFont (option.font);
-		connect (ced, SIGNAL (done(QWidget*,RKItemDelegate::EditorDoneReason)), this, SLOT (editorDone(QWidget*,RKItemDelegate::EditorDoneReason)));
-		return ced;
+		ed = new CellEditor (parent);
 	} else if (metamodel) {
+		int row = index.row ();
+		if (row == RKVarEditMetaModel::FormatRow) {
+			ed = new EditFormatDialogProxy (parent);
+		} else {
+			ed = new CellEditor (parent);
 #warning implement
+		}
 	}
 
+	if (ed) {
+		ed->setFont (option.font);
+		connect (ed, SIGNAL (done(QWidget*,RKItemDelegate::EditorDoneReason)), this, SLOT (editorDone(QWidget*,RKItemDelegate::EditorDoneReason)));
+		return ed;
+	}
+
 	RK_ASSERT (false);
 	return 0;
 }
@@ -276,6 +287,7 @@
 	if (!index.isValid ()) return;
 
 	if (datamodel) {
+		// do nothing. CellEditor will be intialized below
 		CellEditor* ced = static_cast<CellEditor*> (editor);
 		ced->setText (datamodel->data (index, Qt::EditRole).toString ());
 
@@ -284,12 +296,21 @@
 			labels = datamodel->getObject (index.column ())->getValueLabels ();
 		}
 		if (labels) ced->setValueLabels (labels);
-
 	} else if (metamodel) {
+		int row = index.row ();
+		if (row == RKVarEditMetaModel::FormatRow) {
+			EditFormatDialogProxy* fed = static_cast<EditFormatDialogProxy*> (editor);
+			fed->initialize (RKVariable::parseFormattingOptionsString (metamodel->data (index, Qt::EditRole).toString ()), metamodel->data (metamodel->index (RKVarEditMetaModel::FormatRow, index.column ())).toString ());
+		} else {
 #warning implement
+			CellEditor* ced = static_cast<CellEditor*> (editor);
+			ced->setText (metamodel->data (index, Qt::EditRole).toString ());
+		}
 	} else {
 		RK_ASSERT (false);
 	}
+
+
 }
 
 void RKItemDelegate::setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {
@@ -299,14 +320,24 @@
 
 	if (datamodel) {
 		RK_ASSERT (model == datamodel);
+		// real work is done down below
+	} else if (metamodel) {
+		RK_ASSERT (model == metamodel);
 
-		CellEditor* ced = static_cast<CellEditor*> (editor);
-		model->setData (index, ced->text (), Qt::EditRole);
-	} else if (metamodel) {
+		int row = index.row ();
+		if (row == RKVarEditMetaModel::FormatRow) {
+			EditFormatDialogProxy* fed = static_cast<EditFormatDialogProxy*> (editor);
+			model->setData (index, RKVariable::formattingOptionsToString (fed->getOptions ()), Qt::EditRole);
+			return;
+		} else {
 #warning implement
+		}
 	} else {
 		RK_ASSERT (false);
 	}
+
+	CellEditor* ced = static_cast<CellEditor*> (editor);
+	model->setData (index, ced->text (), Qt::EditRole);
 }
 
 bool RKItemDelegate::eventFilter (QObject* object, QEvent* event) {
@@ -330,7 +361,7 @@
 void RKItemDelegate::editorDone (QWidget* editor, RKItemDelegate::EditorDoneReason reason) {
 	RK_TRACE (EDITOR);
 
-	emit (commitData (editor));
+	if (reason != EditorReject) emit (commitData (editor));
 	emit (doCloseEditor (editor, reason));
 }
 

Modified: branches/KDE4_port/rkward/dataeditor/twintablemember.h
===================================================================
--- branches/KDE4_port/rkward/dataeditor/twintablemember.h	2007-11-11 18:20:46 UTC (rev 2199)
+++ branches/KDE4_port/rkward/dataeditor/twintablemember.h	2007-11-11 21:28:08 UTC (rev 2200)
@@ -56,6 +56,7 @@
 		EditorExitRight,
 		EditorExitUp,
 		EditorExitDown,
+		EditorReject,
 		EditorExit
 	};
 signals:


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