RKComponent::UnserializeError RKComponentBase::unserializeState (const QStringList &state) { RK_TRACE (PLUGIN); QMap<QString, QString> props; for (int i = 0; i < state.count (); ++i) { QString line = state[i]; int sep = line.indexOf ('='); if (sep < 0) return BadFormat; props.insert (RKCommonFunctions::unescape (line.left (sep)), RKCommonFunctions::unescape (line.mid (sep+1))); } setPropertyValues (&props); // verify UnserializeError error = NoError; for (QMap<QString, QString>::const_iterator it = props.constBegin (); it != props.constEnd (); ++it) { if (fetchStringValue (it.key ()) != it.value ()) { // COMPAT: In RKWard 0.5.1, the formatting of real numbers was different. Hence we compare the numeric values, instead QString dummy; RKComponentBase *prop = lookupComponent (it.key (), &dummy); if (dummy.isEmpty () && prop && prop->type () == PropertyDouble) { if (static_cast<RKComponentPropertyDouble*> (prop)->doubleValue () == it.value ().toDouble ()) { continue; } } RK_DO(qDebug ("Tried to apply value %s to property %s, but got %s", qPrintable (it.value ()), qPrintable (it.key ()), qPrintable (fetchStringValue (it.key ()))), PLUGIN, DL_WARNING); error = NotAllSettingsApplied; } } return error; }
RKPreviewBox::RKPreviewBox (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) { RK_TRACE (PLUGIN); preview_active = false; last_plot_done = true; new_plot_pending = false; dev_num = 0; // get xml-helper XMLHelper *xml = XMLHelper::getStaticHelper (); // create and add property addChild ("state", state = new RKComponentPropertyBool (this, true, preview_active, "active", "inactive")); state->setInternal (true); // restoring this does not make sense. connect (state, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (changedState (RKComponentPropertyBase *))); // create checkbox QVBoxLayout *vbox = new QVBoxLayout (this); vbox->setContentsMargins (0, 0, 0, 0); toggle_preview_box = new QCheckBox (xml->getStringAttribute (element, "label", i18n ("Preview"), DL_INFO), this); vbox->addWidget (toggle_preview_box); toggle_preview_box->setChecked (preview_active); connect (toggle_preview_box, SIGNAL (stateChanged (int)), this, SLOT (changedState (int))); // status lable status_label = new QLabel (QString::null, this); vbox->addWidget (status_label); // find and connect to code property of the parent QString dummy; RKComponentBase *cp = parentComponent ()->lookupComponent ("code", &dummy); if (cp && dummy.isNull () && (cp->type () == PropertyCode)) { code_property = static_cast<RKComponentPropertyCode *> (cp); connect (code_property, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (changedCode (RKComponentPropertyBase *))); } else {
QString RKComponentBase::fetchStringValue (const QString &identifier) { RK_TRACE (PLUGIN); QString mod; RKComponentBase *prop = lookupComponent (identifier, &mod); return prop->value (mod); }
void RKComponentScriptingProxy::addChangeCommand (const QString& changed_id, const QString& command) { RK_TRACE (PHP); QString remainder; RKComponentBase* base = component->lookupComponent (changed_id, &remainder); if (remainder.isEmpty ()) { component_commands.insert (base, command); if (base->isComponent()) { connect (static_cast<RKComponent*> (base), SIGNAL (componentChanged(RKComponent*)), this, SLOT (componentChanged(RKComponent*))); } else {
void RKComponentBase::setPropertyValues (QMap<QString, QString> *list) { RK_TRACE (PLUGIN); // TODO: visibility enabledness and requiredness should be excluded, as those are not directly user settable. Perhaps even mark up all properties as user settable or not. for (QMap<QString, QString>::const_iterator it = list->constBegin (); it != list->constEnd (); ++it) { QString mod; RKComponentBase *prop = lookupComponent (it.key (), &mod); if (mod.isEmpty () && prop->isProperty ()) { // found a property static_cast<RKComponentPropertyBase*>(prop)->setValue (it.data ()); } } }
RKComponentBase* RKComponentBase::lookupComponent (const QString &identifier, QString *remainder) { RK_TRACE (PLUGIN); if (identifier.isEmpty ()) return this; RK_DO (qDebug ("looking up '%s'", identifier.latin1 ()), PLUGIN, DL_DEBUG); RKComponentBase *child = child_map.find (identifier.section (".", 0, 0)); if (!child) { // if we do not have such a child, return 0 unless this is a property if (remainder) *remainder = identifier; return this; } else { // else do recursive lookup return child->lookupComponent (identifier.section (".", 1), remainder); } }
RKComponentBase* RKComponentBase::lookupComponent (const QString &identifier, QString *remainder) { RK_TRACE (PLUGIN); RK_ASSERT (remainder); if (identifier.isEmpty ()) return this; RK_DO (qDebug ("looking up '%s'", identifier.toLatin1 ().data ()), PLUGIN, DL_DEBUG); RKComponentBase *child = child_map.value (identifier.section (".", 0, 0)); if (!child) { // if we do not have such a child, return this (and set remainder) *remainder = identifier; return this; } else { // else do recursive lookup return child->lookupComponent (identifier.section (".", 1), remainder); } }
void RKContextHandler::invokeComponent (RKComponentHandle *handle) { RK_TRACE (PLUGIN); RK_ASSERT (handle); // create component RKComponent *component = handle->invoke (0, 0); // set context values for (QHash<QString, RKComponentBase*>::const_iterator it = child_map.constBegin (); it != child_map.constEnd (); ++it) { if (it.key () != "#noid#") { QString id = it.key (); QString remainder; RKComponentBase *client = component->lookupComponent (id, &remainder); RK_ASSERT (it.value ()->isProperty ()); if (!(client && remainder.isEmpty () && client->isProperty () && it.value ()->isProperty ())) { RK_DEBUG (PLUGIN, DL_INFO, "Could not set context property %s", id.toLatin1 ().data ()); continue; } static_cast<RKComponentPropertyBase *> (client)->connectToGovernor (static_cast<RKComponentPropertyBase *> (it.value ()), QString (), false); } } }
RKOptionSet::RKOptionSet (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) { RK_TRACE (PLUGIN); XMLHelper *xml = XMLHelper::getStaticHelper (); updating = false; last_known_status = Processing; n_invalid_rows = n_unfinished_rows = 0; min_rows = xml->getIntAttribute (element, "min_rows", 0, DL_INFO); min_rows_if_any = xml->getIntAttribute (element, "min_rows_if_any", 1, DL_INFO); max_rows = xml->getIntAttribute (element, "max_rows", INT_MAX, DL_INFO); // build UI framework QVBoxLayout *layout = new QVBoxLayout (this); switcher = new QStackedWidget (this); layout->addWidget (switcher); user_area = new KVBox (this); switcher->addWidget (user_area); updating_notice = new QLabel (i18n ("Updating status, please wait"), this); switcher->addWidget (updating_notice); update_timer.setInterval (0); update_timer.setSingleShot (true); connect (&update_timer, SIGNAL (timeout()), this, SLOT (slotUpdateUnfinishedRows())); // create some meta properties serialization_of_set = new RKComponentPropertyBase (this, false); addChild ("serialized", serialization_of_set); connect (serialization_of_set, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (serializationPropertyChanged(RKComponentPropertyBase*))); row_count = new RKComponentPropertyInt (this, false, 0); row_count->setInternal (true); addChild ("row_count", row_count); // NOTE: read-only return_to_row = active_row = -1; current_row = new RKComponentPropertyInt (this, false, active_row); current_row->setInternal (true); addChild ("current_row", current_row); // NOTE: read-write connect (current_row, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (currentRowPropertyChanged(RKComponentPropertyBase*))); // first build the contents, as we will need to refer to the elements inside, later model = 0; display = 0; // will be created from the builder, on demand -> createDisplay () contents_container = new RKComponent (this, user_area); QDomElement content_element = xml->getChildElement (element, "content", DL_ERROR); RKComponentBuilder *builder = new RKComponentBuilder (contents_container, content_element); builder->buildElement (content_element, user_area, 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->parseLogic (xml->getChildElement (element, "logic", DL_INFO), false); builder->makeConnections (); addChild ("contents", contents_container); connect (standardComponent (), SIGNAL (standardInitializationComplete()), this, SLOT (fetchDefaults())); // create columns XMLChildList options = xml->getChildElements (element, "optioncolumn", DL_WARNING); QStringList visible_column_labels ("#"); // Optionally hidden first row for index for (int i = 0; i < options.size (); ++i) { const QDomElement &e = options.at (i); QString id = xml->getStringAttribute (e, "id", QString (), DL_ERROR); QString label = xml->getStringAttribute (e, "label", QString (), DL_DEBUG); QString governor = xml->getStringAttribute (e, "connect", QString (), DL_INFO); bool external = xml->getBoolAttribute (e, "external", false, DL_INFO); while (child_map.contains (id)) { RK_DEBUG (PLUGIN, DL_ERROR, "optionset already contains a property named %s. Renaming to _%s", qPrintable (id), qPrintable (id)); id = "_" + id; } ColumnInfo col_inf; col_inf.column_name = id; col_inf.external = external; col_inf.governor = governor; if (external && e.hasAttribute ("default")) col_inf.default_value = xml->getStringAttribute (e, "default", QString (), DL_ERROR); RKComponentPropertyStringList *column_property = new RKComponentPropertyStringList (this, false); column_property->setInternal (external); // Yes, looks strange, indeed. External properties should simply not be serialized / restored... addChild (id, column_property); connect (column_property, SIGNAL (valueChanged(RKComponentPropertyBase *)), this, SLOT (columnPropertyChanged(RKComponentPropertyBase *))); if (!label.isEmpty ()) { col_inf.display_index = visible_column_labels.size (); col_inf.column_label = label; visible_column_labels.append (label); visible_columns.append (column_property); } else { col_inf.display_index = -1; } column_map.insert (column_property, col_inf); } keycolumn = 0; QString keycol = xml->getStringAttribute (element, "keycolumn", QString (), DL_DEBUG); if (!keycol.isEmpty ()) { keycolumn = static_cast<RKComponentPropertyStringList*> (child_map.value (keycol)); if (!column_map.contains (keycolumn)) { RK_DEBUG (PLUGIN, DL_ERROR, "optionset does not contain an optioncolumn named %s. Falling back to manual insertion mode", qPrintable (keycol)); keycolumn = 0; } else if (!column_map[keycolumn].external) { RK_DEBUG (PLUGIN, DL_ERROR, "keycolumn (%s) is not marked as external. Falling back to manual insertion mode", qPrintable (keycol)); keycolumn = 0; } else { updating = true; keycolumn->setValue (KEYCOLUMN_UNINITIALIZED_VALUE); updating = false; } } QMap<RKComponentPropertyStringList *, ColumnInfo>::iterator it = column_map.begin (); for (; it != column_map.end (); ++it) { ColumnInfo &ci = it.value (); if (!ci.governor.isEmpty ()) { // there *can* be columns without governor for driven or connected option sets // Establish connections between columns and their respective governors. Since the format differs, the connection is done indirectly, through this component. // So, here, we set up a map of properties to columns, and connect to the change signals. RKComponentBase *governor = contents_container->lookupComponent (ci.governor, &ci.governor_modifier); if (governor && governor->isProperty ()) { RKComponentPropertyBase *gov_prop = static_cast<RKComponentPropertyBase*> (governor); if (ci.external) { if (!ci.governor_modifier.isEmpty ()) { RK_DEBUG (PLUGIN, DL_ERROR, "Cannot connect external column '%s' in optionset to property with modifier (%s).", qPrintable (ci.column_name), qPrintable (ci.governor)); continue; } } columns_to_update.insertMulti (gov_prop, it.key ()); connect (gov_prop, SIGNAL (valueChanged(RKComponentPropertyBase *)), this, SLOT (governingPropertyChanged(RKComponentPropertyBase *))); } else {
RKPreviewBox::RKPreviewBox (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) { RK_TRACE (PLUGIN); prior_preview_done = true; new_preview_pending = false; // get xml-helper XMLHelper *xml = parent_component->xmlHelper (); preview_mode = (PreviewMode) xml->getMultiChoiceAttribute (element, "mode", "plot;data;output;custom", 0, DL_INFO); placement = (PreviewPlacement) xml->getMultiChoiceAttribute (element, "placement", "default;attached;detached;docked", 0, DL_INFO); if (placement == DefaultPreview) placement = DockedPreview; preview_active = xml->getBoolAttribute (element, "active", false, DL_INFO); idprop = RObject::rQuote (QString ().sprintf ("%p", this)); // create and add property addChild ("state", state = new RKComponentPropertyBool (this, true, preview_active, "active", "inactive")); state->setInternal (true); // restoring this does not make sense. connect (state, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (changedState(RKComponentPropertyBase*))); // create checkbox QVBoxLayout *vbox = new QVBoxLayout (this); vbox->setContentsMargins (0, 0, 0, 0); toggle_preview_box = new QCheckBox (xml->i18nStringAttribute (element, "label", i18n ("Preview"), DL_INFO), this); vbox->addWidget (toggle_preview_box); toggle_preview_box->setChecked (preview_active); connect (toggle_preview_box, SIGNAL (stateChanged(int)), this, SLOT (changedState(int))); // status label status_label = new QLabel (QString (), this); status_label->setWordWrap (true); vbox->addWidget (status_label); // prepare placement placement_command = ".rk.with.window.hints ({"; placement_end = "\n}, "; if (placement == AttachedPreview) placement_end.append ("\"attached\""); else if (placement == DetachedPreview) placement_end.append ("\"detached\""); else placement_end.append ("\"\""); placement_end.append (", " + RObject::rQuote (idprop) + ", style=\"preview\")"); if (placement == DockedPreview) { RKStandardComponent *uicomp = topmostStandardComponent (); if (uicomp) { uicomp->addDockedPreview (state, toggle_preview_box->text (), idprop); if (preview_mode == OutputPreview) { RKGlobals::rInterface ()->issueCommand ("local ({\n" "outfile <- tempfile (fileext='html')\n" "rk.assign.preview.data(" + idprop + ", list (filename=outfile, on.delete=function (id) {\n" " rk.flush.output (outfile, ask=FALSE)\n" " unlink (outfile)\n" "}))\n" "oldfile <- rk.set.output.html.file (outfile, style='preview') # for initialization\n" "rk.set.output.html.file (oldfile)\n" "})\n" + placement_command + "rk.show.html(rk.get.preview.data (" + idprop + ")$filename)" + placement_end, RCommand::Plugin | RCommand::Sync); } else { // For all others, create an empty data.frame as dummy. Even for custom docked previews it has the effect of initializing the preview area with _something_. RKGlobals::rInterface ()->issueCommand ("local ({\nrk.assign.preview.data(" + idprop + ", data.frame ())\n})\n" + placement_command + "rk.edit(rkward::.rk.variables$.rk.preview.data[[" + idprop + "]])" + placement_end, RCommand::Plugin | RCommand::Sync); } // A bit of a hack: For now, in wizards, docked previews are always active, and control boxes are meaningless. if (uicomp->isWizardish ()) { hide (); toggle_preview_box->setChecked (true); } } } // find and connect to code property of the parent QString dummy; RKComponentBase *cp = parentComponent ()->lookupComponent ("code", &dummy); if (cp && dummy.isNull () && (cp->type () == PropertyCode)) { code_property = static_cast<RKComponentPropertyCode *> (cp); connect (code_property, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (changedCode(RKComponentPropertyBase*))); } else {