コード例 #1
0
void KstImageDialogI::fillFieldsForEditNoUpdate() {
  KstImagePtr ip = kst_cast<KstImage>(_dp);
  if (!ip) {
    return; // shouldn't be needed
  }

  KstImageList images = kstObjectSubList<KstDataObject, KstImage>(KST::dataObjectList);

  ip->readLock();
  // fill in the tag name
  _tagName->setText(ip->tagName());

  // fill in the other parameters
  _w->_lowerZ->setText(QString::number(ip->lowerThreshold()));
  _w->_upperZ->setText(QString::number(ip->upperThreshold()));
  _w->_realTimeAutoThreshold->setChecked(ip->autoThreshold());

  _w->_colorPalette->refresh(ip->paletteName());
  _w->_numContourLines->setValue(ip->numContourLines());
  _w->_contourColor->setColor(ip->contourColor());
  int tempWeight = ip->contourWeight();
  _w->_useVariableWeight->setChecked(tempWeight == -1);
  if (tempWeight >= 0) {
    _w->_contourWeight->setValue(tempWeight);
  }

  ip->unlock();

  //don't place the image in edits
  _w->_curvePlacement->hide();

  updateEnables();
}
コード例 #2
0
bool KstImageDialogI::editSingleObject(KstImagePtr imPtr) {
  KstMatrixPtr pMatrix;
  if (_matrixDirty) {
    //find the pMatrix
    KST::matrixList.lock().readLock();
    pMatrix = *KST::matrixList.findTag(_w->_matrix->selectedMatrix());
    KST::matrixList.lock().unlock();

    if (!pMatrix) {
      KMessageBox::sorry(this, i18n("Matrix is a 2D grid of numbers, used to create image", "Could not find pMatrix."));
      return false;
    }
  } else {
    imPtr->readLock();
    pMatrix = imPtr->matrix();
    imPtr->unlock();
  }

  imPtr->writeLock();

  // if image type was changed, get all parameters from the dialog
  if (_contourOnlyDirty || _colorOnlyDirty || _colorAndContourDirty) {
    double lowerZDouble, upperZDouble;
    if (!checkParameters(lowerZDouble, upperZDouble)) {
      //KMessageBox::sorry(this, i18n("Image type was changed: Lower Z threshold cannot be higher than Upper Z threshold."));
      //pMatrix->unlock();
      imPtr->unlock();
      return false;
    }
    if (_w->_contourOnly->isChecked()) {
      //need a contour map only
      QColor tempColor = _w->_contourColor->color();
      imPtr->changeToContourOnly(imPtr->tagName(), pMatrix, _w->_numContourLines->text().toInt(), tempColor,
                              _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
    } else if (_w->_colorOnly->isChecked()) {
      //need a color map only
      KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette());
      imPtr->changeToColorOnly(imPtr->tagName(), pMatrix, lowerZDouble, upperZDouble,
                            _w->_realTimeAutoThreshold->isChecked(), newPal);
    } else {
      //need both a contour map and colour map
      QColor tempColor = _w->_contourColor->color();
      KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette());
      imPtr->changeToColorAndContour(imPtr->tagName(), pMatrix, lowerZDouble, upperZDouble,
                                  _w->_realTimeAutoThreshold->isChecked(), newPal,
                                  _w->_numContourLines->text().toInt(), tempColor,
                                  _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
    }
  } else {
    // get the current or new parameters as required
    QColor pContourColor;
    double pLowerZ, pUpperZ;
    int pNumContours, pContourWeight;
    bool pRealTimeAutoThreshold, pUseVariableWeight;

    if (_lowerZDirty) {
      pLowerZ = _w->_lowerZ->text().toDouble();
    } else {
      pLowerZ = imPtr->lowerThreshold();
    }

    if (_upperZDirty) {
      pUpperZ = _w->_upperZ->text().toDouble();
    } else {
      pUpperZ = imPtr->upperThreshold();
    }

    if (_realTimeAutoThresholdDirty) {
      pRealTimeAutoThreshold = _w->_realTimeAutoThreshold->isChecked();
    } else {
      pRealTimeAutoThreshold = imPtr->autoThreshold();
    }

    if (_numContourLinesDirty) {
      pNumContours = _w->_numContourLines->text().toInt();
    } else {
      pNumContours = imPtr->numContourLines();
    }

    if (_contourWeightDirty) {
      pContourWeight = _w->_contourWeight->value();
    } else {
      pContourWeight = imPtr->contourWeight();
    }

    if (_useVariableWeightDirty) {
      pUseVariableWeight = _w->_useVariableWeight->isChecked();
    } else {
      pUseVariableWeight = imPtr->contourWeight() == -1;
    }

    if (_contourColorDirty) {
      pContourColor = _w->_contourColor->color();
    } else {
      pContourColor = imPtr->contourColor();
    }

    // check parameters for color map
    if (imPtr->hasColorMap()) {
      if (pLowerZ > pUpperZ) {
        //KMessageBox::sorry(this, i18n("The Lower Z threshold cannot be higher than Upper Z threshold."));
        //pMatrix->unlock();
        imPtr->unlock();
        return false;
      }
    }

    // don't change the image type, just change applicable settings for the
    // current image type
    if (imPtr->hasContourMap() && !imPtr->hasColorMap()) {
      imPtr->changeToContourOnly(imPtr->tagName(), pMatrix, pNumContours, pContourColor,
          pUseVariableWeight ? -1 : pContourWeight);
    } else {
      KPalette *palette;
      if (_paletteDirty) {
        palette = new KPalette(_w->_colorPalette->selectedPalette());
      } else {
        palette = imPtr->palette();
      }

      if (imPtr->hasColorMap() && !imPtr->hasContourMap()) {
        imPtr->changeToColorOnly(imPtr->tagName(), pMatrix, pLowerZ, pUpperZ,
            pRealTimeAutoThreshold, palette);
      } else {
        // images always have at least one of color or contour maps
        imPtr->changeToColorAndContour(imPtr->tagName(), pMatrix, pLowerZ, pUpperZ,
            pRealTimeAutoThreshold, palette,
            pNumContours, pContourColor,
            pUseVariableWeight ? -1 : pContourWeight);
      }
    }
  }


  imPtr->unlock();

  return true;
}