Skip to content

Commit

Permalink
Re #11828. Fix gcc and cppcheck errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed May 28, 2015
1 parent bcac8f5 commit 2d4aba7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 66 deletions.
16 changes: 14 additions & 2 deletions Code/Mantid/MantidPlot/src/ContourLinesEditor.cpp
Expand Up @@ -43,6 +43,8 @@
#include <QPainter>
#include <QGroupBox>

#include <stdexcept>

ContourLinesEditor::ContourLinesEditor(const QLocale& locale, int precision, QWidget* parent)
: QWidget(parent),
table(NULL),
Expand Down Expand Up @@ -186,8 +188,9 @@ void ContourLinesEditor::insertLevel()
QwtDoubleInterval range = d_spectrogram->data().range();
double current_value = sb->value();
double previous_value = range.minValue ();
sb = table_cellWidget<DoubleSpinBox>(row - 1, 0);
previous_value = sb->value();
sb = dynamic_cast<DoubleSpinBox*>(table->cellWidget(row - 1, 0));
if (sb)
previous_value = sb->value();

double val = 0.5*(current_value + previous_value);

Expand Down Expand Up @@ -419,3 +422,12 @@ ContourLinesEditor::~ContourLinesEditor()
if(penDialog)
delete penDialog;
}

template<class Widget>
Widget* ContourLinesEditor::table_cellWidget(int i, int j) const {
Widget *w = dynamic_cast<Widget*>(table->cellWidget(i, j));
if (!w) {
throw std::logic_error("Unexpected widget type in ContourLinesEditor.");
}
return w;
}
8 changes: 1 addition & 7 deletions Code/Mantid/MantidPlot/src/ContourLinesEditor.h
Expand Up @@ -79,13 +79,7 @@ protected slots:
private:
void updatePenColumn();
template<class Widget>
Widget* table_cellWidget(int i, int j) const {
Widget *w = dynamic_cast<Widget*>(table->cellWidget(i, j));
if (!w) {
throw std::logic_error("Unexpected widget type in ContourLinesEditor.");
}
return w;
}
Widget* table_cellWidget(int i, int j) const;

//! Table displaying the values ranges in the first column and their corresponding pens in the second column
QTableWidget *table;
Expand Down
74 changes: 40 additions & 34 deletions Code/Mantid/MantidPlot/src/Differentiation.cpp
Expand Up @@ -65,42 +65,48 @@ void Differentiation::init()
d_min_points = 4;
}

