Eliminate some redundant executes

- excessive calls to DrawView::execute were
  slowing data entry in PropertyEditor.
This commit is contained in:
wandererfan
2018-05-04 10:28:03 -04:00
committed by Yorik van Havre
parent 6b91a3ec32
commit 8a183a0ba0
12 changed files with 58 additions and 86 deletions

View File

@@ -137,17 +137,21 @@ void DrawPage::onChanged(const App::Property* prop)
}
} else if(prop == &Scale) {
// touch all views in the Page as they may be dependent on this scale
const std::vector<App::DocumentObject*> &vals = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = vals.begin(); it < vals.end(); ++it) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
if (view != NULL && view->ScaleType.isValue("Page")) {
if(std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) {
view->Scale.setValue(Scale.getValue());
// WF: not sure this loop is required. Views figure out their scale as required. but maybe
// this is needed just to mark the Views to recompute??
if (!isRestoring()) {
const std::vector<App::DocumentObject*> &vals = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = vals.begin(); it < vals.end(); ++it) {
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
if (view != NULL && view->ScaleType.isValue("Page")) {
if(std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) {
view->Scale.setValue(Scale.getValue());
}
}
}
}
} else if (prop == &ProjectionType) {
// touch all ortho views in the Page as they may be dependent on Projection Type
// touch all ortho views in the Page as they may be dependent on Projection Type //(is this true?)
const std::vector<App::DocumentObject*> &vals = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = vals.begin(); it < vals.end(); ++it) {
TechDraw::DrawProjGroup *view = dynamic_cast<TechDraw::DrawProjGroup *>(*it);

View File

@@ -103,6 +103,7 @@ void DrawView::checkScale(void)
if (ScaleType.isValue("Page")) {
if(std::abs(page->Scale.getValue() - getScale()) > FLT_EPSILON) {
Scale.setValue(page->Scale.getValue());
Scale.purgeTouched();
}
}
}
@@ -121,6 +122,7 @@ void DrawView::onChanged(const App::Property* prop)
if (page != nullptr) {
if(std::abs(page->Scale.getValue() - getScale()) > FLT_EPSILON) {
Scale.setValue(page->Scale.getValue());
Scale.purgeTouched();
}
}
} else if ( ScaleType.isValue("Custom") ) {
@@ -137,6 +139,7 @@ void DrawView::onChanged(const App::Property* prop)
double newScale = autoScale(page->getPageWidth(),page->getPageHeight());
if(std::abs(newScale - getScale()) > FLT_EPSILON) { //stops onChanged/execute loop
Scale.setValue(newScale);
Scale.purgeTouched();
}
}
}
@@ -354,6 +357,7 @@ bool DrawView::keepUpdated(void)
void DrawView::requestPaint(void)
{
Base::Console().Message("TRACE - DV::requestPaint()\n");
signalGuiPaint(this);
}

View File

