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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Oct 25 21:19:03 UTC 2007


Revision: 2133
          http://rkward.svn.sourceforge.net/rkward/?rev=2133&view=rev
Author:   tfry
Date:     2007-10-25 14:19:02 -0700 (Thu, 25 Oct 2007)

Log Message:
-----------
Remove Qt3 support code in RKHelpSearchWindow

Modified Paths:
--------------
    branches/KDE4_port/TODO_KDE4
    branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp
    branches/KDE4_port/rkward/windows/rkcommandeditorwindow.h
    branches/KDE4_port/rkward/windows/rkhelpsearchwindow.cpp
    branches/KDE4_port/rkward/windows/rkhelpsearchwindow.h

Modified: branches/KDE4_port/TODO_KDE4
===================================================================
--- branches/KDE4_port/TODO_KDE4	2007-10-25 18:25:14 UTC (rev 2132)
+++ branches/KDE4_port/TODO_KDE4	2007-10-25 21:19:02 UTC (rev 2133)
@@ -29,7 +29,8 @@
 	-* the 'X' icon for closing a tab (Ctl-W) is absent
 
 rkcommandeditorwindow
-	- polish code completion (e.g. hide window, when there are no completions)
+	- code completion
+		- probably we can trim down the completion widget by providing custom headerData()? (Low priority)
 	- placement of menu options?
 
 rkward

Modified: branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp	2007-10-25 18:25:14 UTC (rev 2132)
+++ branches/KDE4_port/rkward/windows/rkcommandeditorwindow.cpp	2007-10-25 21:19:02 UTC (rev 2133)
@@ -278,13 +278,14 @@
 	if ((end - start) >= RKSettingsModuleCommandEditor::completionMinChars ()) {
 		KTextEditor::Range range (para, start, para, end);
 
-		if (iface->isCompletionActive ()) {
-			completion_model->completionInvoked (m_view, range, KTextEditor::CodeCompletionModel::ManualInvocation);
+		completion_model->updateCompletionList (m_doc->text (range));
+		if (completion_model->isEmpty ()) {
+			iface->abortCompletion ();
 		} else {
-			iface->startCompletion (range, completion_model);
+			if (!iface->isCompletionActive ()) {
+				iface->startCompletion (range, completion_model);
+			}
 		}
-#warning TODO: flicker when no matches. Nag Kate devels? Remove?
-		if (!completion_model->rowCount ()) iface->abortCompletion ();
 	} else {
 		iface->abortCompletion ();
 	}
@@ -513,25 +514,32 @@
 	RK_TRACE (COMMANDEDITOR);
 }
 