void Differentiation::output()
{
double *result = new double[d_n-1];
for (int i = 1; i < d_n-1; i++)
result[i]=0.5*((d_y[i+1]-d_y[i])/(d_x[i+1]-d_x[i]) + (d_y[i]-d_y[i-1])/(d_x[i]-d_x[i-1]));
void Differentiation::output() {
std::vector<double> result(d_n - 1);
for (int i = 1; i < d_n - 1; i++)
result[i] = 0.5 * ((d_y[i + 1] - d_y[i]) / (d_x[i + 1] - d_x[i]) +
(d_y[i] - d_y[i - 1]) / (d_x[i] - d_x[i - 1]));

ApplicationWindow *app = dynamic_cast<ApplicationWindow *>(parent());
if (!app) {
throw std::logic_error("Parent of Differentiation is not ApplicationWindow as expected.");
}
QLocale locale = app->locale();
QString tableName = app->generateUniqueName(QString(objectName()));
QString dataSet;
if (d_curve)
dataSet = d_curve->title().text();
else
dataSet = d_y_col_name;
ApplicationWindow *app = dynamic_cast<ApplicationWindow *>(parent());
if (!app) {
throw std::logic_error(
"Parent of Differentiation is not ApplicationWindow as expected.");
}
QLocale locale = app->locale();
QString tableName = app->generateUniqueName(QString(objectName()));
QString dataSet;
if (d_curve)
dataSet = d_curve->title().text();
else
dataSet = d_y_col_name;

d_result_table = app->newHiddenTable(tableName, tr("Derivative") + " " + tr("of","Derivative of") + " " + dataSet, d_n-2, 2);
for (int i = 1; i < d_n-1; i++) {
d_result_table->setText(i-1, 0, locale.toString(d_x[i], 'g', app->d_decimal_digits));
d_result_table->setText(i-1, 1, locale.toString(result[i], 'g', app->d_decimal_digits));
}
delete[] result;
d_result_table = app->newHiddenTable(
tableName,
tr("Derivative") + " " + tr("of", "Derivative of") + " " + dataSet,
d_n - 2, 2);
for (int i = 1; i < d_n - 1; i++) {
d_result_table->setText(
i - 1, 0, locale.toString(d_x[i], 'g', app->d_decimal_digits));
d_result_table->setText(
i - 1, 1, locale.toString(result[i], 'g', app->d_decimal_digits));
}

if (d_graphics_display){
if (!d_output_graph)
d_output_graph = createOutputGraph()->activeGraph();
if (d_graphics_display) {
if (!d_output_graph)
d_output_graph = createOutputGraph()->activeGraph();

d_output_graph->insertCurve(d_result_table, tableName + "_2", 0);
QString legend = "\\l(1)" + tr("Derivative") + " " + tr("of","Derivative of") + " " + dataSet;
LegendWidget *l = d_output_graph->legend();
if (l){
l->setText(legend);
l->repaint();
} else
d_output_graph->newLegend(legend);
}
d_output_graph->insertCurve(d_result_table, tableName + "_2", 0);
QString legend = "\\l(1)" + tr("Derivative") + " " +
tr("of", "Derivative of") + " " + dataSet;
LegendWidget *l = d_output_graph->legend();
if (l) {
l->setText(legend);
l->repaint();
} else
d_output_graph->newLegend(legend);
}
}
25 changes: 9 additions & 16 deletions Code/Mantid/MantidPlot/src/FFT.cpp
Expand Up @@ -72,12 +72,12 @@ void FFT::init ()

QString FFT::fftCurve()
{
int i, i2;
int i, i2;
int n2 = d_n/2;
double *amp = new double[d_n];
double *result = new double[2*d_n];
std::vector<double> amp(d_n);
std::vector<double> result(2*d_n);

if(!amp || !result){
if(amp.empty() || result.empty()){
QMessageBox::critical(dynamic_cast<ApplicationWindow *>(parent()), tr("MantidPlot") + " - " + tr("Error"),
tr("Could not allocate memory, operation aborted!"));
d_init_err = true;
Expand All @@ -98,36 +98,30 @@ QString FFT::fftCurve()
QMessageBox::critical(dynamic_cast<ApplicationWindow *>(parent()), tr("MantidPlot") + " - " + tr("Error"),
tr("Could not allocate memory, operation aborted!"));
d_init_err = true;
// Cleanup variables before returning
delete [] amp;
delete [] result;
return "";
}

gsl_fft_real_transform(d_y, 1, d_n, real,work);
gsl_fft_halfcomplex_unpack (d_y, result, 1, d_n);
gsl_fft_halfcomplex_unpack (d_y, result.data(), 1, d_n);

gsl_fft_real_wavetable_free(real);
gsl_fft_real_workspace_free(work);
} else {
d_explanation = tr("Inverse") + " " + tr("FFT") + " " + tr("of") + " " + d_curve->title().text();
text = tr("Time");

gsl_fft_real_unpack (d_y, result, 1, d_n);
gsl_fft_real_unpack (d_y, result.data(), 1, d_n);
gsl_fft_complex_wavetable *wavetable = gsl_fft_complex_wavetable_alloc (d_n);
gsl_fft_complex_workspace *workspace = gsl_fft_complex_workspace_alloc (d_n);

if(!workspace || !wavetable){
QMessageBox::critical(dynamic_cast<ApplicationWindow *>(parent()), tr("MantidPlot") + " - " + tr("Error"),
tr("Could not allocate memory, operation aborted!"));
d_init_err = true;
// Cleanup local variables before returning
delete [] amp;
delete [] result;
return "";
}

gsl_fft_complex_inverse (result, 1, d_n, wavetable, workspace);
gsl_fft_complex_inverse (result.data(), 1, d_n, wavetable, workspace);
gsl_fft_complex_wavetable_free (wavetable);
gsl_fft_complex_workspace_free (workspace);
}
Expand Down Expand Up @@ -159,6 +153,7 @@ QString FFT::fftCurve()
if (!app) {
throw std::logic_error("Parent of FFTDialog is not ApplicationWindow as expected.");
}

QLocale locale = app->locale();
int prec = app->d_decimal_digits;

Expand All @@ -174,9 +169,7 @@ QString FFT::fftCurve()
text += locale.toString(amp[i], 'g', prec)+"\t";
text += locale.toString(atan(result[i2+1]/result[i2]), 'g', prec)+"\n";
}
delete[] amp;
delete[] result;
return text;
return text;
}

QString FFT::fftTable()
Expand Down
10 changes: 10 additions & 0 deletions Code/Mantid/MantidPlot/src/FitDialog.cpp
Expand Up @@ -1494,3 +1494,13 @@ QString FitDialog::parseFormula(const QString& s)
}
return formula;
}

template<class Widget>
Widget* FitDialog::boxParams_cellWidget(int i, int j) const {
Widget *w = dynamic_cast<Widget*>(boxParams->cellWidget(i, j));
if (!w) {
throw std::logic_error("Unexpected widget type in FitDialog.");
}
return w;
}

8 changes: 1 addition & 7 deletions Code/Mantid/MantidPlot/src/FitDialog.h
Expand Up @@ -116,13 +116,7 @@ private slots:
QStringList plugInNames();
QString parseFormula(const QString& s);
template<class Widget>
Widget* boxParams_cellWidget(int i, int j) const {
Widget *w = dynamic_cast<Widget*>(boxParams->cellWidget(i, j));
if (!w) {
throw std::logic_error("Unexpected widget type in FitDialog.");
}
return w;
}
Widget* boxParams_cellWidget(int i, int j) const ;

Fit *d_current_fit;
Graph *d_graph;
Expand Down

0 comments on commit 2d4aba7

Please sign in to comment.