本文整理汇总了C++中KstStringPtr类的典型用法代码示例。如果您正苦于以下问题:C++ KstStringPtr类的具体用法?C++ KstStringPtr怎么用?C++ KstStringPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KstStringPtr类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeDuplicate
KstDataObjectPtr KstPlugin::makeDuplicate(KstDataObjectDataObjectMap& duplicatedMap) {
KstPluginPtr plugin = new KstPlugin;
// use same inputs
for (KstVectorMap::ConstIterator iter = _inputVectors.begin(); iter != _inputVectors.end(); ++iter) {
plugin->inputVectors().insert(iter.key(), iter.data());
}
for (KstScalarMap::ConstIterator iter = _inputScalars.begin(); iter != _inputScalars.end(); ++iter) {
plugin->inputScalars().insert(iter.key(), iter.data());
}
for (KstStringMap::ConstIterator iter = _inputStrings.begin(); iter != _inputStrings.end(); ++iter) {
plugin->inputStrings().insert(iter.key(), iter.data());
}
// create new outputs
for (KstVectorMap::ConstIterator iter = outputVectors().begin(); iter != outputVectors().end(); ++iter) {
KstVectorPtr v = new KstVector;
v->writeLock();
plugin->outputVectors().insert(iter.key(), v);
v->setTagName(iter.data()->tagName() + "'");
v->setProvider(plugin.data());
KST::addVectorToList(v);
v->writeUnlock();
}
for (KstScalarMap::ConstIterator iter = outputScalars().begin(); iter != outputScalars().end(); ++iter) {
KstScalarPtr s = new KstScalar;
s->writeLock();
plugin->outputScalars().insert(iter.key(), s);
s->setTagName(iter.data()->tagName() + "'");
s->setProvider(plugin.data());
s->writeUnlock();
}
for (KstStringMap::ConstIterator iter = outputStrings().begin(); iter != outputStrings().end(); ++iter) {
KstStringPtr s = new KstString;
s->writeLock();
plugin->outputStrings().insert(iter.key(), s);
s->setTagName(iter.data()->tagName() + "'");
s->setProvider(plugin.data());
s->writeUnlock();
}
// set the same plugin
plugin->setPlugin(_plugin);
plugin->setTagName(tagName() + "'");
duplicatedMap.insert(this, KstDataObjectPtr(plugin));
return KstDataObjectPtr(plugin);
}
示例2: inputString
bool PlanckLatestDate::algorithm() {
KstStringPtr kstrTemplate = inputString(TEMPLATE);
KstStringPtr kstrName = outputString(LATEST_DATE);
QString strTemplate = kstrTemplate->value();
QStringList files;
QString strFile;
QString strDir;
int iRetVal = false;
int iIndex;
kstrName->setValue(QString());
iIndex = strTemplate.lastIndexOf( QDir::separator() );
if (iIndex >= 0) {
strDir = strTemplate.left( iIndex + 1 );
if (strTemplate.length() > 0) {
strFile = strTemplate.right( strTemplate.length() - iIndex - 1 );
}
} else {
strFile = strTemplate;
}
{
QDir dir(strDir, strFile, QDir::Name, QDir::Files );
files = dir.entryList( );
if (!files.empty()) {
kstrName->setValue( dir.absoluteFilePath( files.back() ) );
}
iRetVal = true;
}
return iRetVal;
}
示例3: renderLabel
void renderLabel(RenderContext& rc, Label::Chunk *fi) {
// FIXME: RTL support
int oldSize = rc.size;
int oldY = rc.y;
int oldX = rc.x;
while (fi) {
if (fi->vOffset != Label::Chunk::None) {
if (fi->vOffset == Label::Chunk::Up) {
rc.y -= int(0.4 * rc.fontHeight());
} else { // Down
rc.y += int(0.4 * rc.fontHeight());
}
if (rc.size > 5) {
rc.size = (rc.size*2)/3;
}
}
QFont f = rc.font();
if (rc.fontSize() != rc.size) {
f.setPointSize(rc.size);
}
f.setBold(fi->attributes.bold);
f.setItalic(fi->attributes.italic);
f.setUnderline(fi->attributes.underline);
if (rc.p && fi->attributes.color.isValid()) {
rc.p->setPen(fi->attributes.color);
} else if (rc.p) {
rc.p->setPen(rc.pen);
}
rc.setFont(f);
if (fi->linebreak) {
rc.x = oldX;
rc.y += rc.fontAscent() + rc.fontDescent() + 1;
fi = fi->next;
continue;
}
if (!rc.substitute && (fi->scalar || fi->vector)) {
QString txt = QString("[") + fi->text + "]";
if (rc.p) {
rc.p->drawText(rc.x, rc.y, txt);
}
rc.x += rc.fontWidth(txt);
} else if (fi->scalar) {
// do scalar/string/fit substitution
QString txt;
if (!fi->text.isEmpty() && fi->text[0] == '=') {
// Parse and evaluate as an equation
bool ok = false;
const double eqResult(Equation::interpret(fi->text.mid(1).latin1(), &ok));
txt = QString::number(eqResult, 'g', rc.precision);
if (rc._cache) {
rc._cache->append(DataRef(DataRef::DRExpression, fi->text, QString::null, 0.0, QVariant(eqResult)));
}
} else {
KST::scalarList.lock().readLock();
KstScalarPtr scp = *KST::scalarList.findTag(fi->text);
KST::scalarList.lock().unlock();
if (scp) {
scp->readLock();
txt = QString::number(scp->value(), 'g', rc.precision);
if (rc._cache) {
rc._cache->append(DataRef(DataRef::DRScalar, fi->text, QString::null, 0.0, QVariant(scp->value())));
}
scp->unlock();
} else {
KST::stringList.lock().readLock();
KstStringPtr stp = *KST::stringList.findTag(fi->text);
KST::stringList.lock().unlock();
if (stp) {
stp->readLock();
txt = stp->value();
if (rc._cache) {
rc._cache->append(DataRef(DataRef::DRString, fi->text, QString::null, 0.0, QVariant(stp->value())));
}
stp->unlock();
} else {
KST::dataObjectList.lock().readLock();
KstDataObjectList::Iterator oi = KST::dataObjectList.findTag(fi->text);
KST::dataObjectList.lock().unlock();
if (oi != KST::dataObjectList.end()) {
KstPluginPtr fit = kst_cast<KstPlugin>(*oi);
if (fit) {
fit->readLock();
const QString txtAll = fit->label(rc.precision);
fit->unlock();
const QValueList<QString> strList = QStringList::split('\n', txtAll);
QValueListConstIterator<QString> last = --(strList.end());
for (QValueListConstIterator<QString> iter = strList.begin(); iter != strList.end(); ++iter) {
txt = (*iter);
if (iter != last) {
if (rc.p) {
rc.p->drawText(rc.x, rc.y, txt);
} else {
rc.ascent = kMax(rc.ascent, -rc.y + rc.fontAscent());
//.........这里部分代码省略.........
示例4: Q_ASSERT
KstObject::UpdateType KstCPlugin::update(int update_counter) {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
if (!isValid()) {
return setLastUpdateResult(NO_CHANGE);
}
if (recursed()) {
return setLastUpdateResult(NO_CHANGE);
}
bool force = dirty();
setDirty(false);
if (KstObject::checkUpdateCounter(update_counter) && !force) {
return lastUpdateResult();
}
#define CLEANUP() do {\
for (unsigned i = 0; i < _outStringCnt; ++i) { \
if (_outStrings[i]) { \
free(_outStrings[i]); \
_outStrings[i] = 0L; \
} \
} \
for (unsigned i = 0; i < _inStringCnt; ++i) { \
if (_inStrings[i]) { \
free(_inStrings[i]); \
_inStrings[i] = 0L; \
} \
} \
} while(0)
writeLockInputsAndOutputs();
const QValueList<Plugin::Data::IOValue>& itable = _plugin->data()._inputs;
const QValueList<Plugin::Data::IOValue>& otable = _plugin->data()._outputs;
int itcnt = 0, vitcnt = 0, sitcnt = 0;
bool doUpdate = force;
// Populate the input scalars and vectors
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin(); it != itable.end(); ++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!_inputVectors.contains((*it)._name)) {
KstDebug::self()->log(i18n("Input vector [%1] for plugin %2 not found. Unable to continue.").arg((*it)._name).arg(tagName()), KstDebug::Error);
CLEANUP();
return setLastUpdateResult(NO_CHANGE);
}
KstVectorPtr iv = _inputVectors[(*it)._name];
if (!iv) {
kstdFatal() << "Input vector \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == iv->update(update_counter)) || doUpdate;
_inVectors[vitcnt] = iv->value();
_inArrayLens[vitcnt++] = iv->length();
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
KstScalarPtr is = _inputScalars[(*it)._name];
if (!is) {
kstdFatal() << "Input scalar \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == is->update(update_counter)) || doUpdate;
_inScalars[itcnt++] = is->value();
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
KstStringPtr is = _inputStrings[(*it)._name];
if (!is) {
kstdFatal() << "Input string \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == is->update(update_counter)) || doUpdate;
// Maybe we should use UTF-8 instead?
_inStrings[sitcnt++] = strdup(is->value().latin1());
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
_inScalars[itcnt++] = getpid();
}
}
if (!doUpdate) {
CLEANUP();
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
vitcnt = 0;
// Populate the output vectors
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin();
it != otable.end();
++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!_outputVectors.contains((*it)._name)) {
KstDebug::self()->log(i18n("Output vector [%1] for plugin %2 not found. Unable to continue.").arg((*it)._name).arg(tagName()), KstDebug::Error);
CLEANUP();
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
_outVectors[vitcnt] = _outputVectors[(*it)._name]->value();
_outArrayLens[vitcnt++] = _outputVectors[(*it)._name]->length();
}
}
if (_outStringCnt > 0) {
//.........这里部分代码省略.........
示例5: i18n
void KstPluginDialogI::generateEntries(bool input, int& cnt, QWidget *parent, QGridLayout *grid, const QValueList<Plugin::Data::IOValue>& table) {
QString scalarLabelTemplate, vectorLabelTemplate, stringLabelTemplate;
if (input) {
stringLabelTemplate = i18n("Input string - %1:");
scalarLabelTemplate = i18n("Input scalar - %1:");
vectorLabelTemplate = i18n("Input vector - %1:");
} else {
stringLabelTemplate = i18n("Output string - %1:");
scalarLabelTemplate = i18n("Output scalar - %1:");
vectorLabelTemplate = i18n("Output vector - %1:");
}
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = table.begin(); it != table.end(); ++it) {
QString labellabel;
bool scalar = false;
bool string = false;
switch ((*it)._type) {
case Plugin::Data::IOValue::PidType:
continue;
case Plugin::Data::IOValue::StringType:
labellabel = stringLabelTemplate.arg((*it)._name);
string = true;
break;
case Plugin::Data::IOValue::FloatType:
labellabel = scalarLabelTemplate.arg((*it)._name);
scalar = true;
break;
case Plugin::Data::IOValue::TableType:
if ((*it)._subType == Plugin::Data::IOValue::FloatSubType ||
(*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
labellabel = vectorLabelTemplate.arg((*it)._name);
} else {
// unsupported
continue;
}
break;
default:
// unsupported
continue;
}
QLabel *label = new QLabel(labellabel, parent, input ? "Input label" : "Output label");
QWidget *widget = 0L;
if (input) {
if (scalar) {
ScalarSelector *w = new ScalarSelector(parent, (*it)._name.latin1());
widget = w;
connect(w->_scalar, SIGNAL(activated(const QString&)), this, SLOT(updateScalarTooltip(const QString&)));
connect(widget, SIGNAL(newScalarCreated()), this, SIGNAL(modified()));
if (!(*it)._default.isEmpty()) {
w->_scalar->insertItem((*it)._default);
w->_scalar->setCurrentText((*it)._default);
}
KstScalarPtr p = *KST::scalarList.findTag(w->_scalar->currentText());
w->allowDirectEntry(true);
if (p) {
p->readLock();
QToolTip::remove(w->_scalar);
QToolTip::add(w->_scalar, QString::number(p->value()));
p->unlock();
}
} else if (string) {
StringSelector *w = new StringSelector(parent, (*it)._name.latin1());
widget = w;
connect(w->_string, SIGNAL(activated(const QString&)), this, SLOT(updateStringTooltip(const QString&)));
connect(widget, SIGNAL(newStringCreated()), this, SIGNAL(modified()));
if (!(*it)._default.isEmpty()) {
w->_string->insertItem((*it)._default);
w->_string->setCurrentText((*it)._default);
}
KstStringPtr p = *KST::stringList.findTag(w->_string->currentText());
w->allowDirectEntry(true);
if (p) {
p->readLock();
QToolTip::remove(w->_string);
QToolTip::add(w->_string, p->value());
p->unlock();
}
} else {
widget = new VectorSelector(parent, (*it)._name.latin1());
connect(widget, SIGNAL(newVectorCreated(const QString&)), this, SIGNAL(modified()));
}
} else {
示例6: blockVectorUpdates
bool KstPluginDialogI::saveOutputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
const QValueList<Plugin::Data::IOValue>& otable = p->data()._outputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin(); it != otable.end(); ++it) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "QLineEdit");
if (!field) {
continue; // Some are unsupported
}
QLineEdit *li = static_cast<QLineEdit*>(field);
if (li->text().isEmpty()) {
li->setText((*it)._name);
}
QString nt = li->text();
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
// Implicitly creates it if it doesn't exist
KstVectorPtr v = plugin->outputVectors()[(*it)._name];
if (!v) {
KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
v = new KstVector(KstObjectTag(nt, plugin->tag()), 0, plugin.data());
plugin->outputVectors().insert((*it)._name, v);
}
v->setTagName(KstObjectTag(nt, plugin->tag()));
} else if (plugin->outputVectors()[(*it)._name]->tagName() != nt) {
while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
nt += "'";
}
KstVectorPtr v;
if (plugin->outputVectors().contains((*it)._name)) {
v = plugin->outputVectors()[(*it)._name];
} else {
KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
v = new KstVector(KstObjectTag(nt, plugin->tag()), 0, plugin.data());
plugin->outputVectors().insert((*it)._name, v);
}
v->setTagName(KstObjectTag(nt, plugin->tag()));
}
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
KstStringPtr s;
if (plugin->outputStrings().contains((*it)._name)) {
s = plugin->outputStrings()[(*it)._name];
} else {
KstWriteLocker blockStringUpdates(&KST::stringList.lock());
s = new KstString(KstObjectTag(nt, plugin->tag()), plugin.data());
plugin->outputStrings().insert((*it)._name, s);
}
s->setTagName(KstObjectTag(nt, plugin->tag()));
} else if (plugin->outputStrings()[(*it)._name]->tagName() != nt) {
while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
nt += "'";
}
KstStringPtr s;
if (plugin->outputStrings().contains((*it)._name)) {
s = plugin->outputStrings()[(*it)._name];
} else {
KstWriteLocker blockStringUpdates(&KST::stringList.lock());
s = new KstString(KstObjectTag(nt, plugin->tag()), plugin.data());
plugin->outputStrings().insert((*it)._name, s);
}
s->setTagName(KstObjectTag(nt, plugin->tag()));
}
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
// Nothing
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
KstScalarPtr s;
if (plugin->outputScalars().contains((*it)._name)) {
s = plugin->outputScalars()[(*it)._name];
} else {
KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
s = new KstScalar(KstObjectTag(nt, plugin->tag()), plugin.data());
plugin->outputScalars().insert((*it)._name, s);
}
s->setTagName(KstObjectTag(nt, plugin->tag()));
} else if (plugin->outputScalars()[(*it)._name]->tagName() != nt) {
while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
nt += "'";
}
KstScalarPtr s;
if (plugin->outputScalars().contains((*it)._name)) {
s = plugin->outputScalars()[(*it)._name];
} else {
KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
s = new KstScalar(KstObjectTag(nt, plugin->tag()), plugin.data());
plugin->outputScalars().insert((*it)._name, s);
}
s->setTagName(KstObjectTag(nt, plugin->tag()));
}
}
}
return true;
}
示例7: assert
bool KstPluginDialogI::saveInputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
bool rc = true;
KST::vectorList.lock().readLock();
KST::scalarList.lock().readLock();
KST::stringList.lock().readLock();
const QValueList<Plugin::Data::IOValue>& itable = p->data()._inputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin(); it != itable.end(); ++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "VectorSelector");
assert(field);
VectorSelector *vs = static_cast<VectorSelector*>(field);
KstVectorPtr v = *KST::vectorList.findTag(vs->selectedVector());
if (v) {
v->writeLock(); // to match with plugin->writeLock()
if (plugin->inputVectors().contains((*it)._name) && plugin->inputVectors()[(*it)._name] != v) {
plugin->inputVectors()[(*it)._name]->unlock();
}
plugin->inputVectors().insert((*it)._name, v);
} else if (plugin->inputVectors().contains((*it)._name)) {
plugin->inputVectors().erase((*it)._name);
rc = false;
}
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "StringSelector");
assert(field);
StringSelector *ss = static_cast<StringSelector*>(field);
KstStringPtr s = *KST::stringList.findTag(ss->selectedString());
if (s == *KST::stringList.end()) {
QString val = ss->_string->currentText();
KstStringPtr newString = new KstString(ss->_string->currentText(), 0L, val, true, false);
newString->writeLock(); // to match with plugin->writeLock()
if (plugin->inputStrings().contains((*it)._name) && plugin->inputStrings()[(*it)._name] != s) {
plugin->inputStrings()[(*it)._name]->unlock();
}
plugin->inputStrings().insert((*it)._name, newString);
} else {
s->writeLock(); // to match with plugin->writeLock()
if (plugin->inputStrings().contains((*it)._name) && plugin->inputStrings()[(*it)._name] != s) {
plugin->inputStrings()[(*it)._name]->unlock();
}
plugin->inputStrings().insert((*it)._name, s);
}
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
// Nothing
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "ScalarSelector");
assert(field);
ScalarSelector *ss = static_cast<ScalarSelector*>(field);
KstScalarPtr s = *KST::scalarList.findTag(ss->selectedScalar());
if (s == *KST::scalarList.end()) {
bool ok;
double val = ss->_scalar->currentText().toDouble(&ok);
if (ok) {
KstScalarPtr newScalar = new KstScalar(ss->_scalar->currentText(), 0L, val, true, false, false);
newScalar->writeLock(); // to match with plugin->writeLock()
if (plugin->inputScalars().contains((*it)._name) && plugin->inputScalars()[(*it)._name] != s) {
plugin->inputScalars()[(*it)._name]->unlock();
}
plugin->inputScalars().insert((*it)._name, newScalar);
} else {
s->writeLock(); // to match with plugin->writeLock()
if (plugin->inputScalars().contains((*it)._name) && plugin->inputScalars()[(*it)._name] != s) {
plugin->inputScalars()[(*it)._name]->unlock();
}
plugin->inputScalars().insert((*it)._name, s);
}
} else {
s->writeLock(); // to match with plugin->writeLock()
if (plugin->inputScalars().contains((*it)._name) && plugin->inputScalars()[(*it)._name] != s) {
plugin->inputScalars()[(*it)._name]->unlock();
}
plugin->inputScalars().insert((*it)._name, s);
}
} else {
}
}
KST::stringList.lock().unlock();
KST::scalarList.lock().unlock();
KST::vectorList.lock().unlock();
return rc;
}
示例8: switch
void KstViewLabel::DataCache::update() {
for (QValueVector<DataRef>::ConstIterator i = data.begin(); valid && i != data.end(); ++i) {
switch ((*i).type) {
case DataRef::DataRef::DRScalar:
{
KST::scalarList.lock().readLock();
KstScalarPtr p = *KST::scalarList.findTag((*i).name);
KST::scalarList.lock().unlock();
if (p) {
p->readLock();
if (QVariant(p->value()) != (*i).value) {
valid = false;
}
p->unlock();
}
}
break;
case DataRef::DRString:
{
KST::stringList.lock().readLock();
KstStringPtr p = *KST::stringList.findTag((*i).name);
KST::stringList.lock().unlock();
if (p) {
p->readLock();
if (QVariant(p->value()) != (*i).value) {
valid = false;
}
p->unlock();
}
}
break;
case DataRef::DRExpression:
{
bool ok = false;
const double val = Equation::interpret((*i).name.latin1(), &ok, (*i).name.length());
if (QVariant(val) != (*i).value) {
valid = false;
}
}
break;
case DataRef::DRVector:
{
bool ok = false;
const double idx = Equation::interpret((*i).index.latin1(), &ok, (*i).index.length());
if (idx != (*i).indexValue) {
valid = false;
break;
}
KST::vectorList.lock().readLock();
KstVectorPtr p = *KST::vectorList.findTag((*i).name);
KST::vectorList.lock().unlock();
if (p) {
p->readLock();
if (QVariant(p->value(int((*i).indexValue))) != (*i).value) {
valid = false;
}
p->unlock();
}
}
break;
case DataRef::DataRef::DRFit:
{
KST::dataObjectList.lock().readLock();
KstDataObjectList::Iterator oi = KST::dataObjectList.findTag((*i).name);
KST::dataObjectList.lock().unlock();
if (oi != KST::dataObjectList.end()) {
KstCPluginPtr fit = kst_cast<KstCPlugin>(*oi);
if (fit) {
fit->readLock();
if (fit->label((int)((*i).indexValue)) != (*i).index) {
valid = false;
}
fit->unlock();
}
}
}
break;
}
}
}
示例9: freeParameters
bool KstPlugin::setPlugin(KstSharedPtr<Plugin> plugin) {
// Assumes that this is called with a write lock in place on this object
if (plugin == _plugin) {
return true;
}
freeParameters();
if (_localData) {
if (!_plugin || !_plugin->freeLocalData(&_localData)) {
free(_localData);
}
_localData = 0L;
}
if (!plugin) {
_inputVectors.clear();
_inputScalars.clear();
_inputStrings.clear();
_outputVectors.clear();
_outputScalars.clear();
_outputStrings.clear();
_plugin = 0L;
return true;
}
Plugin::countScalarsVectorsAndStrings(plugin->data()._inputs, _inScalarCnt, _inArrayCnt, _inStringCnt, _inPid);
if (_inputVectors.count() != _inArrayCnt ||
_inputScalars.count() != _inScalarCnt - _inPid ||
_inputStrings.count() != _inStringCnt) {
_plugin = 0L;
return false;
}
_outScalarCnt = 0;
_outArrayCnt = 0;
_outStringCnt = 0;
_outputVectors.clear();
_outputScalars.clear();
_outputStrings.clear();
const QValueList<Plugin::Data::IOValue>& otable = plugin->data()._outputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin();
it != otable.end();
++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
KstVectorPtr v;
if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
v = new KstVector(QString::null, 0, true);
} else {
v = new KstVector;
}
v->writeLock();
v->setProvider(this);
_outputVectors.insert((*it)._name, v);
_outArrayCnt++;
KST::addVectorToList(v);
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
KstScalarPtr s = new KstScalar;
s->writeLock();
s->setProvider(this);
_outputScalars.insert((*it)._name, s);
_outScalarCnt++;
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
KstStringPtr s = new KstString;
s->writeLock();
s->setProvider(this);
_outputStrings.insert((*it)._name, s);
_outStringCnt++;
}
}
allocateParameters();
_plugin = plugin;
return true;
}
示例10: KstDataObject
KstPlugin::KstPlugin(const QDomElement& e)
: KstDataObject(e) {
QString pluginName;
_inStringCnt = 0;
_outStringCnt = 0;
commonConstructor();
QDomNode n = e.firstChild();
while (!n.isNull()) {
QDomElement e = n.toElement();
if (!e.isNull()) {
if (e.tagName() == "tag") {
setTagName(e.text());
} else if (e.tagName() == "name") {
pluginName = e.text();
} else if (e.tagName() == "ivector") {
_inputVectorLoadQueue.append(qMakePair(e.attribute("name"), e.text()));
} else if (e.tagName() == "iscalar") {
_inputScalarLoadQueue.append(qMakePair(e.attribute("name"), e.text()));
} else if (e.tagName() == "istring") {
_inputStringLoadQueue.append(qMakePair(e.attribute("name"), e.text()));
} else if (e.tagName() == "ovector") {
KstVectorPtr v;
if (e.attribute("scalarList", "0").toInt()) {
v = new KstVector(e.text(), 0, true);
} else {
v = new KstVector(e.text(), 0, false);
}
v->setProvider(this);
_outputVectors.insert(e.attribute("name"), v);
KST::addVectorToList(v);
} else if (e.tagName() == "oscalar") {
KstScalarPtr sp = new KstScalar(e.text());
sp->writeLock();
sp->setProvider(this);
sp->writeUnlock();
_outputScalars.insert(e.attribute("name"), sp);
} else if (e.tagName() == "ostring") {
KstStringPtr sp = new KstString(e.text());
sp->writeLock();
sp->setProvider(this);
sp->writeUnlock();
_outputStrings.insert(e.attribute("name"), sp);
}
}
n = n.nextSibling();
}
_plugin = PluginCollection::self()->plugin(pluginName);
if (!_plugin.data()) {
KstDebug::self()->log(i18n("Unable to load plugin %1 for \"%2\".").arg(pluginName).arg(tagName()), KstDebug::Warning);
} else {
Plugin::countScalarsVectorsAndStrings(_plugin->data()._inputs, _inScalarCnt, _inArrayCnt, _inStringCnt, _inPid);
const QValueList<Plugin::Data::IOValue>& otable = _plugin->data()._outputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin();
it != otable.end();
++it) {
// FIXME: i18n?
if ((*it)._type == Plugin::Data::IOValue::TableType) {
_outArrayCnt++;
if (!_outputVectors.contains((*it)._name)) {
KstVectorPtr v;
if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
v = new KstVector(tagName() + " vector - " + (*it)._name, 0, true);
} else {
v = new KstVector(tagName() + " vector - " + (*it)._name, 0, false);
}
v->setProvider(this);
_outputVectors.insert((*it)._name, v);
KST::addVectorToList(v);
}
} else if ((*it)._type == Plugin::Data::IOValue::MatrixType) {
abort(); // FIXME:
#if 0
_outArrayCnt += 2;
if (!_outputMatrices.contains((*it)._name)) {
KstMatrixPtr m;
if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
m = new KstMatrix(tagName() + " matrix - " + (*it)._name, 0, true);
} else {
m = new KstMatrix(tagName() + " matrix - " + (*it)._name, 0, false);
}
m->setProvider(this);
_outputMatrices.insert((*it)._name, m);
KST::addVectorToList(v);
}
#endif
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
_outScalarCnt++;
if (!_outputScalars.contains((*it)._name)) {
KstScalarPtr s = new KstScalar(tagName() + " scalar - " + (*it)._name);
s->writeLock();
s->setProvider(this);
s->writeUnlock();
//.........这里部分代码省略.........
示例11: fillFieldsForEdit
void KstBasicDialogI::fillFieldsForEdit() {
KstBasicPluginPtr ptr = kst_cast<KstBasicPlugin>(_dp);
if (!ptr)
return; //shouldn't happen
ptr->readLock();
_tagName->setText(ptr->tagName());
_legendText->setText(defaultTag); //FIXME?
//Update the various widgets...
//input vectors...
QStringList iv = ptr->inputVectorList();
QStringList::ConstIterator ivI = iv.begin();
for (; ivI != iv.end(); ++ivI) {
KstVectorPtr p = ptr->inputVector(*ivI);
QString t = p ? p->tagName() : QString::null;
if (VectorSelector *w = vector(*ivI)) {
w->setSelection(t);
}
}
//input scalars...
QStringList is = ptr->inputScalarList();
QStringList::ConstIterator isI = is.begin();
for (; isI != is.end(); ++isI) {
KstScalarPtr p = ptr->inputScalar(*isI);
QString t = p ? p->tagName() : QString::null;
if (ScalarSelector *w = scalar(*isI)) {
w->setSelection(t);
}
}
//input strings...
QStringList istr = ptr->inputStringList();
QStringList::ConstIterator istrI = istr.begin();
for (; istrI != istr.end(); ++istrI) {
KstStringPtr p = ptr->inputString(*istrI);
QString t = p ? p->tagName() : QString::null;
if (StringSelector *w = string(*istrI)) {
w->setSelection(t);
}
}
//output vectors...
QStringList ov = ptr->outputVectorList();
QStringList::ConstIterator ovI = ov.begin();
for (; ovI != ov.end(); ++ovI) {
KstVectorPtr p = ptr->outputVector(*ovI);
QString t = p ? p->tagName() : QString::null;
if (QLineEdit *w = output(*ovI)) {
w->setText(t);
w->setEnabled(false);
}
}
//output scalars...
QStringList os = ptr->outputScalarList();
QStringList::ConstIterator osI = os.begin();
for (; osI != os.end(); ++osI) {
KstScalarPtr p = ptr->outputScalar(*osI);
QString t = p ? p->tagName() : QString::null;
if (QLineEdit *w = output(*osI)) {
w->setText(t);
w->setEnabled(false);
}
}
//ouput strings...
QStringList ostr = ptr->outputStringList();
QStringList::ConstIterator ostrI = ostr.begin();
for (; ostrI != ostr.end(); ++ostrI) {
KstStringPtr p = ptr->outputString(*ostrI);
QString t = p ? p->tagName() : QString::null;
if (QLineEdit *w = output(*ostrI)) {
w->setText(t);
w->setEnabled(false);
}
}
ptr->unlock();
adjustSize();
resize(minimumSizeHint());
setFixedHeight(height());
}