-void RKCodeCompletionModel::completionInvoked (KTextEditor::View *view, const KTextEditor::Range &range, InvocationType) {
+void RKCodeCompletionModel::updateCompletionList (const QString& symbol) {
 	RK_TRACE (COMMANDEDITOR);
-qDebug ("invoked");
 
-	QString current_symbol = view->document ()->text (range);
+	if (current_symbol == symbol) return;	// already up to date
+
 	RObject::RObjectMap map;
-	RObjectList::getObjectList ()->findObjectsMatching (current_symbol, &map);
+	RObjectList::getObjectList ()->findObjectsMatching (symbol, &map);
 
 	list.clear ();
 	// this is silly, but we need an int indexable storage, so we copy the map to a list
 	for (RObject::RObjectMap::const_iterator it = map.constBegin (); it != map.constEnd (); ++it) {
 		list.append (it.data ());
 	}
-qDebug ("%d", list.count ());
+
 	setRowCount (list.count ());
+	current_symbol = symbol;
 
 	reset ();
 }
 
+void RKCodeCompletionModel::completionInvoked (KTextEditor::View *view, const KTextEditor::Range &range, InvocationType) {
+	RK_TRACE (COMMANDEDITOR);
+
+	updateCompletionList (view->document ()->text (range));
+}
+
 void RKCodeCompletionModel::executeCompletionItem (KTextEditor::Document *document, const KTextEditor::Range &word, int row) const {
 	RK_TRACE (COMMANDEDITOR);
 

Modified: branches/KDE4_port/rkward/windows/rkcommandeditorwindow.h
===================================================================
--- branches/KDE4_port/rkward/windows/rkcommandeditorwindow.h	2007-10-25 18:25:14 UTC (rev 2132)
+++ branches/KDE4_port/rkward/windows/rkcommandeditorwindow.h	2007-10-25 21:19:02 UTC (rev 2133)
@@ -76,11 +76,16 @@
 public:
 	RKCodeCompletionModel (KTextEditor::View* parent);
 	~RKCodeCompletionModel ();
+
+	void updateCompletionList (const QString& symbol);
 	void completionInvoked (KTextEditor::View *view, const KTextEditor::Range &range, InvocationType);
 	void executeCompletionItem (KTextEditor::Document *document, const KTextEditor::Range &word, int row) const;
 	QVariant data (const QModelIndex& index, int role=Qt::DisplayRole) const;
+
+	bool isEmpty () { return list.isEmpty (); };
 private:
 	QList<RObject*> list;
+	QString current_symbol;
 };
 
 class QTimer;

Modified: branches/KDE4_port/rkward/windows/rkhelpsearchwindow.cpp
===================================================================
--- branches/KDE4_port/rkward/windows/rkhelpsearchwindow.cpp	2007-10-25 18:25:14 UTC (rev 2132)
+++ branches/KDE4_port/rkward/windows/rkhelpsearchwindow.cpp	2007-10-25 21:19:02 UTC (rev 2133)
@@ -23,7 +23,7 @@
 
 #include <qcheckbox.h>
 #include <qcombobox.h>
-#include <q3listview.h>
+#include <QTreeView>
 #include <qlineedit.h>
 #include <qlayout.h>
 #include <qlabel.h>
@@ -44,6 +44,12 @@
 #define HELP_SEARCH 2
 #define GET_INSTALLED_PACKAGES 3
 
+// result columns
+#define COL_TOPIC 0
+#define COL_TITLE 1
+#define COL_PACKAGE 2
+#define COL_COUNT 3
+
 RKHelpSearchWindow* RKHelpSearchWindow::main_help_search = 0;
 
 RKHelpSearchWindow::RKHelpSearchWindow (QWidget *parent, bool tool_window, const char *name) : RKMDIWindow (parent, SearchHelpWindow, tool_window, name) {
@@ -75,11 +81,10 @@
 	QHBoxLayout* fields_packages_layout = new QHBoxLayout (main_settings_layout, RKGlobals::spacingHint ());
 	fields_packages_layout->setContentsMargins (0, 0, 0, 0);
 	fieldsList = new QComboBox (false, this);
-	// HACK the sequence of options is hardcoded, do not modify
-	fieldsList->insertItem (i18n("All"));
-	fieldsList->insertItem (i18n("All but keywords"));
-	fieldsList->insertItem (i18n("Keywords"));
-	fieldsList->insertItem (i18n("Title"));
+	fieldsList->addItem (i18n ("All"), "c(\"alias\", \"concept\", \"title\",\"keyword\")");
+	fieldsList->addItem (i18n ("All but keywords"), "c(\"alias\", \"concept\", \"title\")");
+	fieldsList->addItem (i18n ("Keywords"), "c(\"keyword\")");
+	fieldsList->addItem (i18n ("Title"), "c(\"title\")");
 	fields_packages_layout->addWidget (fieldsList);
 
 	label = new QLabel (i18n ("Package:"), this);
@@ -103,12 +108,12 @@
 	connect (findButton, SIGNAL (clicked ()), this, SLOT (slotFindButtonClicked ()));
 	selection_layout->addWidget (findButton);
 
-	resultsList = new Q3ListView (this);
-	resultsList->addColumn (i18n ("Topic"));
-	resultsList->addColumn (i18n ("Title"));
-	resultsList->addColumn (i18n ("Package"));
-	connect (resultsList, SIGNAL (doubleClicked (Q3ListViewItem*, const QPoint&, int)), this, SLOT (slotResultsListDblClicked (Q3ListViewItem*, const QPoint&, int)));
-	main_layout->addWidget (resultsList);
+	results = new RKHelpSearchResultsModel (this);
+	results_view = new QTreeView (this);
+	results_view->setRootIsDecorated (false);
+	results_view->setModel (results);
+	connect (results_view, SIGNAL (doubleClicked(const QModelIndex&)), this, SLOT (resultDoubleClicked(const QModelIndex&)));
+	main_layout->addWidget (results_view);
 
 	RKGlobals::rInterface ()->issueCommand (".rk.get.installed.packages ()[[1]]", RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, GET_INSTALLED_PACKAGES, 0);
 
@@ -159,21 +164,11 @@
 	}
 	
 	QString package = "NULL";
-	if (packagesList->currentItem ()!=0) {
-		package="\"";
-		package.append (packagesList->currentText ());
-		package.append ("\"");
+	if (packagesList->currentIndex () != 0) {
+		package= "\"" +	packagesList->currentText () + "\"";
 	}
 
-	// HACK the sequence of options is hardcoded, do not modify
-	QString fields;
-	
-	switch (fieldsList->currentItem ()) {
-		case 1: fields = "c(\"alias\", \"concept\", \"title\")";break;
-		case 2: fields = "c(\"keyword\")";break;
-		case 3: fields = "c(\"title\")";break;
-		default: fields = "c(\"alias\", \"concept\", \"title\",\"keyword\")";
-	}
+	QString fields = fieldsList->itemData (fieldsList->currentIndex ()).toString ();
 
 	QString s = ".rk.get.search.results (\"" + field->currentText () + "\",agrep=" + agrep + ", ignore.case=" + ignoreCase + ", package=" + package + ", fields=" + fields +")";
 	
@@ -182,38 +177,40 @@
 	field->insertItem (field->currentText ());
 }
 
-void RKHelpSearchWindow::slotResultsListDblClicked (Q3ListViewItem * item, const QPoint &, int) {
+void RKHelpSearchWindow::resultDoubleClicked (const QModelIndex& index) {
 	RK_TRACE (APP);
-	if (item == NULL) {
-		return;
-	}
-	if (item->text(0).isEmpty ()) {
-		return;
-	}
+
+	if (!index.isValid ()) return;
+
+	int row = index.row ();
+	QString topic = results->data (results->index (row, COL_TOPIC)).toString ();
+	QString package = results->data (results->index (row, COL_PACKAGE)).toString ();
+
+	if (topic.isEmpty ()) return;
 	
-	QString s="help(\"";
-	s.append (item->text (0));
-	s.append ("\", htmlhelp=TRUE, package= \"");
-	s.append (item->text (2));
-	s.append ("\")");
+	QString command = "help(\"" + topic + "\", htmlhelp=TRUE, package= \"" + package + "\")";
 	
-	RKGlobals::rInterface ()->issueCommand (s, RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, GET_HELP_URL, 0);
+	RKGlobals::rInterface ()->issueCommand (command, RCommand::App | RCommand::Sync | RCommand::GetStringVector, i18n ("Show help for %1 in package %2", topic, package), this, GET_HELP_URL);
 }
 
 void RKHelpSearchWindow::rCommandDone (RCommand *command) {
 	RK_TRACE (APP);
-	KUrl url;
 	if (command->getFlags () == HELP_SEARCH) {
-		resultsList->clear ();
 		RK_ASSERT ((command->getDataLength () % 3) == 0);
-		int count = (command->getDataLength () / 3);
-		for (int i=0; i < count; ++i) {
-			new Q3ListViewItem (resultsList, command->getStringVector ()[i], command->getStringVector ()[count + i], command->getStringVector ()[2*count + i]);
-		}
+		RK_ASSERT (command->getDataType () == RData::StringVector);
+
+		results->setResults (command->getStringVector (), command->getDataLength () / 3);
+		command->detachData ();		// now owned by the model
+
+		for (int i = 0; i < COL_COUNT; ++i) results_view->resizeColumnToContents (i);
 		setEnabled(true);
 	} else if (command->getFlags () == GET_HELP_URL) {
-		RK_ASSERT (command->getDataLength ());
-		url.setPath(command->getStringVector ()[0]);
+		KUrl url;
+
+		if (command->getDataLength ()) {
+			RK_ASSERT (command->getDataType () == RData::StringVector);
+			url.setPath(command->getStringVector ()[0]);
+		}
 		if (QFile::exists (url.path ())) {
 			RKWardMainWindow::getMain ()->openHTML (url);
 			return;
@@ -231,4 +228,80 @@
 	}
 }
 
+//////////////// RKHelpResultsModel ////////////////
+
+RKHelpSearchResultsModel::RKHelpSearchResultsModel (QObject *parent) : QAbstractTableModel (parent) {
+	RK_TRACE (APP);
+
+	results = 0;
+	result_count = 0;
+}
+
+RKHelpSearchResultsModel::~RKHelpSearchResultsModel () {
+	RK_TRACE (APP);
+
+	delete [] results;
+}
+
+void RKHelpSearchResultsModel::setResults (QString* new_results, int new_result_count) {
+	RK_TRACE (APP);
+
+	delete [] results;
+	results = new_results;
+	result_count = new_result_count;
+
+	reset ();
+}
+
+int RKHelpSearchResultsModel::rowCount (const QModelIndex& parent) const {
+	// don't trace
+	if (parent.isValid ()) return 0;
+	return result_count;
+}
+
+int RKHelpSearchResultsModel::columnCount (const QModelIndex& parent) const {
+	// don't trace
+	if (parent.isValid ()) return 0;
+	return COL_COUNT;
+}
+
+QVariant RKHelpSearchResultsModel::data (const QModelIndex& index, int role) const {
+	// don't trace
+
+	// easier typing
+	int row = index.row ();
+	int col = index.column ();
+	if (results) {
+		if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
+			if (row < result_count) {
+				if (col < COL_COUNT) {
+					return results[row + col * result_count];
+				} else {
+				
+				}
+			} else {
+				RK_ASSERT (false);
+			}
+		}
+	} else {
+		RK_ASSERT (false);
+	}
+
+	return QVariant ();
+}
+
+QVariant RKHelpSearchResultsModel::headerData (int section, Qt::Orientation orientation, int role) const {
+	// don't trace
+
+	if (orientation == Qt::Horizontal) {
+		if (role == Qt::DisplayRole) {
+			if (section == COL_TOPIC) return (i18n ("Topic"));
+			if (section == COL_TITLE) return (i18n ("Title"));
+			if (section == COL_PACKAGE) return (i18n ("Package"));
+		}
+	}
+
+	return QVariant ();
+}
+
 #include "rkhelpsearchwindow.moc"

Modified: branches/KDE4_port/rkward/windows/rkhelpsearchwindow.h
===================================================================
--- branches/KDE4_port/rkward/windows/rkhelpsearchwindow.h	2007-10-25 18:25:14 UTC (rev 2132)
+++ branches/KDE4_port/rkward/windows/rkhelpsearchwindow.h	2007-10-25 21:19:02 UTC (rev 2133)
@@ -19,17 +19,17 @@
 #define RKHELPSEARCHWINDOW_H
 
 #include <qwidget.h>
-//Added by qt3to4:
-#include <QFocusEvent>
+#include <QAbstractTableModel>
 
 #include "../rbackend/rcommandreceiver.h"
 #include "rkmdiwindow.h"
 
+class QFocusEvent;
 class QComboBox;
 class QCheckBox;
 class QPushButton;
-class Q3ListView;
-class Q3ListViewItem;
+class RKHelpSearchResultsModel;
+class QTreeView;
 
 class RCommandChain;
 
@@ -51,7 +51,7 @@
 	static RKHelpSearchWindow *mainHelpSearch () { return main_help_search; };
 public slots:
 	void slotFindButtonClicked();
-	void slotResultsListDblClicked (Q3ListViewItem *item, const QPoint &, int);
+	void resultDoubleClicked (const QModelIndex& index);
 protected:
 /** reimplemnented from QWidget to make the input focus default to the input field */
 	void focusInEvent (QFocusEvent *e);
@@ -62,9 +62,30 @@
 	QCheckBox* caseSensitiveCheckBox;
 	QCheckBox* fuzzyCheckBox;
 	QPushButton* findButton;
-	Q3ListView* resultsList;
+	QTreeView* results_view;
+	RKHelpSearchResultsModel* results;
+
 friend class RKWardMainWindow;
 	static RKHelpSearchWindow *main_help_search;
 };
 
+/** An item model meant for use by RKHelpSearchWindow. Since it is fairly specialized, it is unlikely to be of any use in any other context.
+ at author Thomas Friedrichsmeier */
+class RKHelpSearchResultsModel : public QAbstractTableModel {
+public:
+	RKHelpSearchResultsModel (QObject *parent);
+	~RKHelpSearchResultsModel ();
+
+/** Set the results. The model will assume ownership of the results */
+	void setResults (QString* new_results, int new_result_count);
+
+	int rowCount (const QModelIndex& parent=QModelIndex()) const;
+	int columnCount (const QModelIndex& parent=QModelIndex()) const;
+	QVariant data (const QModelIndex& index, int role=Qt::DisplayRole) const;
+	QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const;
+private:
+	QString* results;
+	int result_count;
+};
+
 #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