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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Nov 13 16:01:37 UTC 2012


Revision: 4432
          http://rkward.svn.sourceforge.net/rkward/?rev=4432&view=rev
Author:   tfry
Date:     2012-11-13 16:01:37 +0000 (Tue, 13 Nov 2012)
Log Message:
-----------
Unfortunately, this commit mixes some unrelated stuff...

- More work on the optionset
- Make code-display read-only
- Silence some (but unfortunately, not all) KTextEditor debug messages

Modified Paths:
--------------
    trunk/rkward/rkward/plugin/rkcomponent.cpp
    trunk/rkward/rkward/plugin/rkcomponent.h
    trunk/rkward/rkward/plugin/rkoptionset.cpp
    trunk/rkward/rkward/plugin/rkoptionset.h
    trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
    trunk/rkward/rkward/plugin/rkstandardcomponent.h
    trunk/rkward/rkward/plugin/rkstandardcomponentgui.cpp
    trunk/rkward/rkward/plugins/testing/optionset.xml
    trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
    trunk/rkward/rkward/windows/rkcommandeditorwindow.h

Modified: trunk/rkward/rkward/plugin/rkcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.cpp	2012-11-13 14:42:38 UTC (rev 4431)
+++ trunk/rkward/rkward/plugin/rkcomponent.cpp	2012-11-13 16:01:37 UTC (rev 4432)
@@ -304,6 +304,17 @@
 	return 0;
 }
 
+RKStandardComponent* RKComponent::topmostStandardComponent () {
+	RK_TRACE (PLUGIN);
+
+	RKComponent *p = this;
+	while (p->parentComponent ()) p = p->parentComponent ();
+	if (p->type () == RKComponent::ComponentStandard) return static_cast<RKStandardComponent*> (p);
+	// NOTE: currently, *only* standard components can be topmost
+	RK_ASSERT (false);
+	return 0;
+}
+
 void RKComponent::removeFromParent () {
 	RK_TRACE (PLUGIN);
 

Modified: trunk/rkward/rkward/plugin/rkcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.h	2012-11-13 14:42:38 UTC (rev 4431)
+++ trunk/rkward/rkward/plugin/rkcomponent.h	2012-11-13 16:01:37 UTC (rev 4432)
@@ -185,6 +185,8 @@
 	RKComponent *parentComponent () const { return _parent; };
 /** The standard component containing this component (if any). If @param id_adjust is given, it will be set to a relative path to the standard component. */
 	RKStandardComponent *standardComponent (QString *id_adjust=0);
+/** Like standardcomponent, but will return the topmost component in case of embedding. */
+	RKStandardComponent *topmostStandardComponent ();
 
 /** Find the id of this component. NOTE: this is slow. Better to store the id in the first place, if needed */
 	QString getIdInParent () const;

Modified: trunk/rkward/rkward/plugin/rkoptionset.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.cpp	2012-11-13 14:42:38 UTC (rev 4431)
+++ trunk/rkward/rkward/plugin/rkoptionset.cpp	2012-11-13 16:01:37 UTC (rev 4432)
@@ -36,7 +36,7 @@
 	RK_TRACE (PLUGIN);
 
 	XMLHelper *xml = XMLHelper::getStaticHelper ();
-	updating_from_contents = updating_from_storage = false;
+	updating = false;
 	last_known_status = Processing;
 
 	min_rows = xml->getIntAttribute (element, "min_rows", 0, DL_INFO);
@@ -64,8 +64,7 @@
 	builder->buildElement (xml->getChildElement (element, "content", DL_ERROR), contents_box, false);	// NOTE that parent widget != parent component, here, by intention. The point is that the display should not be disabled along with the contents
 	builder->makeConnections ();
 	addChild ("contents", contents_container);
-	contents_container->fetchPropertyValuesRecursive (&default_row_state);
-	contents_container->enablednessProperty ()->setBoolValue (false);	// no current row; Do this *after* fetching default values, however
+	connect (standardComponent (), SIGNAL (standardInitializationComplete()), this, SLOT (fetchDefaults()));
 
 	// create columns
 	XMLChildList options = xml->getChildElements (element, "option", DL_WARNING);
@@ -87,10 +86,7 @@
 		col_inf.column_name = id;
 		col_inf.external = external;
 		col_inf.governor = governor;
-#warning TODO: Do we have to wait for the parent component to settle before (re-)fetching defaults?
-#warning -------------- TODO ------------- Do not store defaults per column. Use only implicit defaults, instead.
-		if (e.hasAttribute ("default")) col_inf.default_value = xml->getStringAttribute (e, "default", QString (), DL_ERROR);
-		else if (!governor.isEmpty ()) col_inf.default_value = contents_container->fetchStringValue (governor);
+		if (external && e.hasAttribute ("default")) col_inf.default_value = xml->getStringAttribute (e, "default", QString (), DL_ERROR);
 
 		RKComponentPropertyStringList *column_property = new RKComponentPropertyStringList (this, false);
 		addChild (id, column_property);
@@ -172,6 +168,13 @@
 	RK_TRACE (PLUGIN);
 }
 