@@ -164,6 +164,9 @@ bool DrawViewSymbol::checkFit(TechDraw::DrawPage* p) const
short DrawViewSymbol::mustExecute() const
{
if (Scale.isTouched()) {
Base::Console().Message("TRACE - DVS::mustExecute - Scale is touched\n");
}
short result = 0;
if (!isRestoring()) {
result = (Scale.isTouched() ||

View File

@@ -370,7 +370,10 @@ void MDIViewPage::updateTemplate(bool forceUpdate)
}
}
void MDIViewPage::updateDrawing(bool forceUpdate)
//this is time consuming. should only be used when there is a problem.
//should have been called MDIViewPage::fixWidowAndOrphans()
//void MDIViewPage::updateDrawing(bool forceUpdate)
void MDIViewPage::updateDrawing(void)
{
// get all the DrawViews for this page, including the second level ones
// if we ever have collections of collections, we'll need to revisit this
@@ -384,10 +387,11 @@ void MDIViewPage::updateDrawing(bool forceUpdate)
}
QGIView* qv = m_view->findQViewForDocObj(dv);
if (qv == nullptr) {
Base::Console().Message("TRACE - MDIVP::updateDrawing - making a missing graphic\n");
attachView(dv);
}
}
// if qView doesn't have a Feature on this Page, delete it
std::vector<QGIView*> qvs = m_view->getViews();
App::Document* doc = getAppDocument();
@@ -404,13 +408,15 @@ void MDIViewPage::updateDrawing(bool forceUpdate)
}
// Update all the QGIVxxxx
const std::vector<QGIView *> &upviews = m_view->getViews();
for(std::vector<QGIView *>::const_iterator it = upviews.begin(); it != upviews.end(); ++it) {
if((*it)->getViewObject()->isTouched() ||
forceUpdate) {
(*it)->updateView(forceUpdate);
}
}
// WF: why do we do this? views should be keeping themselves up to date.
// const std::vector<QGIView *> &upviews = m_view->getViews();
// for(std::vector<QGIView *>::const_iterator it = upviews.begin(); it != upviews.end(); ++it) {
// Base::Console().Message("TRACE - MDIVP::updateDrawing - updating a QGIVxxxx\n");
// if((*it)->getViewObject()->isTouched() ||
// forceUpdate) {
// (*it)->updateView(forceUpdate);
// }
// }
}
//NOTE: this doesn't add missing views. see updateDrawing()

View File

@@ -66,7 +66,8 @@ public:
void attachTemplate(TechDraw::DrawTemplate *obj);
void updateTemplate(bool force = false);
void updateDrawing(bool force = false);
// void updateDrawing(bool force = false);
void updateDrawing(void);
void matchSceneRectToTemplate(void);
bool onMsg(const char* pMsg,const char** ppReturn);

View File

