Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TechDraw Coverity warning cleanup #249

Merged
merged 4 commits into from
Aug 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 34 additions & 56 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp
Original file line number Diff line number Diff line change
@@ -217,15 +217,11 @@ void DrawProjGroup::moveToCentre(void)

App::DocumentObject * DrawProjGroup::getProjObj(const char *viewProjType) const
{
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {

DrawView *view = dynamic_cast<DrawView *>(*it);
if(view->getTypeId() == DrawProjGroupItem::getClassTypeId()) {
DrawProjGroupItem *projPtr = dynamic_cast<DrawProjGroupItem *>(*it);

if( strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 )
return *it;
for( auto it : Views.getValues() ) {
auto projPtr( dynamic_cast<DrawProjGroupItem *>(it) );
if( projPtr &&
strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 ) {
return it;
}
}

@@ -234,17 +230,10 @@ App::DocumentObject * DrawProjGroup::getProjObj(const char *viewProjType) const

bool DrawProjGroup::hasProjection(const char *viewProjType) const
{
const std::vector<App::DocumentObject *> &views = Views.getValues();

for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {

TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
if(view->getTypeId() == TechDraw::DrawProjGroupItem::getClassTypeId()) {
TechDraw::DrawProjGroupItem *projPtr = dynamic_cast<TechDraw::DrawProjGroupItem *>(*it);

if( strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 ) {
return true;
}
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<TechDraw::DrawProjGroupItem *>(it) );
if( view && strcmp(viewProjType, view->Type.getValueAsString()) == 0 ) {
return true;
}
}
return false;
@@ -269,14 +258,14 @@ bool DrawProjGroup::checkViewProjType(const char *in)

App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
{
DrawProjGroupItem *view = NULL;
DrawProjGroupItem *view( nullptr );

if ( checkViewProjType(viewProjType) && !hasProjection(viewProjType) ) {
std::string FeatName = getDocument()->getUniqueObjectName("ProjItem");
App::DocumentObject *docObj = getDocument()->addObject("TechDraw::DrawProjGroupItem",
FeatName.c_str());
auto docObj( getDocument()->addObject( "TechDraw::DrawProjGroupItem",
FeatName.c_str() ) );

view = dynamic_cast<TechDraw::DrawProjGroupItem *>( docObj );
view = static_cast<TechDraw::DrawProjGroupItem *>( docObj );
view->Source.setValue( Source.getValue() );
view->ScaleType.setValue( ScaleType.getValue() );
view->Scale.setValue( Scale.getValue() );
@@ -351,23 +340,19 @@ void DrawProjGroup::setViewOrientation(DrawProjGroupItem *v, const char *projTyp
int DrawProjGroup::removeProjection(const char *viewProjType)
{
if ( checkViewProjType(viewProjType) ) {
if(!hasProjection(viewProjType)) {
if( !hasProjection(viewProjType) ) {
throw Base::Exception("The projection doesn't exist in the group");
}

// Iterate through the child views and find the projection type
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {

TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
if(view->getTypeId() == TechDraw::DrawProjGroupItem::getClassTypeId()) {
TechDraw::DrawProjGroupItem *projPtr = dynamic_cast<TechDraw::DrawProjGroupItem *>(*it);

for( auto it : Views.getValues() ) {
auto projPtr( dynamic_cast<TechDraw::DrawProjGroupItem *>(it) );
if( projPtr ) {
if ( strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 ) {
// Remove from the document
getDocument()->remObject((*it)->getNameInDocument());
getDocument()->remObject( it->getNameInDocument() );
moveToCentre();
return views.size();
return Views.getValues().size();
}
}
}
@@ -382,7 +367,7 @@ void DrawProjGroup::arrangeViewPointers(DrawProjGroupItem *viewPtrs[10]) const
viewPtrs[i] = NULL;
}

DrawProjGroupItem *anchorView = dynamic_cast<DrawProjGroupItem *>(Anchor.getValue());
auto anchorView( dynamic_cast<DrawProjGroupItem *>(Anchor.getValue()) );

if (!anchorView) { //TODO: Consider not requiring an anchor view, or allowing ones other than "Front"
throw Base::Exception("No anchor view set in DrawProjGroup::arrangeViewPointers()");
@@ -397,8 +382,6 @@ void DrawProjGroup::arrangeViewPointers(DrawProjGroupItem *viewPtrs[10]) const
}

// Iterate through views and populate viewPtrs
DrawProjGroupItem* oView;
std::vector<App::DocumentObject *> views = Views.getValues();
if ( strcmp(projType, "Third Angle") == 0 ||
strcmp(projType, "First Angle") == 0 ) {
// Third Angle: FTL T FTRight
@@ -409,10 +392,9 @@ void DrawProjGroup::arrangeViewPointers(DrawProjGroupItem *viewPtrs[10]) const
// Right F L Rear
// FTRight T FTL
bool thirdAngle = (strcmp(projType, "Third Angle") == 0);
for (std::vector<App::DocumentObject*>::const_iterator it = views.begin(); it != views.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawProjGroupItem::getClassTypeId())) {
oView = dynamic_cast<DrawProjGroupItem *>(*it);

for (auto it : Views.getValues()) {
auto oView( dynamic_cast<DrawProjGroupItem *>(it) );
if (oView) {
const char *viewTypeCStr = oView->Type.getValueAsString();
if (strcmp(viewTypeCStr, "Front") == 0) {
viewPtrs[thirdAngle ? 4 : 4] = oView;
@@ -425,7 +407,7 @@ void DrawProjGroup::arrangeViewPointers(DrawProjGroupItem *viewPtrs[10]) const
} else if (strcmp(viewTypeCStr, "Bottom") == 0) {
viewPtrs[thirdAngle ? 8 : 1] = oView;
} else if (strcmp(viewTypeCStr, "Rear") == 0) {
viewPtrs[thirdAngle ? 6 : 6] = oView;
viewPtrs[6] = oView;
} else if (strcmp(viewTypeCStr, "FrontTopLeft") == 0) {
viewPtrs[thirdAngle ? 0 : 9] = oView;
} else if (strcmp(viewTypeCStr, "FrontTopRight") == 0) {
@@ -535,10 +517,9 @@ bool DrawProjGroup::distributeProjections()
//!allow child DPGI's to be automatically positioned
void DrawProjGroup::resetPositions(void)
{
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
DrawView *view = dynamic_cast<DrawView *>(*it);
if(view->getTypeId() == DrawProjGroupItem::getClassTypeId()) {
for( auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if( view ) {
view->setAutoPos(true);
//X,Y == 0??
}
@@ -550,12 +531,11 @@ void DrawProjGroup::setFrontViewOrientation(const Base::Matrix4D &newMat)
{
viewOrientationMatrix.setValue(newMat);

DrawProjGroupItem *view;
std::vector<App::DocumentObject *> views = Views.getValues();
for (std::vector<App::DocumentObject*>::const_iterator it = views.begin(); it != views.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawProjGroupItem::getClassTypeId())) {
view = dynamic_cast<DrawProjGroupItem *>(*it);
for( auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if( view ) {
setViewOrientation(view, view->Type.getValueAsString());
// TODO: Seems we should ensure that modifying the view triggers this automatically? IR
view->touch();
}
}
@@ -573,11 +553,9 @@ App::DocumentObjectExecReturn *DrawProjGroup::execute(void)
Scale.setValue(autoScale);

//Rebuild the DPGI's
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
App::DocumentObject *docObj = *it;
if(docObj->getTypeId().isDerivedFrom(DrawProjGroupItem::getClassTypeId())) {
DrawProjGroupItem *view = dynamic_cast<DrawProjGroupItem *>(*it);
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if( view ) {
view->ScaleType.setValue("Custom");
view->Scale.setValue(autoScale);
view->Scale.setStatus(App::Property::ReadOnly,true);
1 change: 0 additions & 1 deletion src/Mod/TechDraw/App/DrawViewSection.cpp
Original file line number Diff line number Diff line change
@@ -320,7 +320,6 @@ TopoDS_Face DrawViewSection::projectFace(const TopoDS_Shape &face,
{
if(face.IsNull()) {
throw Base::Exception("DrawViewSection::projectFace - input Face is NULL");
return TopoDS_Face();
}

gp_Ax2 transform;
12 changes: 9 additions & 3 deletions src/Mod/TechDraw/Gui/CommandCreateDims.cpp
Original file line number Diff line number Diff line change
@@ -1012,10 +1012,16 @@ bool _isValidVertexes(Gui::Command* cmd) {
//! verify that the Selection contains valid geometries for an Edge to Edge Dimension
int _isValidEdgeToEdge(Gui::Command* cmd) {
//TODO: can the edges be in 2 different features??
int edgeType = isInvalid;
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
TechDraw::DrawViewPart* objFeat0 = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
//TechDraw::DrawViewPart* objFeat1 = dynamic_cast<TechDraw::DrawViewPart *>(selection[1].getObject());

auto objFeat0( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
// getObject() can return null pointer, or dynamic_cast can fail
if ( !objFeat0 ) {
Base::Console().Error("Logic error in _isValidEdgeToEdge()\n");
return isInvalid;
}

int edgeType = isInvalid;
const std::vector<std::string> SubNames = selection[0].getSubNames();
if(SubNames.size() == 2) { //there are 2
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && //they both start with "Edge"
26 changes: 12 additions & 14 deletions src/Mod/TechDraw/Gui/MDIViewPage.cpp
Original file line number Diff line number Diff line change
@@ -264,50 +264,48 @@ void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj)
}


int MDIViewPage::attachView(App::DocumentObject *obj)
bool MDIViewPage::attachView(App::DocumentObject *obj)
{
auto typeId(obj->getTypeId());

QGIView *qview(nullptr);

if (typeId.isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId()) ) {
qview = m_view->addViewSection( dynamic_cast<TechDraw::DrawViewSection *>(obj) );
qview = m_view->addViewSection( static_cast<TechDraw::DrawViewSection *>(obj) );

} else if (typeId.isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()) ) {
qview = m_view->addViewPart( dynamic_cast<TechDraw::DrawViewPart *>(obj) );
qview = m_view->addViewPart( static_cast<TechDraw::DrawViewPart *>(obj) );

} else if (typeId.isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId()) ) {
qview = m_view->addProjectionGroup( dynamic_cast<TechDraw::DrawProjGroup *>(obj) );
qview = m_view->addProjectionGroup( static_cast<TechDraw::DrawProjGroup *>(obj) );

} else if (typeId.isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId()) ) {
qview = m_view->addDrawView( dynamic_cast<TechDraw::DrawViewCollection *>(obj) );
qview = m_view->addDrawView( static_cast<TechDraw::DrawViewCollection *>(obj) );

} else if (typeId.isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) ) {
qview = m_view->addViewDimension( dynamic_cast<TechDraw::DrawViewDimension *>(obj) );
qview = m_view->addViewDimension( static_cast<TechDraw::DrawViewDimension *>(obj) );

} else if (typeId.isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId()) ) {
qview = m_view->addDrawViewAnnotation( dynamic_cast<TechDraw::DrawViewAnnotation *>(obj) );
qview = m_view->addDrawViewAnnotation( static_cast<TechDraw::DrawViewAnnotation *>(obj) );

} else if (typeId.isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId()) ) {
qview = m_view->addDrawViewSymbol( dynamic_cast<TechDraw::DrawViewSymbol *>(obj) );
qview = m_view->addDrawViewSymbol( static_cast<TechDraw::DrawViewSymbol *>(obj) );

} else if (typeId.isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId()) ) {
qview = m_view->addDrawViewClip( dynamic_cast<TechDraw::DrawViewClip *>(obj) );
qview = m_view->addDrawViewClip( static_cast<TechDraw::DrawViewClip *>(obj) );

} else if (typeId.isDerivedFrom(TechDraw::DrawViewSpreadsheet::getClassTypeId()) ) {
qview = m_view->addDrawViewSpreadsheet( dynamic_cast<TechDraw::DrawViewSpreadsheet *>(obj) );
qview = m_view->addDrawViewSpreadsheet( static_cast<TechDraw::DrawViewSpreadsheet *>(obj) );

} else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) ) {
//Hatch is not attached like other Views (since it isn't really a View)
return true;

} else {
Base::Console().Log("Logic Error - Unknown view type in MDIViewPage::attachView\n");
}

if(!qview)
return -1;
else
return m_view->getViews().size();
return (qview != nullptr);
}


5 changes: 4 additions & 1 deletion src/Mod/TechDraw/Gui/MDIViewPage.h
Original file line number Diff line number Diff line change
@@ -92,7 +92,10 @@ public Q_SLOTS:
void findMissingViews( const std::vector<App::DocumentObject*> &list, std::vector<App::DocumentObject*> &missing);
bool hasQView(App::DocumentObject *obj);
bool orphanExists(const char *viewName, const std::vector<App::DocumentObject*> &list);
int attachView(App::DocumentObject *obj);

/// Attaches view of obj to m_view. Returns true on success, false otherwise
bool attachView(App::DocumentObject *obj);

void contextMenuEvent(QContextMenuEvent *event);
void closeEvent(QCloseEvent*);
QPrinter::PaperSize getPaperSize(int w, int h) const;
11 changes: 5 additions & 6 deletions src/Mod/TechDraw/Gui/QGCustomSvg.h
Original file line number Diff line number Diff line change
@@ -44,21 +44,20 @@ class TechDrawGuiExport QGCustomSvg : public QGraphicsSvgItem
~QGCustomSvg();

enum {Type = QGraphicsItem::UserType + 131};
int type() const { return Type;}
int type() const override { return Type;}

virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
virtual void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget = nullptr ) override;
virtual void centerAt(QPointF centerPos);
virtual void centerAt(double cX, double cY);
virtual bool load(QByteArray *svgString);
virtual QRectF boundingRect(void) const override;

protected:
QSvgRenderer *m_svgRender;

private:

};

} // namespace MDIViewPageGui
} // namespace TechDrawGui

#endif // DRAWINGGUI_QGCUSTOMSVG_H
18 changes: 11 additions & 7 deletions src/Mod/TechDraw/Gui/QGIView.cpp
Original file line number Diff line number Diff line change
@@ -213,15 +213,19 @@ void QGIView::setPosition(qreal x, qreal y)

double QGIView::getYInClip(double y)
{
QGCustomClip* parentClip = dynamic_cast<QGCustomClip*>(parentItem());
auto parentClip( dynamic_cast<QGCustomClip*>( parentItem() ) );
if (parentClip) {
QGIViewClip* parentView = dynamic_cast<QGIViewClip*>(parentClip->parentItem());
TechDraw::DrawViewClip* parentFeat = dynamic_cast<TechDraw::DrawViewClip*>(parentView->getViewObject());
double newY = parentFeat->Height.getValue() - y;
return newY;
} else {
Base::Console().Log("Logic Error - getYInClip called for child (%s) not in Clip\n",getViewName());
auto parentView( dynamic_cast<QGIViewClip*>( parentClip->parentItem() ) );
if (parentView) {
auto parentFeat( dynamic_cast<TechDraw::DrawViewClip*>(parentView->getViewObject()) );
if (parentFeat) {
return parentFeat->Height.getValue() - y;
}
}
}

Base::Console().Log( "Logic Error - getYInClip called for child "
"(%s) not in Clip\n", getViewName() );
return 0;
}

22 changes: 13 additions & 9 deletions src/Mod/TechDraw/Gui/QGIView.h
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ class TechDrawGuiExport QGIView : public QGraphicsItemGroup
virtual ~QGIView() = default;

enum {Type = QGraphicsItem::UserType + 101};
int type() const { return Type;}
int type() const override { return Type;}

const char * getViewName() const;
void setViewFeature(TechDraw::DrawView *obj);
@@ -62,33 +62,37 @@ class TechDrawGuiExport QGIView : public QGraphicsItemGroup
virtual bool isVisible(void) {return m_visibility;};
virtual void draw(void);

/// Methods to ensure that Y-Coordinates are orientated correctly.
/** Methods to ensure that Y-Coordinates are orientated correctly.
* @{ */
void setPosition(qreal x, qreal y);
inline qreal getY() { return y() * -1; }
bool isInnerView() { return m_innerView; }
void isInnerView(bool state) { m_innerView = state; }
double getYInClip(double y);
/** @} */

void alignTo(QGraphicsItem*, const QString &alignment);
void setLocked(bool state = true) { locked = true; }

virtual void toggleCache(bool state);
virtual void updateView(bool update = false);
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
virtual void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget = nullptr ) override;
virtual QRectF boundingRect() const override;

virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;

protected:
QGIView* getQGIVByName(std::string name);

virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
// Mouse handling
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event );
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
// Preselection events:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
virtual QRectF customChildrenBoundingRect(void);
void dumpRect(char* text, QRectF r);

4 changes: 2 additions & 2 deletions src/Mod/TechDraw/Gui/QGIViewDimension.cpp
Original file line number Diff line number Diff line change
@@ -209,9 +209,9 @@ void QGIViewDimension::hover(bool state)

void QGIViewDimension::updateView(bool update)
{
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()))
auto dim( dynamic_cast<TechDraw::DrawViewDimension*>(getViewObject()) );
if( dim == nullptr )
return;
TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension*>(getViewObject());

// Identify what changed to prevent complete redraw
if(dim->Fontsize.isTouched() ||
3 changes: 1 addition & 2 deletions src/Mod/TechDraw/Gui/QGVPage.cpp
Original file line number Diff line number Diff line change
@@ -464,8 +464,7 @@ void QGVPage::toggleHatch(bool enable)
int faceItemType = QGraphicsItem::UserType + 104;
for (auto& c:partChildren) {
if (c->type() == faceItemType) {
QGIFace* f = dynamic_cast<QGIFace*>(c);
f->toggleSvg(enable);
static_cast<QGIFace*>(c)->toggleSvg(enable);
}
}
}