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 {
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); 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 {