cppcheck warnings.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-08-02 15:12:13 +03:00
parent 3e12775a22
commit ffb6f1fbd5
29 changed files with 56 additions and 86 deletions

View file

@ -228,7 +228,6 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress uninitMemberVar
MApplication::MApplication(int &argc, char **argv)
:VAbstractApplication(argc, argv),
mainWindows(),

View file

@ -574,8 +574,7 @@ void TMainWindow::FileSave()
else
{
QString error;
bool result = SaveMeasurements(curFile, error);
if (not result)
if (not SaveMeasurements(curFile, error))
{
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning);
@ -1534,9 +1533,7 @@ void TMainWindow::SaveMValue()
return;
}
const bool ok = EvalFormula(text, true, meash->GetData(), ui->labelCalculatedValue);
if (not ok)
if (not EvalFormula(text, true, meash->GetData(), ui->labelCalculatedValue))
{
return;
}

View file

@ -615,9 +615,7 @@ void DialogIncrements::SaveIncrFormula()
}
QSharedPointer<VIncrement> incr = data->GetVariable<VIncrement>(nameField->text());
const bool ok = EvalIncrementFormula(text, true, incr->GetData(), ui->labelCalculatedValue);
if (not ok)
if (not EvalIncrementFormula(text, true, incr->GetData(), ui->labelCalculatedValue))
{
return;
}

View file