+void RKOptionSet::fetchDefaults () {
+	RK_TRACE (PLUGIN);
+	RK_ASSERT (default_row_state.isEmpty ());
+	contents_container->fetchPropertyValuesRecursive (&default_row_state);
+	contents_container->enablednessProperty ()->setBoolValue (rowCount () > 0);	// no current row; Do this *after* fetching default values, however. Otherwise most values will *not* be read, as the element is disabled
+}
+
 RKComponent *RKOptionSet::createDisplay (bool show_index, QWidget *parent) {
 	RK_TRACE (PLUGIN);
 
@@ -202,6 +205,8 @@
 void RKOptionSet::addRow () {
 	RK_TRACE (PLUGIN);
 
+	storeRowSerialization (active_row);
+
 	int row = active_row + 1;	// append feels more natural than insert, here
 	int nrows = rowCount ();
 	if (row <= 0) row = nrows;
@@ -209,6 +214,7 @@
 
 	if (display) model->beginInsertRows (QModelIndex (), row, row);
 	// adjust values
+	updating = true;
 	QMap<RKComponentPropertyStringList *, ColumnInfo>::iterator it = column_map.begin ();
 	for (; it != column_map.end (); ++it) {
 		RKComponentPropertyStringList* col = it.key ();
@@ -217,6 +223,7 @@
 		values.insert (row, getDefaultValue (column, row));
 		col->setValues (values);
 	}
+	updating = false;
 
 	// adjust status info
 	RowInfo ri (default_row_state);
@@ -227,9 +234,8 @@
 	++n_invalid_rows;
 
 	row_count->setIntValue (nrows + 1);
-	storeRowSerialization (active_row);
 	current_row->setIntValue (active_row = row);
-	setContentsForRow (row);
+	setContentsForRow (active_row);
 	if (display) model->endInsertRows ();
 
 	changed ();
@@ -247,6 +253,7 @@
 	RK_ASSERT (!keycolumn);
 
 	if (display) model->beginRemoveRows (QModelIndex (), row, row);
+	updating = true;
 	// adjust values
 	QMap<RKComponentPropertyStringList *, ColumnInfo>::iterator it = column_map.begin ();
 	for (; it != column_map.end (); ++it) {
@@ -255,6 +262,7 @@
 		values.removeAt (row);
 		col->setValues (values);
 	}
+	updating = false;
 
 	// adjust status info
 	if (!rows[row].valid) --n_invalid_rows;
@@ -317,8 +325,8 @@
 
 	int row = active_row;
 	if (row < 0) return;
-	if (updating_from_storage) return;
-	updating_from_contents = true;
+	if (updating) return;
+	updating = true;
 
 	QList<RKComponentPropertyStringList *> cols = columns_to_update.values (property);
 	for (int i = 0; i < cols.size (); ++i) {
@@ -332,20 +340,20 @@
 		}
 	}
 
-	updating_from_contents = false;
+	updating = false;
 }
 
 // This function is called, when a column of the set is changed, typically from external logic
 void RKOptionSet::columnPropertyChanged (RKComponentPropertyBase *property) {
 	RK_TRACE (PLUGIN);
 
-	if (updating_from_contents) return;
+	if (updating) return;
 
 	RKComponentPropertyStringList *target = static_cast<RKComponentPropertyStringList *> (property);
 	RK_ASSERT (column_map.contains (target));
 	ColumnInfo& ci = column_map[target];
 	if (!ci.external) {
-		RK_ASSERT (false);
+		RK_DO (qDebug ("Column %s was touched externally, although it is not marked as external", qPrintable (ci.column_name)), PLUGIN, DL_ERROR);
 		return;
 	}
 
@@ -378,6 +386,7 @@
 
 	// get state of current row (which may subsequently be moved or even deleted
 	storeRowSerialization (active_row);
+	updating = true;
 
 	// update all columns
 	QMap<RKComponentPropertyStringList *, ColumnInfo>::iterator it = column_map.begin ();
@@ -440,6 +449,7 @@
 	current_row->setIntValue (active_row = activate_row);
 	if (model) model->triggerReset ();
 	setContentsForRow (active_row);
+	updating = false;
 	changed ();
 }
 