@@ -50,21 +50,6 @@ QGIEdge::QGIEdge(int index) :
setCosmetic(isCosmetic);
}
QRectF QGIEdge::boundingRect() const
{
return shape().controlPointRect();
}
QPainterPath QGIEdge::shape() const
{
QPainterPath outline;
QPainterPathStroker stroker;
stroker.setWidth(2.0);
outline = stroker.createStroke(path());
return outline;
}
void QGIEdge::setCosmetic(bool state)
{
isCosmetic = state;
@@ -73,7 +58,6 @@ void QGIEdge::setCosmetic(bool state)
}
}
void QGIEdge::setHiddenEdge(bool b) {
isHiddenEdge = b;
if (b) {

View File

@@ -37,8 +37,6 @@ public:
enum {Type = QGraphicsItem::UserType + 103};
int type() const { return Type;}
QRectF boundingRect() const;
QPainterPath shape() const;
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
int getProjIndex() const { return projIndex; }

View File

@@ -266,19 +266,20 @@ void QGIView::updateView(bool update)
} else {
setFlag(QGraphicsItem::ItemIsMovable, true);
}
if (update ||
getViewObject()->X.isTouched() ||
if (getViewObject()->X.isTouched() ||
getViewObject()->Y.isTouched()) {
double featX = Rez::guiX(getViewObject()->X.getValue());
double featY = Rez::guiX(getViewObject()->Y.getValue());
setPosition(featX,featY);
}
if (update ||
getViewObject()->Rotation.isTouched() ) {
if (getViewObject()->Rotation.isTouched() ) {
rotateView();
}
draw();
if (update)
QGraphicsItem::update();
}
@@ -484,8 +485,11 @@ QGIView* QGIView::getQGIVByName(std::string name)
/* static */
Gui::ViewProvider* QGIView::getViewProvider(App::DocumentObject* obj)
{
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(obj->getDocument());
Gui::ViewProvider* result = guiDoc->getViewProvider(obj);
Gui::ViewProvider* result = nullptr;
if (obj != nullptr) {
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(obj->getDocument());
result = guiDoc->getViewProvider(obj);
}
return result;
}

View File

@@ -40,6 +40,7 @@
#include <QSvgRenderer>
#endif // #ifndef _PreComp_
#include <chrono>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
@@ -293,6 +294,7 @@ QPainterPath QGIViewPart::geomToPainterPath(TechDrawGeometry::BaseGeom *baseGeom
void QGIViewPart::updateView(bool update)
{
auto start = std::chrono::high_resolution_clock::now();
auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) );
if( viewPart == nullptr ) {
return;
@@ -304,28 +306,14 @@ void QGIViewPart::updateView(bool update)
QGIView::updateView(update);
if (update ||
viewPart->isTouched() ||
viewPart->Source.isTouched() ||
viewPart->Direction.isTouched() ||
viewPart->Rotation.isTouched() ||
viewPart->Scale.isTouched() ||
viewPart->HardHidden.isTouched() ||
viewPart->SmoothVisible.isTouched() ||
viewPart->SeamVisible.isTouched() ||
viewPart->IsoVisible.isTouched() ||
viewPart->SmoothHidden.isTouched() ||
viewPart->SeamHidden.isTouched() ||
viewPart->IsoHidden.isTouched() ||
viewPart->IsoCount.isTouched() ) {
if (update ) {
draw();
} else if (update ||
vp->LineWidth.isTouched() ||
vp->HiddenWidth.isTouched()) {
draw();
} else {
QGIView::draw();
}
auto end = std::chrono::high_resolution_clock::now();
auto diff = end - start;
double diffOut = std::chrono::duration <double, std::milli> (diff).count();
Base::Console().Log("TIMING - QGIVP::updateView - total %.3f millisecs\n",diffOut);
}
void QGIViewPart::draw() {

View File

@@ -99,9 +99,7 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent)
setScene(s);
setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
//setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
//setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
setCacheMode(QGraphicsView::CacheBackground);
//setTransformationAnchor(AnchorUnderMouse);
//setTransformationAnchor(NoAnchor);

View File

@@ -131,21 +131,9 @@ void ViewProviderPage::updateData(const App::Property* prop)
if (prop == &(getDrawPage()->KeepUpdated)) {
if (getDrawPage()->KeepUpdated.getValue()) {
sPixmap = "TechDraw_Tree_Page";
if (!m_mdiView.isNull() &&
!getDrawPage()->isUnsetting()) {
m_mdiView->updateDrawing();
}
} else {
sPixmap = "TechDraw_Tree_Page_Unsync";
}
}
//if a view is added/deleted, rebuild the visual
if (prop == &(getDrawPage()->Views)) {
if(!m_mdiView.isNull() &&
!getDrawPage()->isUnsetting()) {
m_mdiView->updateDrawing();
}
//if the template is changed, rebuild the visual
} else if (prop == &(getDrawPage()->Template)) {
if(m_mdiView &&
@@ -205,7 +193,7 @@ bool ViewProviderPage::doubleClicked(void)
bool ViewProviderPage::showMDIViewPage()
{
if (isRestoring()) {
if (isRestoring()) {
return true;
}
@@ -216,11 +204,12 @@ bool ViewProviderPage::showMDIViewPage()
QString tabTitle = QString::fromUtf8(getDrawPage()->getNameInDocument());
m_mdiView->setWindowTitle(tabTitle + QString::fromLatin1("[*]"));
m_mdiView->setWindowIcon(Gui::BitmapFactory().pixmap("TechDraw_Tree_Page"));
m_mdiView->updateDrawing(true);
m_mdiView->updateDrawing();
Gui::getMainWindow()->addWindow(m_mdiView);
m_mdiView->viewAll();
} else {
m_mdiView->updateDrawing(true);
m_mdiView->updateDrawing();
m_mdiView->redrawAllViews();
m_mdiView->updateTemplate(true);
}
return true;

View File

@@ -95,13 +95,6 @@ ViewProviderViewPart::~ViewProviderViewPart()
void ViewProviderViewPart::updateData(const App::Property* prop)
{
if (prop == &(getViewObject()->Scale) ) { //shouldn't Scale cause DVP::execute & request paint??
QGIView* qgiv = getQView();
if (qgiv) {
qgiv->updateView(true);
}
}
ViewProviderDrawingView::updateData(prop);
}