Fix warning and valgrind issues

This commit is contained in:
Jan Käberich 2022-03-17 12:53:13 +01:00
parent 1a779531ea
commit d08388f903
12 changed files with 53 additions and 18 deletions

View File

@ -790,7 +790,7 @@ bool Calibration::openFromFile(QString filename)
qDebug() << "Associated calibration kit expected in" << calkit_file;
try {
kit = Calkit::fromFile(calkit_file);
} catch (runtime_error e) {
} catch (runtime_error &e) {
InformationBox::ShowError("Missing calibration kit", "The calibration kit file associated with the selected calibration could not be parsed. The calibration might not be accurate. (" + QString(e.what()) + ")");
qWarning() << "Parsing of calibration kit failed while opening calibration file: " << e.what();
}
@ -809,7 +809,7 @@ bool Calibration::openFromFile(QString filename)
nlohmann::json j;
file >> j;
fromJSON(j);
} catch(exception e) {
} catch(exception &e) {
// json parsing failed, probably using a legacy file format
try {
file.clear();
@ -818,7 +818,7 @@ bool Calibration::openFromFile(QString filename)
InformationBox::ShowMessage("Loading calibration file", "The file \"" + filename + "\" is stored in a deprecated"
" calibration format. Future versions of this application might not support"
" it anymore. Please save the calibration to update to the new format");
} catch(exception e) {
} catch(exception &e) {
InformationBox::ShowError("File parsing error", e.what());
qWarning() << "Calibration file parsing failed: " << e.what();
return false;

View File

@ -13,6 +13,7 @@ class Calkit
friend class CalkitDialog;
public:
Calkit();
Calkit(const Calkit&) = default;
Calkit& operator=(const Calkit& other)
{
this->manufacturer = other.manufacturer;

View File

@ -195,7 +195,7 @@ CalkitDialog::CalkitDialog(Calkit &c, QWidget *parent) :
if(filename.length() > 0) {
try {
ownKit = Calkit::fromFile(filename);
} catch (runtime_error e) {
} catch (runtime_error &e) {
InformationBox::ShowError("Error", "The calibration kit file could not be parsed (" + QString(e.what()) + ")");
qWarning() << "Parsing of calibration kit failed while opening calibration file: " << e.what();
}

View File

@ -113,12 +113,11 @@ QVariant JSONModel::data(const QModelIndex &index, int role) const
case 0:
return info.name;
case 1:
if(item->is_object() || item->is_array()) {
return QVariant();
} else {
if(!item->is_object() && !item->is_array()) {
return info.data;
}
}
return QVariant();
case Qt::CheckStateRole: {
if(index.column() == 0) {
return info.enabled ? Qt::Checked : Qt::Unchecked;

View File

@ -44,7 +44,7 @@ void TraceWidgetSA::importDialog()
if(AppWindow::showGUI()) {
i->show();
}
} catch(const std::exception e) {
} catch(const std::exception &e) {
InformationBox::ShowError("Failed to import file", QString("Attempt to import file ended with error: \"") + e.what()+"\"");
}
}

View File

@ -267,7 +267,7 @@ void ImpedanceMatchDialog::calculateMatch()
ui->Image->setPixmap(QPixmap(":/icons/pCsC_small.png"));
}
}
} catch (exception e){
} catch (exception &e){
// something went wrong, probably caused by (intermediate) invalid input, such as f=0Hz
ui->lValue->setValue(nan(""));
ui->cValue->setValue(nan(""));

View File

@ -81,6 +81,11 @@ static void createLogarithmicTicks(vector<double>& ticks, double start, double s
} while(div <= stop);
}
YAxis::YAxis()
{
type = Type::Magnitude;
}
double YAxis::sampleToCoordinate(Trace::Data data, Trace *t, unsigned int sample)
{
switch(type) {
@ -246,7 +251,7 @@ QString YAxis::Unit(Type type, TraceModel::DataSource source)
case Type::Reactance: return "Ω";
case Type::Capacitance: return "F";
case Type::Inductance: return "H";
case Type::Last: return "";
default: return "";
}
} else if(source == TraceModel::DataSource::SA) {
switch(type) {
@ -280,7 +285,7 @@ QString YAxis::Prefixes(Type type, TraceModel::DataSource source)
case Type::Reactance: return "m kM";
case Type::Capacitance: return "pnum ";
case Type::Inductance: return "pnum ";
case Type::Last: return " ";
default: return " ";
}
} else if(source == TraceModel::DataSource::SA) {
switch(type) {
@ -358,8 +363,14 @@ bool Axis::getLog() const
return log;
}
XAxis::XAxis()
{
type = Type::Frequency;
}
double XAxis::sampleToCoordinate(Trace::Data data, Trace *t, unsigned int sample)
{
Q_UNUSED(sample)
switch(type) {
case Type::Distance:
if(!t) {
@ -430,6 +441,16 @@ XAxis::Type XAxis::getType() const
return type;
}
Axis::Axis()
{
log = false;
autorange = true;
rangeMin = -1.0;
rangeMax = 1.0;
rangeDiv = 1.0;
ticks.clear();
}
double Axis::transform(double value, double to_low, double to_high)
{
return Util::Scale(value, rangeMin, rangeMax, to_low, to_high, log);

View File

@ -8,6 +8,7 @@
class Axis {
public:
Axis();
virtual double sampleToCoordinate(Trace::Data data, Trace *t = nullptr, unsigned int sample = 0) = 0;
double transform(double value, double to_low, double to_high);
double inverseTransform(double value, double to_low, double to_high);
@ -55,6 +56,7 @@ public:
Impedance,
Last,
};
YAxis();
double sampleToCoordinate(Trace::Data data, Trace *t = nullptr, unsigned int sample = 0) override;
void set(Type type, bool log, bool autorange, double min, double max, double div);
static QString TypeToName(Type type);
@ -80,6 +82,7 @@ public:
Power,
Last,
};
XAxis();
double sampleToCoordinate(Trace::Data data, Trace *t = nullptr, unsigned int sample = 0) override;
void set(Type type, bool log, bool autorange, double min, double max, double div);
static QString TypeToName(Type type);

View File

@ -20,6 +20,7 @@ TraceSmithChart::TraceSmithChart(TraceModel &model, QWidget *parent)
: TracePlot(model, parent)
{
limitToSpan = true;
limitToEdge = true;
edgeReflection = 1.0;
initializeTraceInfo();
}

View File

@ -21,6 +21,11 @@ TraceWaterfall::TraceWaterfall(TraceModel &model, QWidget *parent)
keepDataBeyondPlotSize(false),
maxDataSweeps(500)
{
plotAreaTop = 0;
plotAreaLeft = 0;
plotAreaWidth = 0;
plotAreaBottom = 0;
xAxis.set(XAxis::Type::Frequency, false, true, 0, 6000000000, 500000000);
yAxis.set(YAxis::Type::Magnitude, false, true, -1, 1, 1);
initializeTraceInfo();
@ -478,7 +483,7 @@ double TraceWaterfall::nearestTracePoint(Trace *t, QPoint pixel, double *distanc
QString TraceWaterfall::mouseText(QPoint pos)
{
QString ret;
if(QRect(plotAreaLeft, 0, plotAreaWidth + 1, plotAreaBottom).contains(pos)) {
if(QRect(plotAreaLeft, plotAreaTop, plotAreaWidth + 1, plotAreaBottom).contains(pos)) {
double x = xAxis.inverseTransform(pos.x(), plotAreaLeft, plotAreaLeft + plotAreaWidth);
int significantDigits = floor(log10(abs(xAxis.getRangeMax()))) - floor(log10((abs(xAxis.getRangeMax() - xAxis.getRangeMin())) / 1000.0)) + 1;
ret += Unit::ToString(x, xAxis.Unit(), "fpnum kMG", significantDigits) + "\n";

View File

@ -757,7 +757,7 @@ void VNA::fromJSON(nlohmann::json j)
EnableDeembedding(false);
}
// sweep configuration has to go last sog graphs can catch events from changed sweep
// sweep configuration has to go last so graphs can catch events from changed sweep
if(j.contains("sweep")) {
auto sweep = j["sweep"];
// restore sweep settings, keep current value as default in case of missing entry
@ -882,7 +882,7 @@ void VNA::SettingsChanged(bool resetTraces, std::function<void (Device::Transmis
}
changingSettings = true;
// assemble VNA protocol settings
Protocol::SweepSettings s;
Protocol::SweepSettings s = {};
s.suppressPeaks = Preferences::getInstance().Acquisition.suppressPeaks ? 1 : 0;
if(Preferences::getInstance().Acquisition.alwaysExciteBothPorts) {
s.excitePort1 = 1;
@ -1102,7 +1102,7 @@ void VNA::SetPowerSweepFrequency(double freq)
void VNA::SetPoints(unsigned int points)
{
auto maxPoints = Preferences::getInstance().Acquisition.allowSegmentedSweep ? UINT16_MAX : Device::Info().limits_maxPoints;
unsigned int maxPoints = Preferences::getInstance().Acquisition.allowSegmentedSweep ? UINT16_MAX : Device::Info().limits_maxPoints;
if(points > maxPoints) {
points = maxPoints;
} else if (points < 2) {
@ -1176,7 +1176,7 @@ void VNA::ApplyCalibration(Calibration::Type type)
} else {
DisableCalibration(true);
}
} catch (runtime_error e) {
} catch (runtime_error &e) {
InformationBox::ShowError("Calibration failure", e.what());
DisableCalibration(true);
}
@ -1196,8 +1196,7 @@ void VNA::ApplyCalibration(Calibration::Type type)
void VNA::StartCalibrationMeasurements(std::set<Calibration::Measurement> m)
{
auto device = window->getDevice();
if(!device) {
if(!window->getDevice()) {
return;
}
// Stop sweep

View File

@ -42,6 +42,12 @@ public:
class Settings {
public:
Settings()
: sweepType(SweepType::Frequency)
, Freq({.start=1000000, .stop=6000000000, .excitation_power=-10, .logSweep=false})
, Power({.start=-40, .stop=-10, .frequency=1000000000})
, npoints(501), bandwidth(1000), excitingPort1(true), excitingPort2(true)
, segments(1), activeSegment(0){}
SweepType sweepType;
struct {
double start;