diff --git a/src/actors/draw/drawmodule.cpp b/src/actors/draw/drawmodule.cpp index 5dcb400f11b16b34f347783e285540a63940e7a0..00d180c63c4a98e25751d88d3c1044aac0a52331 100644 --- a/src/actors/draw/drawmodule.cpp +++ b/src/actors/draw/drawmodule.cpp @@ -21,6 +21,7 @@ You should change it corresponding to functionality. namespace ActorDraw { + const int maxBuff=1500; #define NET_RESERVE 15 #define KUM_MULTI 50 @@ -178,14 +179,14 @@ namespace ActorDraw { void DrawScene::addDrawLine(QLineF lineF,QColor color,qreal width) { if(lineF.length()==0)return; - QGraphicsLineItem* line=addLine(lineF); + QGraphicsLineItem* line=new QGraphicsLineItem(lineF); QPen mp=QPen(QColor(color)); mp.setWidthF(width); mp.setCosmetic(true); line->setPen(mp); line->setZValue(90); lines.append(line); - + itemsBuffer.append(line); } @@ -820,6 +821,7 @@ DrawModule::DrawModule(ExtensionSystem::KPlugin * parent) { CurView = 0; firstShow=true; + curPos=QPointF(0,0); } void DrawModule::handleGuiReady() { @@ -898,7 +900,7 @@ QString DrawModule::initialize(const QStringList &configurationParameters, const animate=false; redrawTimer = new QTimer(this); connect(redrawTimer,SIGNAL(timeout()), this, SLOT(redraw())); - redrawTimer->start(500); + redrawTimer->start(250); } return ""; } @@ -979,9 +981,10 @@ void DrawModule::showNavigator(bool state) using namespace ExtensionSystem; // not to write "ExtensionSystem::" each time in this method scope Q_UNUSED(old); // Remove this line on implementation Q_UNUSED(current); // Remove this line on implementation - + updateDraw(); redraw(); - + currentState=current; + CurView->setViewportUpdateMode (QGraphicsView::SmartViewportUpdate); // if(current==GlobalState::GS_Running) // { // redrawTimer->start(500); @@ -1042,6 +1045,8 @@ void DrawModule::showNavigator(bool state) CurView->forceRedraw(); CurView->setZoom(CurView->zoom()*2); CurView->setZoom(CurView->zoom()*0.5); + curPos=QPointF(0,0); + } /* public slot */ void DrawModule::setAnimationEnabled(bool enabled) @@ -1093,6 +1098,7 @@ void DrawModule::showNavigator(bool state) /* public slot */ void DrawModule::runMoveTo(const qreal x, const qreal y) { + int curBuffSize=0; mutex.lock(); QPointF start=mPen->pos(); mPen->setPos(x, -y); @@ -1103,8 +1109,16 @@ void DrawModule::showNavigator(bool state) //CurView->resetCachedContent(); //CurView->update(); // if(animate)redrawPicture(); - - mutex.unlock(); + curBuffSize=CurScene->buffSize(); + mutex.unlock(); + if(curBuffSize>maxBuff-1) + { + msleep(3); + mutex.lock(); + curBuffSize=CurScene->buffSize(); + mutex.unlock(); + + } // msleep(10); } @@ -1112,6 +1126,7 @@ void DrawModule::showNavigator(bool state) { /* алг сместиться на вектор(вещ dX, вещ dY) */ // TODO implement me + int curBuffSize=0; mutex.lock(); QPointF start=mPen->pos(); mPen->moveBy(dX, -dY); @@ -1121,9 +1136,16 @@ void DrawModule::showNavigator(bool state) } //CurView->update(); //if(animate)redrawPicture(); - + curBuffSize=CurScene->buffSize(); mutex.unlock(); - msleep(1); + if(curBuffSize>maxBuff-1) + { + msleep(3); + mutex.lock(); + curBuffSize=CurScene->buffSize(); + mutex.unlock(); + + } } @@ -1319,16 +1341,27 @@ void DrawModule::drawNet() drawNet(); } } -void DrawModule::redraw() +void DrawModule::updateDraw() { - if(currentState!=ExtensionSystem::GlobalState::GS_Running)return; - mutex.lock(); + CurView->setViewportUpdateMode (QGraphicsView::SmartViewportUpdate); + mutex.lock(); + + CurScene->fromBufferToScene(); + redrawPicture(); + + mutex.unlock(); - msleep(5); - // qApp->processEvents(); - mutex.unlock(); drawNet(); + CurView->setViewportUpdateMode (QGraphicsView::NoViewportUpdate); + } +void DrawModule::redraw() + { + if(currentState!=ExtensionSystem::GlobalState::GS_Running)return; + updateDraw(); + + + //qApp->processEvents(); } diff --git a/src/actors/draw/drawmodule.h b/src/actors/draw/drawmodule.h index c60e932d495981542936f0b7ed276da968f66087..0d12f8d0e8b456fb95b11d811d48ac27acd5bbe5 100644 --- a/src/actors/draw/drawmodule.h +++ b/src/actors/draw/drawmodule.h @@ -105,7 +105,7 @@ namespace ActorDraw { for(int i=0;isetZValue(90); + addItem(buff); + clearBuffer(); + } + void clearBuffer() + { + itemsBuffer.clear(); + } + int buffSize() + { + return itemsBuffer.count(); + } protected: // void resizeEvent ( QResizeEvent * event ); // bool eventFilter(QObject *object, QEvent *event); @@ -129,7 +143,8 @@ namespace ActorDraw { QList linesDubl;//Базовый чертеж QList texts; DrawModule* DRAW; - QMutex* dr_mutex; + QList itemsBuffer; + QMutex* dr_mutex; @@ -241,7 +256,7 @@ public slots: void openFile(); void saveFile(); void redraw(); - + void updateDraw(); /* ========= CLASS PRIVATE ========= */ private: @@ -265,6 +280,8 @@ private: QTimer *redrawTimer; qreal curAngle; qreal AncX,AncY; + QPointF curPos; + };