@@ -448,7 +458,9 @@
 
 	const ColumnInfo &ci = column_map[column];
 	if (!ci.external) return;
+	if (ci.governor.isEmpty ()) return;
 
+	updating = true;
 	QString dummy;
 	RKComponentBase *governor = contents_container->lookupComponent (ci.governor, &dummy);
 	if (governor && governor->isProperty ()) {
@@ -463,6 +475,7 @@
 		RK_DO (qDebug ("Lookup error while trying to restore row %d of optionset: %s. Remainder: %s", row, qPrintable (ci.governor), qPrintable (dummy)), PLUGIN, DL_WARNING);
 		RK_ASSERT (false);
 	}
+	updating = false;
 }
 
 void RKOptionSet::setContentsForRow (int row) {

Modified: trunk/rkward/rkward/plugin/rkoptionset.h
===================================================================
--- trunk/rkward/rkward/plugin/rkoptionset.h	2012-11-13 14:42:38 UTC (rev 4431)
+++ trunk/rkward/rkward/plugin/rkoptionset.h	2012-11-13 16:01:37 UTC (rev 4432)
@@ -56,6 +56,7 @@
 	void addRow ();
 	void removeRow ();
 	void currentRowChanged ();
+	void fetchDefaults ();
 private:
 friend class RKOptionSetDisplayModel;
 	int rowCount () const { return row_count->intValue (); };
@@ -110,8 +111,7 @@
 	int min_rows_if_any;
 	int max_rows;
 
-	bool updating_from_contents;
-	bool updating_from_storage;
+	bool updating;
 /** When keys in the key column change, all other columns have to be updated, accordingly. */
 	void handleKeycolumnUpdate ();
 /** Sets the contents from the values in given row */
@@ -137,8 +137,6 @@
 	RKOptionSet *set;
 private slots:
 	void doResetNow ();
-signals:
-	void rowChanged (int new_row);
 };
 
 #endif

Modified: trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkstandardcomponent.cpp	2012-11-13 14:42:38 UTC (rev 4431)
+++ trunk/rkward/rkward/plugin/rkstandardcomponent.cpp	2012-11-13 16:01:37 UTC (rev 4432)
@@ -345,6 +345,7 @@
 		QTimer::singleShot (0, gui, SLOT (show ()));
 	}
 	changed ();
