[rkward-cvs] SF.net SVN: rkward:[4017] trunk/rkward/rkward/windows
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Fri Nov 4 19:39:00 UTC 2011
Revision: 4017
http://rkward.svn.sourceforge.net/rkward/?rev=4017&view=rev
Author: tfry
Date: 2011-11-04 19:39:00 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
Cache info in object name completion model
Modified Paths:
--------------
trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
trunk/rkward/rkward/windows/rkcommandeditorwindow.h
Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp 2011-11-04 19:38:29 UTC (rev 4016)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp 2011-11-04 19:39:00 UTC (rev 4017)
@@ -972,17 +972,17 @@
RObjectList::getObjectList ()->findObjectsMatching (symbol, &map);
int count = map.size ();
- list.clear ();
- list_names.clear ();
- list.reserve (count);
- list_names.reserve (count);
- // this is silly, but we need an int indexable storage, so we copy the map to a list
+ icons.clear ();
+ names.clear ();
+#if QT_VERSION >= 0x040700
+ icons.reserve (count);
+ names.reserve (count);
+#endif
+ // copy the map to two lists. For one thing, we need an int indexable storage, for another, caching this information is safer
+ // in case objects are removed while the completion mode is active.
for (RObject::RObjectSearchMap::const_iterator it = map.constBegin (); it != map.constEnd (); ++it) {
- list.append (it.value ());
- // the second list is used to store the name that should be used for completion.
- // This may be object->getBaseName() or object->getFullName () depending on whether the object is
- // masked or not.
- list_names.append (it.key ());
+ icons.append (RKStandardIcons::iconForObject (it.value ()));
+ names.append (it.value ()->getBaseName ());
}
setRowCount (count);
@@ -1006,9 +1006,9 @@
void RKCodeCompletionModel::executeCompletionItem (KTextEditor::Document *document, const KTextEditor::Range &word, int row) const {
RK_TRACE (COMMANDEDITOR);
- RK_ASSERT (list_names.size () > row);
+ RK_ASSERT (names.size () > row);
- document->replaceText (word, list_names[row]);
+ document->replaceText (word, names[row]);
}
QVariant RKCodeCompletionModel::data (const QModelIndex& index, int role) const {
@@ -1017,18 +1017,14 @@
int row = index.row ();
if (index.parent ().isValid ()) return QVariant ();
- if (row >= list.count ()) return QVariant ();
- RObject* object = list[row];
- RK_ASSERT (object);
-
if ((role == Qt::DisplayRole) || (role==KTextEditor::CodeCompletionModel::CompletionRole)) {
if (col == KTextEditor::CodeCompletionModel::Name) {
- return (object->getBaseName ());
+ return (names.value (row));
}
} else if (role == Qt::DecorationRole) {
if (col == KTextEditor::CodeCompletionModel::Icon) {
- return RKStandardIcons::iconForObject (object);
+ return (icons.value (row));
}
}
Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.h 2011-11-04 19:38:29 UTC (rev 4016)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.h 2011-11-04 19:39:00 UTC (rev 4017)
@@ -136,10 +136,10 @@
void executeCompletionItem (KTextEditor::Document *document, const KTextEditor::Range &word, int row) const;
QVariant data (const QModelIndex& index, int role=Qt::DisplayRole) const;
- bool isEmpty () const { return list.isEmpty (); };
+ bool isEmpty () const { return names.isEmpty (); };
private:
- QVector<RObject*> list;
- QVector<QString> list_names;
+ QList<QIcon> icons;
+ QStringList names;
QString current_symbol;
RKCommandEditorWindow *command_editor;
};
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