bool RKObjectListViewSettings::filterAcceptsRow (int source_row, const QModelIndex& source_parent) const { // RK_TRACE (APP); // So I tried to use a KRecursiveFilterProxyModel, but // a) we don't really want recursion to the full depth. Thus limiting it, here. // b) While we don't handle insertions / removals of source indices in the presence of a filter, correctly, with KRecursiveFilterProxyModel // I got crashes on this (arguably with the depth-limit in place) if (acceptRow (source_row, source_parent)) return true; RObject *parent = static_cast<RObject*> (source_parent.internalPointer ()); if (!parent) { RK_ASSERT (parent); // should have been accepted, above return true; } RObject *object = parent->findChildByObjectModelIndex (source_row); if (!object) { RK_ASSERT (object); // should have been accepted, above RK_DEBUG (APP, DL_ERROR, "row %d of %d in %s", source_row, sourceModel ()->rowCount (source_parent), qPrintable (parent->getShortName ())); return false; } if (object->isType (RObject::ToplevelEnv | RObject::Workspace) || ((depth_limit > 0) && parent->isType (RObject::ToplevelEnv | RObject::Workspace))) { QModelIndex source_index = sourceModel ()->index (source_row, 0, source_parent); for (int row = 0, rows = sourceModel()->rowCount (source_index); row < rows; ++row) { if (filterAcceptsRow (row, source_index)) return true; } } return false; }
bool RKObjectListViewSettings::acceptRow (int source_row, const QModelIndex& source_parent) const { // RK_TRACE (APP); // always show the root item if (!source_parent.isValid ()) return true; RObject* object = static_cast<RObject*> (source_parent.internalPointer ()); // always show global env and search path if (!object) return true; if (!object->findChildByObjectModelIndex (source_row)) { return true; } object = object->findChildByObjectModelIndex (source_row); RK_ASSERT (object); if (!persistent_settings[ShowObjectsHidden]) { if (object->getShortName ().startsWith ('.')) return false; if (object == reinterpret_cast<RObject*> (RObjectList::getObjectList ()->orphanNamespacesObject ())) return false; } if (hide_functions && object->isType (RObject::Function)) return false; if (hide_non_functions && !object->isType (RObject::Function)) return false; if (filterRegExp ().isEmpty ()) return true; if (filter_on_name && object->getShortName ().contains (filterRegExp ())) return true; if (filter_on_label && object->getLabel ().contains (filterRegExp ())) return true; if (filter_on_class) { QStringList cnames = object->classNames (); for (int i = cnames.length () - 1; i >= 0; --i) { if (cnames[i].contains (filterRegExp ())) return true; } } return false; }
void RKObjectListModel::fetchMore (const QModelIndex &parent) { RK_TRACE (OBJECTS); RObject *object = static_cast<RObject*> (parent.internalPointer ()); RK_ASSERT (object && object->isType (RObject::Incomplete)); object->fetchMoreIfNeeded (); }
bool RObject::isInGlobalEnv () const { RK_TRACE (OBJECTS); // could be made recursive instead, but likely it's faster like this RObject *o = const_cast<RObject*> (this); // it's ok, all we need to do is find the toplevel parent while (o && (!o->isType (ToplevelEnv))) { o = o->parent; } if (!o) { RK_ASSERT (this == RObjectList::getObjectList ()); return false; } if (o->isType (GlobalEnv)) { if (o != this) return true; // the GlobalEnv is not inside the GlobalEnv! } return false; }
REnvironmentObject* RObjectList::findPackage (const QString &namespacename) const { RK_TRACE (OBJECTS); for (int i = childmap.size () - 1; i >= 0; --i) { RObject* child = childmap[i]; if (!child->isType (PackageEnv)) continue; // Skip Autoloads REnvironmentObject* env = static_cast<REnvironmentObject *> (child); if (env->packageName () == namespacename) { return env; } } return 0; }
bool RKObjectListModel::canFetchMore (const QModelIndex &parent) const { RK_TRACE (OBJECTS); RObject *object = static_cast<RObject*> (parent.internalPointer ()); return (object && object->isType (RObject::Incomplete)); }
void RObjectList::rCommandDone (RCommand *command) { RK_TRACE (OBJECTS); bool changed = false; if (command->getFlags () == UPDATE_LIST_COMMAND) { // first check, whether all known children still exist: checkRemovedChildren (command->getStringVector (), command->stringVectorLength ()); // next, update the existing and/or new children num_children_updating = command->stringVectorLength (); // TODO: is this correct? Some children might have been removed! // empty workspace? if (!num_children_updating) { num_children_updating = 1; childUpdateComplete (); return; } REnvironmentObject **new_toplevel_envs = new REnvironmentObject*[command->stringVectorLength ()]; int num_new_toplevel_envs = 0; for (int i = 0; i < command->stringVectorLength (); ++i) { QString cname = command->getStringVector ()[i]; // for easier typing /*if (cname == (".rk.meta")) { childUpdateComplete (); continue; }*/ if (childmap.find (cname) != childmap.end ()) { childmap[cname]->updateFromR (); } else { createToplevelEnvironment (cname); changed = true; } RObject *object = childmap[cname]; RK_ASSERT (object); RK_ASSERT (object->isType (Environment)); new_toplevel_envs[num_new_toplevel_envs++] = static_cast<REnvironmentObject *> (object); } delete [] toplevel_environments; toplevel_environments = new_toplevel_envs; num_toplevel_environments = num_new_toplevel_envs; } else if (command->getFlags () == CHILD_GET_TYPE_COMMAND) { if (command->intVectorLength () != 1) { RK_ASSERT (false); qDebug (command->command ().latin1()); } PendingObject *pobj = pending_objects[command]; RObject *robj; // TODO: handle more special types! if (command->getIntVector ()[0] == 1) { robj = new RContainerObject (pobj->parent, pobj->name); } else if (command->getIntVector ()[0] == 2) { robj = new RFunctionObject (pobj->parent, pobj->name); } else { robj = new RKVariable (pobj->parent, pobj->name); } RK_ASSERT (robj); pobj->parent->addChild (robj, pobj->name); delete pobj; pending_objects.remove (command); RKGlobals::tracker ()->addObject (robj, 0); } // TODO: signal change }
void RKFunctionArgHinter::tryArgHintNow () { RK_TRACE (COMMANDEDITOR); int line_rev; int cursor_pos; QString current_context; QString current_line; // fetch the most immediate context line. More will be fetched later, if appropriate bool have_context = provider->provideContext (line_rev = 0, ¤t_line, &cursor_pos); RK_ASSERT (have_context); RK_ASSERT (cursor_pos >= 0); current_context = current_line; // find the corrresponding opening brace int matching_left_brace_pos; int brace_level = 1; int i = cursor_pos; while (true) { if (current_context.at (i) == QChar (')')) { brace_level++; } else if (current_context.at (i) == QChar ('(')) { brace_level--; if (!brace_level) break; } --i; if (i < 0) { bool have_context = provider->provideContext (++line_rev, ¤t_line, &cursor_pos); if (!have_context) break; RK_ASSERT (cursor_pos < 0); current_context.prepend (current_line); i = current_line.length () - 1; } } if (!brace_level) matching_left_brace_pos = i; else { hideArgHint (); return; } // now find where the symbol to the left ends // there cannot be a line-break between the opening brace, and the symbol name (or can there?), so no need to fetch further context int potential_symbol_end = matching_left_brace_pos - 1; while ((potential_symbol_end > 0) && current_context.at (potential_symbol_end).isSpace ()) { --potential_symbol_end; } if (current_context.at (potential_symbol_end).isSpace ()) { hideArgHint (); return; } // now identify the symbol and object (if any) QString effective_symbol = RKCommonFunctions::getCurrentSymbol (current_context, potential_symbol_end+1); if (effective_symbol.isEmpty ()) { hideArgHint (); return; } RObject *object = RObjectList::getObjectList ()->findObject (effective_symbol); if ((!object) || (!object->isType (RObject::Function))) { hideArgHint (); return; } // initialize and show popup arghints_popup_text->setText (effective_symbol + " (" + static_cast<RFunctionObject*> (object)->printArgs () + ')'); arghints_popup->resize (arghints_popup_text->sizeHint () + QSize (2, 2)); arghints_popup->move (view->mapToGlobal (view->cursorCoordinates () + QPoint (0, arghints_popup->height ()))); arghints_popup->show (); }