@ -1021,7 +1021,7 @@ void VPattern::ParseToolBasePoint(VMainGraphicsScene *scene, const QDomElement &
SCASSERT(scene != nullptr);
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
VToolBasePoint *spoint = 0;
VToolBasePoint *spoint = nullptr;
try
{
quint32 id = 0;
@ -1034,7 +1034,7 @@ void VPattern::ParseToolBasePoint(VMainGraphicsScene *scene, const QDomElement &
const qreal y = qApp->toPixel(GetParametrDouble(domElement, AttrY, "10.0"));
VPointF *point = new VPointF(x, y, name, mx, my);
VToolBasePoint::Create(id, nameActivPP, point, scene, this, data, parse, Source::FromFile);
spoint = VToolBasePoint::Create(id, nameActivPP, point, scene, this, data, parse, Source::FromFile);
}
catch (const VExceptionBadId &e)
{

View file

@ -262,7 +262,7 @@ void VAbstractConverter::ValidateInputFile(const QString &currentSchema) const
{
if (ver < MinVer())
{ // Version less than minimally supported version. Can't do anything.
throw e;
throw;
}
else if (ver > MaxVer())
{ // Version bigger than maximum supported version. We still have a chance to open the file.
@ -278,7 +278,7 @@ void VAbstractConverter::ValidateInputFile(const QString &currentSchema) const
}
else
{ // Unexpected version. Most time mean that we do not catch all versions between min and max.
throw e;
throw;
}
return; // All is fine and we can try to convert to current max version.

View file

@ -1218,30 +1218,19 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
switch (tags.indexOf(tag))
{
case 0: //TagUnit
{
return QDomElement();
break;// Mandatory tag
}
return QDomElement();// Mandatory tag
case 1: //TagImage
{
element = createElement(TagImage);
break;
}
case 2: //TagAuthor
{
element = createElement(TagAuthor);
break;
}
case 3: //TagDescription
{
element = createElement(TagDescription);
break;
}
case 4: //TagNotes
{
element = createElement(TagNotes);
break;
}
case 5: //TagGradation
{
element = createElement(TagGradation);
@ -1256,46 +1245,28 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
break;
}
case 6: // TagPatternName
{
element = createElement(TagPatternName);
break;
}
case 7: // TagPatternNum
{
element = createElement(TagPatternNum);
break;
}
case 8: // TagCompanyName
{
element = createElement(TagCompanyName);
break;
}
case 9: // TagCustomerName
{
element = createElement(TagCustomerName);
break;
}
case 10: // TagSize
{
element = createElement(TagSize);
break;
}
case 11: // TagShowDate
{
element = createElement(TagShowDate);
break;
}
case 12: // TagShowMeasurements
{
element = createElement(TagShowMeasurements);
break;
}
default:
{
return QDomElement();
break;
}
}
InsertTag(tags, element);
return element;

View file

@ -351,13 +351,13 @@ quint32 VDomDocument::GetParametrId(const QDomElement &domElement) const
{
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
quint32 id = 0;
quint32 id = NULL_ID;
QString message = tr("Got wrong parameter id. Need only id > 0.");
const QString message = tr("Got wrong parameter id. Need only id > 0.");
try
{
id = GetParametrUInt(domElement, VDomDocument::AttrId, NULL_ID_STR);
if (id <= 0)
if (id == NULL_ID)
{
throw VExceptionWrongId(message, domElement);
}

View file

@ -50,7 +50,7 @@ class QMUPARSERSHARED_EXPORT QmuParserTester : public QObject // final
public:
typedef int ( QmuParserTester::*testfun_type ) ();
QmuParserTester(QObject *parent = nullptr);
explicit QmuParserTester(QObject *parent = nullptr);
private slots:
void Run();

View file

@ -172,12 +172,12 @@ bool DL_Dxf::in(std::stringstream& stream,
*/
bool DL_Dxf::readDxfGroups(FILE *fp, DL_CreationInterface* creationInterface)
{
static int line = 1;
// Read one group of the DXF file and strip the lines:
if (DL_Dxf::getStrippedLine(groupCodeTmp, DL_DXF_MAXLINE, fp) &&
DL_Dxf::getStrippedLine(groupValue, DL_DXF_MAXLINE, fp, false) )
{
static int line = 1;
groupCode = static_cast<quint32>(toInt(groupCodeTmp));
creationInterface->processCodeValuePair(groupCode, groupValue);
@ -196,12 +196,11 @@ bool DL_Dxf::readDxfGroups(FILE *fp, DL_CreationInterface* creationInterface)
bool DL_Dxf::readDxfGroups(std::stringstream& stream,
DL_CreationInterface* creationInterface)
{
static int line = 1;
// Read one group of the DXF file and chop the lines:
if (DL_Dxf::getStrippedLine(groupCodeTmp, DL_DXF_MAXLINE, stream) &&
DL_Dxf::getStrippedLine(groupValue, DL_DXF_MAXLINE, stream, false) )
{
static int line = 1;
groupCode = static_cast<quint32>(toInt(groupCodeTmp));

View file

@ -43,7 +43,7 @@ class VArcData : public QSharedData
public:
VArcData();
VArcData(qreal radius, QString formulaRadius);
VArcData(qreal radius);
explicit VArcData(qreal radius);
VArcData(const VArcData &arc);
virtual ~VArcData();

View file

@ -81,6 +81,7 @@ protected:
private:
QSharedDataPointer<VEllipticalArcData> d;
// cppcheck-suppress unusedPrivateFunction
QVector<qreal> GetAngles () const;
qreal MaxLength() const;
QPointF GetPoint (qreal angle) const;

View file

@ -681,7 +681,7 @@ void VLayoutDetail::SetMirror(bool value)
* @param dAng angle of rotation
* @return position of point pt after rotating it around the center for dAng radians
*/
QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) const
QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng)
{
QPointF ptDest;
QPointF ptRel = pt - ptCenter;
@ -723,10 +723,10 @@ QVector<QPointF> VLayoutDetail::Mirror(const QVector<QPointF> &points) const
* @param pt2 second point
* @return Euclidian distance between the two points
*/
qreal VLayoutDetail::GetDistance(const QPointF &pt1, const QPointF &pt2) const
qreal VLayoutDetail::GetDistance(const QPointF &pt1, const QPointF &pt2)
{
qreal dX = pt1.x() - pt2.x();
qreal dY = pt1.y() - pt2.y();
const qreal dX = pt1.x() - pt2.x();
const qreal dY = pt1.y() - pt2.y();
return qSqrt(dX*dX + dY*dY);
}

View file

@ -100,9 +100,9 @@ private:
QVector<QPointF> Map(const QVector<QPointF> &points) const;
static QVector<QPointF> RoundPoints(const QVector<QPointF> &points);
QPointF RotatePoint(const QPointF& ptCenter, const QPointF& pt, qreal dAng) const;
static QPointF RotatePoint(const QPointF& ptCenter, const QPointF& pt, qreal dAng);
QVector<QPointF> Mirror(const QVector<QPointF>& points) const;
qreal GetDistance(const QPointF& pt1, const QPointF& pt2) const;
static qreal GetDistance(const QPointF& pt1, const QPointF& pt2);
};
Q_DECLARE_TYPEINFO(VLayoutDetail, Q_MOVABLE_TYPE);

View file

@ -18,7 +18,7 @@ TextLine::TextLine()
* @brief VTextManager::VTextManager constructor
*/
VTextManager::VTextManager()
:m_font(), m_liLines(), m_liOutput()
:m_font(), m_liLines(), m_liOutput()
{}
//---------------------------------------------------------------------------------------------------------------------
@ -327,7 +327,7 @@ QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMe
{
if (qsCurrent.length() > 0)
{
qsCurrent += QLatin1Literal(" ");
qsCurrent += QLatin1String(" ");
}
// check if another word can be added into current line
if (fm.width(qsCurrent + qslWords[i]) > fW)

View file

@ -51,7 +51,7 @@ public:
void Update(const VAbstractPattern* pDoc);
protected:
QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm);
static QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm);
private:
QFont m_font;

View file

@ -88,8 +88,9 @@ QString compilerString()
{
return QLatin1String("MSVC ") + QString::number(2008 + 2 * ((_MSC_VER / 100) - 15));
}
#else
return QStringLiteral("<unknown compiler>");
#endif
return QLatin1String("<unknown compiler>");
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -90,7 +90,7 @@ QxtCsvModel::QxtCsvModel(QIODevice *file, QObject *parent, bool withHeader, QCha
\sa setSource
*/
QxtCsvModel::QxtCsvModel(const QString filename, QObject *parent, bool withHeader, QChar separator)
QxtCsvModel::QxtCsvModel(const QString &filename, QObject *parent, bool withHeader, QChar separator)
: QAbstractTableModel(parent)
{
QXT_INIT_PRIVATE(QxtCsvModel);
@ -176,7 +176,7 @@ QVariant QxtCsvModel::headerData(int section, Qt::Orientation orientation, int r
Reads in a CSV file from the provided \a file using \a codec.
*/
void QxtCsvModel::setSource(const QString filename, bool withHeader, QChar separator, QTextCodec* codec)
void QxtCsvModel::setSource(const QString &filename, bool withHeader, QChar separator, QTextCodec* codec)
{
QFile src(filename);
setSource(&src, withHeader, separator, codec);
@ -194,6 +194,7 @@ void QxtCsvModel::setSource(const QString filename, bool withHeader, QChar separ
void QxtCsvModel::setSource(QIODevice *file, bool withHeader, QChar separator, QTextCodec* codec)
{
QxtCsvModelPrivate* d_ptr = &qxt_d();
// cppcheck-suppress unreadVariable
bool headerSet = !withHeader;
if (not file->isOpen())
{
@ -653,7 +654,7 @@ void QxtCsvModel::toCSV(QIODevice* dest, bool withHeader, QChar separator, QText
Fields in the output file will be separated by \a separator. Set \a withHeader to true
to output a row of headers at the top of the file.
*/
void QxtCsvModel::toCSV(const QString filename, bool withHeader, QChar separator, QTextCodec* codec) const
void QxtCsvModel::toCSV(const QString &filename, bool withHeader, QChar separator, QTextCodec* codec) const
{
QFile dest(filename);
toCSV(&dest, withHeader, separator, codec);
@ -695,6 +696,7 @@ void QxtCsvModel::setQuoteMode(QuoteMode mode)
*/
void QxtCsvModel::setText(int row, int column, const QString& value)
{
// cppcheck-suppress indexCalled
setData(index(row, column), value);
}
@ -705,6 +707,7 @@ void QxtCsvModel::setText(int row, int column, const QString& value)
*/
QString QxtCsvModel::text(int row, int column) const
{
// cppcheck-suppress indexCalled
return data(index(row, column)).toString();
}

View file

@ -46,9 +46,9 @@ class QxtCsvModel : public QAbstractTableModel
{
Q_OBJECT
public:
QxtCsvModel(QObject *parent = nullptr);
explicit QxtCsvModel(QObject *parent = nullptr);
explicit QxtCsvModel(QIODevice *file, QObject *parent = nullptr, bool withHeader = false, QChar separator = ',');
explicit QxtCsvModel(const QString filename, QObject *parent = nullptr, bool withHeader = false,
explicit QxtCsvModel(const QString &filename, QObject *parent = nullptr, bool withHeader = false,
QChar separator = ',');
virtual ~QxtCsvModel();
@ -82,10 +82,11 @@ public:
virtual bool removeColumns(int col, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
void setSource(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr);
void setSource(const QString filename, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr);
void setSource(const QString &filename, bool withHeader = false, QChar separator = ',',
QTextCodec* codec = nullptr);
void toCSV(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr) const;
void toCSV(const QString filename, bool withHeader = false, QChar separator = ',',
void toCSV(const QString &filename, bool withHeader = false, QChar separator = ',',
QTextCodec* codec = nullptr) const;
enum QuoteOption { NoQuotes = 0,

View file

@ -134,6 +134,7 @@ static point2d_t* point_alloc()
p = (point2d_t*)malloc(sizeof(point2d_t));
assert( p != NULL );
// cppcheck-suppress memsetClassFloat
memset(p, 0, sizeof(point2d_t));
return p;

View file

@ -784,7 +784,7 @@ QString VTranslateVars::FormulaFromUser(const QString &formula, bool osSeparator
}
//---------------------------------------------------------------------------------------------------------------------
QString VTranslateVars::TryFormulaFromUser(const QString &formula, bool osSeparator) const
QString VTranslateVars::TryFormulaFromUser(const QString &formula, bool osSeparator)
{
try
{

View file

@ -54,7 +54,7 @@ public:
QString PostfixOperator(const QString &name) const;
QString FormulaFromUser(const QString &formula, bool osSeparator) const;
QString TryFormulaFromUser(const QString &formula, bool osSeparator) const;
static QString TryFormulaFromUser(const QString &formula, bool osSeparator);
QString FormulaToUser(const QString &formula, bool osSeparator) const;
virtual void Retranslate() Q_DECL_OVERRIDE;

View file

@ -599,6 +599,7 @@ bool VToolSplinePath::IsMovable(int index) const
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
//index == -1 - can delete, but decided to left
// cppcheck-suppress redundantCondition
if (index == -1 || index < 1 || index > splPath->CountSubSpl())
{
return false;

View file

@ -46,10 +46,9 @@ VToolLinePoint::VToolLinePoint(VAbstractPattern *doc, VContainer *data, const qu
const QString &lineColor, const QString &formula, const quint32 &basePointId,
const qreal &angle, QGraphicsItem *parent)
:VToolSinglePoint(doc, data, id, parent), formulaLength(formula), angle(angle), basePointId(basePointId),
mainLine(nullptr), lineColor(ColorBlack)
mainLine(nullptr), lineColor(lineColor)
{
this->typeLine = typeLine;
this->lineColor = lineColor;
Q_ASSERT_X(basePointId != 0, Q_FUNC_INFO, "basePointId == 0"); //-V654 //-V712
QPointF point1 = *data->GeometricObject<VPointF>(basePointId);
QPointF point2 = *data->GeometricObject<VPointF>(id);

View file

@ -49,10 +49,9 @@ VToolLine::VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint3
const QString &typeLine, const QString &lineColor, const Source &typeCreation,
QGraphicsItem *parent)
:VDrawTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint),
lineColor(ColorBlack)
lineColor(lineColor)
{
this->typeLine = typeLine;
this->lineColor = lineColor;
//Line
const QSharedPointer<VPointF> first = data->GeometricObject<VPointF>(firstPoint);
const QSharedPointer<VPointF> second = data->GeometricObject<VPointF>(secondPoint);

View file

@ -306,7 +306,7 @@ void VAbstractTool::AddRecord(const quint32 id, const Tool &toolType, VAbstractP
}
quint32 cursor = doc->getCursor();
if (cursor <= 0)
if (cursor == NULL_ID)
{
history->append(record);
}

View file

@ -91,15 +91,14 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
painter->fillRect(option->rect, QColor(251, 251, 175));
painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
// draw text lines
int iY = 0;
int iH = 0;
painter->setPen(Qt::black);
QFont fnt = m_tm.GetFont();
for (int i = 0; i < m_tm.GetCount(); ++i)
{
const TextLine& tl = m_tm.GetLine(i);
iH = tl.m_iHeight;
// draw text lines
int iY = 0;
int iH = tl.m_iHeight;
fnt.setPixelSize(m_tm.GetFont().pixelSize() + tl.m_iFontSize);
fnt.setWeight(tl.m_eFontWeight);
fnt.setStyle(tl.m_eStyle);
@ -562,7 +561,7 @@ QRectF VTextGraphicsItem::GetBoundingRect(QRectF rectBB, qreal dRot) const
qreal dY1 = 0;
qreal dY2 = 0;
double dAng = qDegreesToRadians(dRot);
double dAng = qDegreesToRadians(dRot);
for (int i = 0; i < 4; ++i)
{
QPointF pt = apt[i] - ptCenter;

View file

@ -52,8 +52,8 @@ class VTextGraphicsItem : public QGraphicsObject
};
public:
VTextGraphicsItem(QGraphicsItem* pParent = 0);
~VTextGraphicsItem();
explicit VTextGraphicsItem(QGraphicsItem* pParent = nullptr);
virtual ~VTextGraphicsItem();
void SetFont(const QFont& fnt);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

View file

@ -525,7 +525,6 @@ VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d
VContainer *data, const Document &parse, const Source &typeCreation,
bool retainPieces)
{
VToolUnionDetails *unionDetails = 0;
quint32 id = _id;
QString drawName;
if (typeCreation == Source::FromGui)
@ -546,10 +545,12 @@ VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d
if (parse == Document::FullParse)
{
//Scene doesn't show this tool, so doc will destroy this object.
unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation, drawName, doc);
VToolUnionDetails *unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation,
drawName, doc);
doc->AddTool(id, unionDetails);
// Unfortunatelly doc will destroy all objects only in the end, but we should delete them before each FullParse
doc->AddToolOnRemove(unionDetails);
return unionDetails;
}
//Then create new details
VNodeDetail det1p1;

View file

@ -89,7 +89,7 @@ void AddToCalc::redo()
QDomElement calcElement;
if (doc->GetActivNodeElement(VAbstractPattern::TagCalculation, calcElement))
{
if (cursor <= 0)
if (cursor == NULL_ID)
{
calcElement.appendChild(xml);
}