Skip to content

Commit

Permalink
refs #5693. Fixed color map switching.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawrainey committed Jul 8, 2013
1 parent 6b16ed8 commit 4bf72a5
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 80 deletions.
172 changes: 96 additions & 76 deletions Code/Mantid/MantidPlot/src/PlotDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1849,8 +1849,8 @@ void PlotDialog::insertTabs(int plot_type)

void PlotDialog::clearTabWidget()
{
privateTabWidget->removeTab(privateTabWidget->indexOf(labelsPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(axesPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(labelsPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(axesPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(linePage));
privateTabWidget->removeTab(privateTabWidget->indexOf(symbolPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(errorsPage));
Expand All @@ -1860,9 +1860,9 @@ void PlotDialog::clearTabWidget()
privateTabWidget->removeTab(privateTabWidget->indexOf(boxPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(percentilePage));
privateTabWidget->removeTab(privateTabWidget->indexOf(spectrogramPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(piePage));
privateTabWidget->removeTab(privateTabWidget->indexOf(pieGeometryPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(pieLabelsPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(piePage));
privateTabWidget->removeTab(privateTabWidget->indexOf(pieGeometryPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(pieLabelsPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(layerPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(layerGeometryPage));
privateTabWidget->removeTab(privateTabWidget->indexOf(fontsPage));
Expand Down Expand Up @@ -2390,64 +2390,73 @@ bool PlotDialog::acceptParams()
if (!graph)
return false;

if (privateTabWidget->currentPage() == axesPage){
plotItem->setAxis(boxXAxis->currentIndex() + 2, boxYAxis->currentIndex());
if (privateTabWidget->currentPage() == axesPage)
{
plotItem->setAxis(boxXAxis->currentIndex() + 2, boxYAxis->currentIndex());
graph->setAutoScale();
return true;
} else if (privateTabWidget->currentPage() == spectrogramPage){
Spectrogram *sp = dynamic_cast<Spectrogram*>(plotItem);
if (!sp || sp->rtti() != QwtPlotItem::Rtti_PlotSpectrogram)
{
return false;
}
if (grayScaleBox->isChecked()){
sp->setGrayScale();
} else if (defaultScaleBox->isChecked()){
sp->setDefaultColorMap();
}
//if customScaleBox radiobutton is selected it loads teh colormap file and
}
else if (privateTabWidget->currentPage() == spectrogramPage)
{
Spectrogram *sp = dynamic_cast<Spectrogram*>(plotItem);

if (!sp || sp->rtti() != QwtPlotItem::Rtti_PlotSpectrogram) { return false; }

if (grayScaleBox->isChecked())
{
sp->setGrayScale();
}
else if (defaultScaleBox->isChecked())
{
sp->setDefaultColorMap();
}
//if customScaleBox radiobutton is selected it loads the colormap file and
//updates the spectrogram,colormap widget with the loaded file
else if (customScaleBox->isChecked()){
sp->mutableColorMap().loadMap(mCurrentColorMap);
// sp->setDefaultColorMap();
sp->setCustomColorMap(sp->mutableColorMap());
//sets the selected colormapfile name to spectrogram
sp->setColorMapFileName(mCurrentColorMap);
//saves the settings
sp->saveSettings();
}

sp->showColorScale((QwtPlot::Axis)colorScaleBox->currentItem(), axisScaleBox->isChecked());
sp->setColorBarWidth(colorScaleWidthBox->value());
else if (customScaleBox->isChecked())
{
sp->mutableColorMap().loadMap(mCurrentColorMap);
// sp->setDefaultColorMap();
sp->setCustomColorMap(sp->mutableColorMap());
//sets the selected colormapfile name to spectrogram
sp->setColorMapFileName(mCurrentColorMap);
//saves the settings
sp->saveSettings();
}

sp->showColorScale((QwtPlot::Axis)colorScaleBox->currentItem(), axisScaleBox->isChecked());
sp->setColorBarWidth(colorScaleWidthBox->value());

//Update axes page
boxXAxis->setCurrentItem(sp->xAxis()-2);
boxYAxis->setCurrentItem(sp->yAxis());
}
else if (privateTabWidget->currentPage() == contourLinesPage)
{
Spectrogram *sp = dynamic_cast<Spectrogram*>(plotItem);

//Update axes page
boxXAxis->setCurrentItem(sp->xAxis()-2);
boxYAxis->setCurrentItem(sp->yAxis());
}else if (privateTabWidget->currentPage() == contourLinesPage){
if (!sp || sp->rtti() != QwtPlotItem::Rtti_PlotSpectrogram) { return false; }

Spectrogram *sp = dynamic_cast<Spectrogram*>(plotItem);
if (!sp || sp->rtti() != QwtPlotItem::Rtti_PlotSpectrogram)
{
return false;
if (defaultContourBox->isChecked())
{
QPen pen = QPen(levelsColorBox->color(), contourWidthBox->value(),Graph::getPenStyle(boxContourStyle->currentIndex()));
pen.setCosmetic(true);
sp->setDefaultContourPen(pen);
sp->setColorMapPen(false);
}
if (defaultContourBox->isChecked()){
QPen pen = QPen(levelsColorBox->color(), contourWidthBox->value(),Graph::getPenStyle(boxContourStyle->currentIndex()));
pen.setCosmetic(true);
sp->setDefaultContourPen(pen);
sp->setColorMapPen(false);
} else if (customPenBtn->isChecked())
else if (customPenBtn->isChecked())
contourLinesEditor->updateContourPens();
else
sp->setColorMapPen();

contourLinesEditor->updateContourLevels();
contourLinesEditor->updateContourLevels();
sp->setDisplayMode(QwtPlotSpectrogram::ContourMode, levelsGroupBox->isChecked());
labelsGroupBox->setChecked(levelsGroupBox->isChecked());
labelsGroupBox->setEnabled(levelsGroupBox->isChecked());
sp->showContourLineLabels(levelsGroupBox->isChecked());
}
else if (privateTabWidget->currentPage() == linePage){
int index = item->plotItemIndex();
}
else if (privateTabWidget->currentPage() == linePage)
{
int index = item->plotItemIndex();
graph->setCurveStyle(index, boxConnect->currentIndex());
QBrush br = QBrush(boxAreaColor->color(), boxPattern->getSelectedPattern());
if (!fillGroupBox->isChecked())
Expand All @@ -2457,34 +2466,44 @@ bool PlotDialog::acceptParams()
QPen pen = QPen(boxLineColor->color(), boxLineWidth->value(), Graph::getPenStyle(boxLineStyle->currentIndex()));
QwtPlotCurve *curve = dynamic_cast<QwtPlotCurve *>(plotItem);
curve->setPen(pen);
} else if (privateTabWidget->currentPage() == symbolPage){
int size = 2*boxSymbolSize->value()+1;
}
else if (privateTabWidget->currentPage() == symbolPage)
{
int size = 2*boxSymbolSize->value()+1;
QBrush br = QBrush(boxFillColor->color(), Qt::SolidPattern);

if (!boxFillSymbol->isChecked())
br = QBrush();

QPen pen = QPen(boxSymbolColor->color(), boxPenWidth->value(), Qt::SolidLine);
QwtSymbol s = QwtSymbol(boxSymbolStyle->selectedSymbol(), br, pen, QSize(size, size));
QwtPlotCurve *curve = dynamic_cast<QwtPlotCurve*>(plotItem);
curve->setSymbol(s);
} else if (privateTabWidget->currentPage() == histogramPage){
QwtHistogram *h = dynamic_cast<QwtHistogram*>(plotItem);
if (!h)
}
else if (privateTabWidget->currentPage() == histogramPage)
{
QwtHistogram *h = dynamic_cast<QwtHistogram*>(plotItem);
if (!h)
return false;

if (validInput()){
if (h->autoBinning() == automaticBox->isChecked() &&
if (validInput())
{
if (h->autoBinning() == automaticBox->isChecked() &&
h->binSize() == binSizeBox->text().toDouble() &&
h->begin() == histogramBeginBox->text().toDouble() &&
h->end() == histogramEndBox->text().toDouble()) return true;

h->setBinning(automaticBox->isChecked(), binSizeBox->text().toDouble(),
histogramBeginBox->text().toDouble(), histogramEndBox->text().toDouble());
h->loadData();
graph->updateScale();
graph->notifyChanges();
return true;
}
} else if (privateTabWidget->currentPage() == spacingPage)
h->setBinning(automaticBox->isChecked(), binSizeBox->text().toDouble(),
histogramBeginBox->text().toDouble(), histogramEndBox->text().toDouble());
h->loadData();

graph->updateScale();
graph->notifyChanges();

return true;
}
}
else if (privateTabWidget->currentPage() == spacingPage)
graph->setBarsGap(item->plotItemIndex(), gapBox->value(), offsetBox->value());
else if (privateTabWidget->currentPage() == vectPage){
int index = item->plotItemIndex();
Expand Down Expand Up @@ -2871,23 +2890,24 @@ void PlotDialog::customVectorsPage(bool angleMag)

void PlotDialog::showColorMapEditor(bool)
{
if (grayScaleBox->isChecked() || defaultScaleBox->isChecked())
{
//colorMapEditor->hide();
//mSelectColormap->hide();
}
else
{
//colorMapEditor->show();
// colorMapEditor->setFocus();
}
// if (grayScaleBox->isChecked() || defaultScaleBox->isChecked())
// {
// colorMapEditor->hide();
// mSelectColormap->hide();
// }
// else
// {
// colorMapEditor->show();
// colorMapEditor->setFocus();
// }
}

void PlotDialog::showSelectColorMapButton(bool )
{
mSelectColormap->show();
mSelectColormap->show();
connect(mSelectColormap,SIGNAL(clicked()),this,SLOT(changeColormap()));

}

/**
This slot gets called on clicking slect colormap button
*/
Expand Down
6 changes: 4 additions & 2 deletions Code/Mantid/MantidPlot/src/Spectrogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ void Spectrogram::setGrayScale()

void Spectrogram::setDefaultColorMap()
{
//color_map = defaultColorMap();
//setColorMap(color_map);
//Pass the spectrogram default (__standard) string to use as colormap.
mColorMap.setupDefaultMap();

setColorMap(mColorMap);
color_map_policy = Default;

Expand Down Expand Up @@ -340,6 +341,7 @@ void Spectrogram::setCustomColorMap(const QwtColorMap &map)
colorAxis->setColorMap(this->data().range(), this->getColorMap());
}
}

void Spectrogram::setCustomColorMap(const QwtLinearColorMap& map)
{
setColorMap(map);
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/MantidColorMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class EXPORT_OPT_MANTIDQT_API MantidColorMap : public QwtColorMap

void setupDefaultMap();

void buildColorMap(std::string);

QRgb rgb(const QwtDoubleInterval & interval, double value) const;

double normalize(const QwtDoubleInterval &interval, double value) const;
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/API/src/MantidColorMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void MantidColorMap::setNanColor(int r, int g, int b)
*/
void MantidColorMap::setupDefaultMap()
{
// The coldfire map distrubuted with qtiplot is the default and putting this into a string with an @ separator was the
// The __standard map distrubuted with qtiplot is the default and putting this into a string with an @ separator was the
// easiest way to construct it as it doesn't have a regular pattern so a loop wouldn't work.
std::string colorstring =
"0 172 252@0 170 252@0 168 252@0 164 252@0 160 252@0 156 252@0 152 252@0 152 252@0 148 252@0 144 252@0 140 252@0 136 252"
Expand Down Expand Up @@ -218,7 +218,7 @@ void MantidColorMap::setupDefaultMap()
std::stringstream reader(line);
reader >> red >> green >> blue;
m_colors.push_back(qRgb((unsigned char)(red), (unsigned char)green, (unsigned char)blue));
}
}
this->setNanColor(255,255,255);
}

Expand Down

0 comments on commit 4bf72a5

Please sign in to comment.