void KstMatrixTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QColorGroup& cg ) { KstMatrixList matrices = KST::matrixList; KstMatrixPtr matrix = *matrices.findTag(_strMatrix); QString str; double value; painter->eraseRect( 0, 0, cr.width(), cr.height() ); if (selected) { painter->fillRect( 0, 0, cr.width(), cr.height(), cg.highlight() ); painter->setPen(cg.highlightedText()); } else { painter->fillRect( 0, 0, cr.width(), cr.height(), cg.base() ); painter->setPen(cg.text()); } if (matrix) { bool ok; value = matrix->valueRaw(col, row, &ok); if (ok) { str.setNum(value, 'g', 16); } } painter->drawText(0, 0, cr.width(), cr.height(), AlignLeft, str); }
void MatrixSelector::update() { QString prev = _matrix->currentText(); QString tag; bool found = false; int index; /* xxx if (_matrix->listBox()->isVisible()) { QTimer::singleShot(250, this, SLOT(update())); return; } */ blockSignals(true); _matrix->clear(); if (_provideNoneMatrix) { _matrix->insertItem(0, "<None>"); } KstMatrixList matrices = KST::matrixList.list(); KST::matrixList.lock().readLock(); for (KstMatrixList::ConstIterator i = matrices.begin(); i != matrices.end(); ++i) { (*i)->readLock(); tag = (*i)->tag().displayString(); (*i)->unlock(); _matrix->addItem(tag); if (!found && tag == prev) { found = true; } } KST::matrixList.lock().unlock(); if (found) { index = _matrix->findText(prev); if (index != -1) { _matrix->setCurrentIndex(index); } } blockSignals(false); setEdit(_matrix->currentText()); }
QString KstIfaceImpl::createImage(const QString &name, const QString &in_matrix, double lowerZ, double upperZ, const QString &paletteName, int numContours, const QColor& contourColor, uint imageType) { //get the matrix KstMatrixList matrices = kstObjectSubList<KstDataObject, KstMatrix>(KST::dataObjectList); KstMatrixPtr matrix = *matrices.findTag(in_matrix); if (!matrix) { return QString::null; } //make a name if necessary QString imgtag; if (name.isEmpty()) { imgtag = KST::suggestImageName(in_matrix); } else { QString imgtag_end = QString(name); //count number of data objects and make a unique name int i = KST::dataObjectList.count() + 1; imgtag = QString::number(i) + "-" + imgtag_end; } while (KstData::self()->dataTagNameNotUnique(imgtag, false)) { imgtag += "\'"; } //determine the image type KstImagePtr image; if (imageType == 0) { //need a colormap if (lowerZ > upperZ) { return QString::null; } KPalette* pal = new KPalette(paletteName); matrix->readLock(); image = new KstImage(imgtag, matrix, lowerZ, upperZ, false, pal); matrix->unlock(); } else if (imageType == 1) { //need a contourmap if (numContours < 1) { return QString::null; } matrix->readLock(); image = new KstImage(imgtag, matrix, numContours, contourColor.isValid() ? contourColor : QColor("darkBlue"), 0); matrix->unlock(); } else if (imageType == 2) { //need both contourmap and colormap if (lowerZ > upperZ) { return QString::null; } if (numContours < 1) { return QString::null; } KPalette* pal = new KPalette(paletteName); matrix->readLock(); image = new KstImage(imgtag, matrix, lowerZ, upperZ, false, pal, numContours, contourColor.isValid() ? contourColor : QColor("darkBlue"), 0); matrix->unlock(); } else { return QString::null; } KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(KstDataObjectPtr(image)); KST::dataObjectList.lock().unlock(); _doc->forceUpdate(); _doc->setModified(); return imgtag; }