+	standardInitializationComplete ();
 }
 
 RKComponentBase::ComponentStatus RKStandardComponent::recursiveStatus () {

Modified: trunk/rkward/rkward/plugin/rkstandardcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkstandardcomponent.h	2012-11-13 14:42:38 UTC (rev 4431)
+++ trunk/rkward/rkward/plugin/rkstandardcomponent.h	2012-11-13 16:01:37 UTC (rev 4432)
@@ -2,7 +2,7 @@
                           rkstandardcomponent  -  description
                              -------------------
     begin                : Sun Feb 19 2006
-    copyright            : (C) 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
+    copyright            : (C) 2006, 2007, 2009, 2010, 2012 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -81,6 +81,8 @@
 
 /** Return the GUI-scripting handler (creating it, if needed) */
 	RKComponentScriptingProxy* scriptingProxy ();
+signals:
+	void standardInitializationComplete ();
 public slots:
 /** this gets called by the script-backend, when it's done. Might enable the
 	submit button or destruct the plugin. */

Modified: trunk/rkward/rkward/plugin/rkstandardcomponentgui.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkstandardcomponentgui.cpp	2012-11-13 14:42:38 UTC (rev 4431)
+++ trunk/rkward/rkward/plugin/rkstandardcomponentgui.cpp	2012-11-13 16:01:37 UTC (rev 4432)
@@ -127,7 +127,8 @@
 	if (enslaved) toggle_code_button->hide ();
 	
 	// code display
-	code_display = new RKCommandEditorWindow (this, true);
+	code_display = new RKCommandEditorWindow (this, true, false);
+	code_display->setReadOnly (true);
 	code_display->setMinimumHeight (RKSettingsModulePlugins::defaultCodeHeight ());
 	code_display->hide ();
 
@@ -337,7 +338,8 @@
 		vbox->setContentsMargins (0, 0, 0, 0);
 		QLabel *label = new QLabel (i18n ("Below you can see the command(s) corresponding to the settings you made. Click 'Submit' to run the command(s)."), last_page);
 		label->setWordWrap (true);
-		code_display = new RKCommandEditorWindow (last_page, true);
+		code_display = new RKCommandEditorWindow (last_page, true, false);
+		code_display->setReadOnly (true);
 		vbox->addWidget (label);
 		vbox->addWidget (code_display);
 	}

Modified: trunk/rkward/rkward/plugins/testing/optionset.xml
===================================================================
--- trunk/rkward/rkward/plugins/testing/optionset.xml	2012-11-13 14:42:38 UTC (rev 4431)
+++ trunk/rkward/rkward/plugins/testing/optionset.xml	2012-11-13 16:01:37 UTC (rev 4432)
@@ -48,7 +48,7 @@
 					</content>
 					<option id="object" external="true"/>
 					<option id="objshort" label="Object" external="true"/>
-					<option id="summary" connect="summary.text"/>
+					<option id="summary2" connect="summary.text"/>
 				</optionset>
 			</tab>
 			<tab label="Driven set">
@@ -65,13 +65,13 @@
 								<optiondisplay index="false"/>
 								<checkbox id="dummybox" label="This dummy option is always disabled"/>
 								<input id="commenta" label="Comment A"/>
-								<input id="commentb" label="Comment B"/>
+								<input id="commentb" label="Comment B" initial="This is a default entry. Change it, if you like."/>
 							</frame>
 						</content>
 						<option id="var" label="test" external="true"/>
 						<option id="varname" label="Varname" external="true"/>
 						<option id="ca" label="Comment A" connect="commenta.text"/>
-						<option id="cb" connect="commentb.text" default="This is a default entry. Change it, if you like."/>
+						<option id="cb" connect="commentb.text"/>
 					</optionset>
 				</row>
 			</tab>

Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp	2012-11-13 14:42:38 UTC (rev 4431)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp	2012-11-13 16:01:37 UTC (rev 4432)
@@ -82,7 +82,7 @@
 #define GET_HELP_URL 1
 #define NUM_BLOCK_RECORDS 6
 
-RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, bool use_r_highlighting) : RKMDIWindow (parent, RKMDIWindow::CommandEditorWindow) {
+RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, bool use_r_highlighting, bool use_codehinting) : RKMDIWindow (parent, RKMDIWindow::CommandEditorWindow) {
 	RK_TRACE (COMMANDEDITOR);
 
 	KTextEditor::Editor* editor = KTextEditor::editor("katepart");
@@ -128,18 +128,20 @@
 	hinter = 0;
 	if (use_r_highlighting) {
 		RKCommandHighlighter::setHighlighting (m_doc, RKCommandHighlighter::RScript);
-		cc_iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (m_view);
-		if (cc_iface) {
-			cc_iface->setAutomaticInvocationEnabled (true);
-			completion_model = new RKCodeCompletionModel (this);
-			completion_timer = new QTimer (this);
-			completion_timer->setSingleShot (true);
-			connect (completion_timer, SIGNAL (timeout ()), this, SLOT (tryCompletion()));
-			connect (m_doc, SIGNAL (textChanged (KTextEditor::Document*)), this, SLOT (tryCompletionProxy (KTextEditor::Document*)));
-		} else {
-			RK_ASSERT (false);
+		if (use_codehinting) {
+			cc_iface = qobject_cast<KTextEditor::CodeCompletionInterface*> (m_view);
+			if (cc_iface) {
+				cc_iface->setAutomaticInvocationEnabled (true);
+				completion_model = new RKCodeCompletionModel (this);
+				completion_timer = new QTimer (this);
+				completion_timer->setSingleShot (true);
+				connect (completion_timer, SIGNAL (timeout ()), this, SLOT (tryCompletion()));
+				connect (m_doc, SIGNAL (textChanged (KTextEditor::Document*)), this, SLOT (tryCompletionProxy (KTextEditor::Document*)));
+			} else {
+				RK_ASSERT (false);
+			}
+			hinter = new RKFunctionArgHinter (this, m_view);
 		}
-		hinter = new RKFunctionArgHinter (this, m_view);
 	}
 
 #if KDE_IS_VERSION(4,5,0)
@@ -603,6 +605,7 @@
 // KDE4 TODO: This may no longer be needed, if the katepart gets fixed not to abort completions when the range
 // contains dots or other special characters
 	KTextEditor::Cursor c = m_view->cursorPosition();
+	if (!c.isValid ()) return QString ();
 	uint para=c.line(); uint cursor_pos=c.column();
 
 	QString current_line = m_doc->line (para);
@@ -613,6 +616,7 @@
 
 #if KDE_IS_VERSION(4,2,0)
 KTextEditor::Range RKCodeCompletionModel::completionRange (KTextEditor::View *view, const KTextEditor::Cursor &position) {
+	if (!position.isValid ()) return KTextEditor::Range ();
 	QString current_line = view->document ()->line (position.line ());
 	int start;
 	int end;
@@ -638,7 +642,8 @@
 	RKCommonFunctions::getCurrentSymbolOffset (current_line, cursor_pos, false, &start, &end);
 
 	KTextEditor::Range range = KTextEditor::Range (para, start, para, end);
-	QString word = m_doc->text (range);
+	QString word;
+	if (range.isValid ()) m_doc->text (range);
 	if (current_line.lastIndexOf ("#", cursor_pos) >= 0) word.clear ();	// do not hint while in comments
 	if (word.length () >= RKSettingsModuleCommandEditor::completionMinChars ()) {
 		completion_model->updateCompletionList (word);

Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.h	2012-11-13 14:42:38 UTC (rev 4431)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.h	2012-11-13 16:01:37 UTC (rev 4432)
@@ -2,7 +2,7 @@
                           rkcommandeditorwindow  -  description
                              -------------------
     begin                : Mon Aug 30 2004
-    copyright            : (C) 2004, 2006, 2007, 2009, 2010, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006, 2007, 2009, 2010, 2011, 2012 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -160,7 +160,7 @@
 public:
 /** constructor
 @param use_r_highlighting Initialize the view to use R syntax highlighting. Use, if you're going to edit an R syntax file */
-	RKCommandEditorWindow (QWidget *parent = 0, bool use_r_highlighting=true);
+	RKCommandEditorWindow (QWidget *parent = 0, bool use_r_highlighting=true, bool use_codehinting=true);
 /** destructor */
 	~RKCommandEditorWindow ();
 /** open given URL. 

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