本文整理汇总了C++中KstVectorPtr::readLock方法的典型用法代码示例。如果您正苦于以下问题:C++ KstVectorPtr::readLock方法的具体用法?C++ KstVectorPtr::readLock怎么用?C++ KstVectorPtr::readLock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KstVectorPtr
的用法示例。
在下文中一共展示了KstVectorPtr::readLock方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vectorToFile
int KST::vectorToFile(KstVectorPtr v, QFile *f) {
KstApp *app = KstApp::inst();
#define BSIZE 128
char buf[BSIZE];
v->readLock();
int vSize = v->length();
double *value = v->value();
register int modval;
QString saving = i18n("Saving vector %1").arg(v->tagName());
modval = QMAX(vSize/100, 100);
QString ltxt = "; " + v->tagName() + '\n';
f->writeBlock(ltxt.ascii(), ltxt.length());
ltxt.fill('-');
ltxt[0] = ';';
ltxt[1] = ' ';
ltxt[ltxt.length() - 1] = '\n';
f->writeBlock(ltxt.ascii(), ltxt.length());
app->slotUpdateProgress(vSize, 0, QString::null);
for (int i = 0; i < vSize; i++) {
int l = snprintf(buf, BSIZE, "%.15g\n", value[i]);
f->writeBlock(buf, l);
if (i % modval == 0) {
app->slotUpdateProgress(vSize, i, saving);
}
}
v->readUnlock();
app->slotUpdateProgress(0, 0, QString::null);
#undef BSIZE
return 0;
}
示例2: 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());
//.........这里部分代码省略.........
示例3: newObject
bool KstEqDialogI::newObject() {
QString tag_name = _tagName->text();
QString etext = _w->_equation->text();
etext.remove(QRegExp("[^a-zA-Z0-9\\(\\)\\+\\-\\*/\\%\\^\\|\\&\\!<>=_.]"));
if (etext.length() > 12) {
etext.truncate(12);
etext += "...";
}
if (tag_name == defaultTag) {
tag_name = KST::suggestEQName(etext);
}
/* verify that the curve name is unique */
if (KstData::self()->dataTagNameNotUnique(tag_name)) {
_tagName->setFocus();
return false;
}
if (!checkEntries()) {
return false;
}
KST::vectorList.lock().readLock();
/* find *V */
KstVectorPtr vp = *KST::vectorList.findTag(_w->_xVectors->selectedVector());
if (!vp) {
kstdFatal() << "Bug in kst: the Vector field (Eq) "
<< "refers to a non-existent vector..." << endl;
}
KST::vectorList.lock().unlock();
/** Create the equation here */
vp->readLock();
KstEquationPtr eq = new KstEquation(tag_name, _w->_equation->text(), vp, _w->_doInterpolation->isChecked());
vp->unlock();
if (!eq->isValid()) {
eq = 0L;
QString parseErrors;
for (QStringList::ConstIterator i = Equation::errorStack.begin(); i != Equation::errorStack.end(); ++i) {
parseErrors += *i;
parseErrors += "\n";
}
KMessageBox::detailedSorry(this, i18n("There is an error in the equation you entered."), parseErrors);
return false;
}
KstVCurvePtr vc = new KstVCurve(KST::suggestCurveName(tag_name, true), eq->vX(), eq->vY(), 0L, 0L, 0L, 0L, _w->_curveAppearance->color());
vc->setHasPoints(_w->_curveAppearance->showPoints());
vc->setHasLines(_w->_curveAppearance->showLines());
vc->setHasBars(_w->_curveAppearance->showBars());
vc->setLineWidth(_w->_curveAppearance->lineWidth());
vc->setLineStyle(_w->_curveAppearance->lineStyle());
vc->pointType = _w->_curveAppearance->pointType();
vc->setPointDensity(_w->_curveAppearance->pointDensity());
vc->setBarStyle(_w->_curveAppearance->barStyle());
QString legend_text = _legendText->text();
if (legend_text == defaultTag) {
vc->setLegendText(QString(""));
} else {
vc->setLegendText(legend_text);
}
KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(_w->_curvePlacement->_plotWindow->currentText()));
if (!w) {
QString n = KstApp::inst()->newWindow(KST::suggestWinName());
w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(n));
}
if (w) {
Kst2DPlotPtr plot;
if (_w->_curvePlacement->existingPlot()) {
/* assign curve to plot */
plot = kst_cast<Kst2DPlot>(w->view()->findChild(_w->_curvePlacement->plotName()));
if (plot) {
plot->addCurve(vc.data());
}
}
if (_w->_curvePlacement->newPlot()) {
/* assign curve to plot */
QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName());
if (_w->_curvePlacement->reGrid()) {
w->view()->cleanup(_w->_curvePlacement->columns());
}
plot = kst_cast<Kst2DPlot>(w->view()->findChild(name));
if (plot) {
_w->_curvePlacement->update();
_w->_curvePlacement->setCurrentPlot(plot->tagName());
plot->addCurve(vc.data());
plot->generateDefaultLabels();
}
}
}
KST::dataObjectList.lock().writeLock();
KST::dataObjectList.append(eq.data());
//.........这里部分代码省略.........
示例4: update
void KstObjectItem::update(bool recursive, int localUseCount) {
switch (_rtti) {
case RTTI_OBJ_DATA_VECTOR:
{
KST::vectorList.lock().readLock();
KstRVectorPtr x = kst_cast<KstRVector>(*KST::vectorList.findTag(_tag));
KST::vectorList.lock().unlock();
if (x) {
x->readLock();
// getUsage: subtract 1 for KstRVectorPtr x
bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
if (inUse != _inUse) {
_inUse = inUse;
setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
}
QString field;
if (inUse) {
field = QString::number(x->length());
} else {
field = "-";
}
if (text(3) != field) {
setText(3, field);
}
field = i18n("%3: %4 [%1..%2]").arg(x->reqStartFrame())
.arg(x->reqStartFrame() + x->reqNumFrames())
.arg(x->filename())
.arg(x->field());
if (text(4) != field) {
setText(4, field);
}
_removable = x->getUsage() == 2;
x->unlock();
}
// Hmmm what happens if this if() fails?? We become inconsistent?
break;
}
case RTTI_OBJ_STATIC_VECTOR:
{
KST::vectorList.lock().readLock();
KstSVectorPtr x = kst_cast<KstSVector>(*KST::vectorList.findTag(_tag));
KST::vectorList.lock().unlock();
if (x) {
x->readLock();
// getUsage: subtract 1 for KstRVectorPtr x
bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
if (inUse != _inUse) {
_inUse = inUse;
setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
}
QString field;
if (inUse) {
field = QString::number(x->length());
} else {
field = "-";
}
if (text(3) != field) {
setText(3, field);
}
field = i18n("%1 to %2").arg(x->min()).arg(x->max());
if (text(4) != field) {
setText(4, field);
}
_removable = x->getUsage() == 2;
x->unlock();
}
// Hmmm what happens if this if() fails?? We become inconsistent?
break;
}
case RTTI_OBJ_VECTOR:
{
KST::vectorList.lock().readLock();
KstVectorPtr x = *KST::vectorList.findTag(_tag);
KST::vectorList.lock().unlock();
if (x) {
x->readLock();
// getUsage:
// subtract 1 for KstVectorPtr x
bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
if (inUse != _inUse) {
_inUse = inUse;
setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
}
QString field = QString::number(x->length());
if (text(3) != field) {
setText(3, field);
}
field = i18n("[%1..%2]").arg(x->min()).arg(x->max());
if (text(4) != field) {
setText(4, field);
}
x->unlock();
_removable = false;
}
break;
}
case RTTI_OBJ_OBJECT:
{
KST::dataObjectList.lock().readLock();
KstDataObjectPtr x = *KST::dataObjectList.findTag(_tag.tag());
//.........这里部分代码省略.........
示例5: 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;
}
}
}
示例6: fitChanged
void KstViewFitsDialog::fitChanged(const QString& strFit) {
KstCPluginList fits;
KstCPluginPtr plugin;
double* params = 0L;
double* covars = 0L;
double chi2Nu = 0.0;
int numParams = 0;
int numCovars = 0;
int i;
fits = kstObjectSubList<KstDataObject,KstCPlugin>(KST::dataObjectList);
plugin = *(fits.findTag(strFit));
if (plugin) {
KstScalarPtr scalarChi2Nu;
KstVectorPtr vectorParam;
plugin->readLock();
const KstScalarMap& scalars = plugin->outputScalars();
scalarChi2Nu = scalars["chi^2/nu"];
if (scalarChi2Nu) {
scalarChi2Nu->readLock();
chi2Nu = scalarChi2Nu->value();
scalarChi2Nu->unlock();
}
const KstVectorMap& vectors = plugin->outputVectors();
vectorParam = vectors["Parameters"];
if (vectorParam) {
KstVectorPtr vectorCovar;
vectorParam->readLock();
vectorCovar = vectors["Covariance"];
if (vectorCovar) {
vectorCovar->readLock();
numParams = vectorParam->length();
numCovars = vectorCovar->length();
if (numParams > 0 && numCovars > 0) {
params = new double[numParams];
covars = new double[numCovars];
for (i = 0; i < numParams; i++) {
params[i] = vectorParam->value(i);
}
for (i = 0; i < numCovars; i++) {
covars[i] = vectorCovar->value(i);
}
}
vectorCovar->unlock();
}
vectorParam->unlock();
}
plugin->unlock();
}
_tableFits->setParameters(params, numParams, covars, numCovars, chi2Nu);
if (numParams > 0) {
_tableFits->horizontalHeaderItem(0)->setText(QObject::tr("Value"));
_tableFits->horizontalHeaderItem(1)->setText(QObject::tr("Covariance:"));
_tableFits->verticalHeaderItem(numParams+0)->setText("---");
_tableFits->verticalHeaderItem(numParams+1)->setText(QObject::tr("Chi^2/Nu"));
if (plugin) {
QExplicitlySharedDataPointer<Plugin> pluginBase;
plugin->readLock();
pluginBase = plugin->plugin();
if (pluginBase) {
textLabelFit->setText(pluginBase->data()._readableName);
for (i = 0; i < numParams; i++) {
QString parameterName = pluginBase->parameterName(i);
_tableFits->horizontalHeaderItem(i+2)->setText(parameterName);
_tableFits->verticalHeaderItem(i)->setText(parameterName);
}
}
plugin->unlock();
}
}
_tableFits->update();
}