From 2ee84c5948ede7fc2f7b4435c5edef42a030ac05 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Mon, 13 Sep 2010 21:40:56 +0000 Subject: [PATCH] Fixed hatch dialog, added snap/preview to circle tools. --- src/actions/actiondimleader.cpp | 46 +++++++++-------- src/actions/actiondrawcircle.cpp | 34 ++++++------ src/actions/actiondrawcircle2p.cpp | 39 ++++++++------ src/actions/actiondrawcircle3p.cpp | 31 ++++++----- src/actions/actiondrawcirclecr.cpp | 36 ++++++++----- src/actions/actiondrawhatch.cpp | 24 ++------- src/base/entity.cpp | 6 +-- src/base/entitycontainer.cpp | 10 ++-- src/base/pattern.cpp | 56 +++++++------------- src/base/pattern.h | 4 +- src/base/patternlist.cpp | 83 +++++++++++++----------------- src/forms/dlghatch.cpp | 2 +- src/forms/dlghatch.ui | 4 +- src/widgets/patternbox.cpp | 18 ++++--- 14 files changed, 190 insertions(+), 203 deletions(-) diff --git a/src/actions/actiondimleader.cpp b/src/actions/actiondimleader.cpp index f65ff31..5216506 100644 --- a/src/actions/actiondimleader.cpp +++ b/src/actions/actiondimleader.cpp @@ -12,6 +12,7 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 06/03/2010 Added this text. :-) +// JLH 09/11/2010 Fixed preview/snapper rendering. // #include "actiondimleader.h" @@ -39,9 +40,6 @@ ActionDimLeader::~ActionDimLeader() void ActionDimLeader::reset() { - //data = LineData(Vector(false), Vector(false)); - //start = Vector(false); - //history.clear(); points.clear(); } @@ -62,29 +60,28 @@ void ActionDimLeader::trigger() leader->setLayerToActive(); leader->setPenToActive(); -// for(Vector * v=points.first(); v!=NULL; v=points.next()) -// leader->addVertex(*v); - for (int i = 0; i < points.size(); i++) + for(int i=0; iaddVertex(*(points[i])); container->addEntity(leader); // upd. undo list: - if (document != NULL) + if (document) { document->startUndoCycle(); document->addUndoable(leader); document->endUndoCycle(); } - deletePreview(); - clearPreview(); - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0, 0.0)); - graphicView->drawEntity(leader); - graphicView->moveRelativeZero(rz); - //drawSnapper(); +// deletePreview(); +// clearPreview(); +// deleteSnapper(); +// Vector rz = graphicView->getRelativeZero(); +// graphicView->moveRelativeZero(Vector(0.0, 0.0)); +// graphicView->drawEntity(leader); +// graphicView->moveRelativeZero(rz); + graphicView->preview.clear(); //hm. + graphicView->redraw(); DEBUG->print("ActionDimLeader::trigger(): leader added: %d", leader->getId()); } @@ -98,8 +95,9 @@ void ActionDimLeader::mouseMoveEvent(QMouseEvent * e) if (getStatus() == SetEndpoint && points.last() != NULL) { - deletePreview(); - clearPreview(); +// deletePreview(); +// clearPreview(); + graphicView->preview.clear(); // fill in lines that were already set: Vector last(false); @@ -110,15 +108,20 @@ void ActionDimLeader::mouseMoveEvent(QMouseEvent * e) // if (last.valid) // preview->addEntity(new Line(preview, LineData(last, *v))); + if (last.valid) + graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(last, *v))); last = *v; } Vector p = *points.last(); // preview->addEntity(new Line(preview, LineData(p, mouse))); - drawPreview(); +// drawPreview(); + graphicView->preview.addEntity(new Line(&(graphicView->preview), LineData(p, mouse))); } + graphicView->redraw(); + DEBUG->print("ActionDimLeader::mouseMoveEvent end"); } @@ -139,9 +142,10 @@ void ActionDimLeader::mouseReleaseEvent(QMouseEvent * e) } else { - deletePreview(); - deleteSnapper(); +// deletePreview(); +// deleteSnapper(); init(getStatus() - 1); + graphicView->redraw(); //hm. } } } @@ -193,7 +197,7 @@ void ActionDimLeader::commandEvent(CommandEvent * e) if (checkCommand("help", c)) { - if (DIALOGFACTORY != NULL) + if (DIALOGFACTORY) DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", ")); diff --git a/src/actions/actiondrawcircle.cpp b/src/actions/actiondrawcircle.cpp index 7c19be0..9f64a0e 100644 --- a/src/actions/actiondrawcircle.cpp +++ b/src/actions/actiondrawcircle.cpp @@ -12,6 +12,7 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 06/03/2010 Added this text. :-) +// JLH 09/11/2010 Fixed preview/snapper rendering. // #include "actiondrawcircle.h" @@ -59,19 +60,21 @@ void ActionDrawCircle::trigger() container->addEntity(circle); // upd. undo list: - if (document != NULL) + if (document) { document->startUndoCycle(); document->addUndoable(circle); document->endUndoCycle(); } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0, 0.0)); - graphicView->drawEntity(circle); + graphicView->preview.clear(); // hm. +// deleteSnapper(); +// Vector rz = graphicView->getRelativeZero(); +// graphicView->moveRelativeZero(Vector(0.0, 0.0)); +// graphicView->drawEntity(circle); graphicView->moveRelativeZero(circle->getCenter()); - drawSnapper(); +// drawSnapper(); + graphicView->redraw(); setStatus(SetCenter); reset(); @@ -92,18 +95,16 @@ void ActionDrawCircle::mouseMoveEvent(QMouseEvent * e) break; case SetRadius: - if (data.center.valid) { data.radius = data.center.distanceTo(mouse); - deletePreview(); - clearPreview(); -// preview->addEntity(new Circle(preview, data)); - drawPreview(); + graphicView->preview.clear(); + graphicView->preview.addEntity(new Circle(&(graphicView->preview), data)); } break; } + graphicView->redraw(); DEBUG->print("ActionDrawCircle::mouseMoveEvent end"); } @@ -116,9 +117,13 @@ void ActionDrawCircle::mouseReleaseEvent(QMouseEvent * e) } else if (e->button() == Qt::RightButton) { - deletePreview(); - deleteSnapper(); +// deletePreview(); +// deleteSnapper(); +// //Is this necessary? Or should the base class take care of this kind of crap? +// graphicView->preview.clear(); init(getStatus() - 1); + // Looks like we need at least to redraw... Though shouldn't base class do it??? + graphicView->redraw(); } } @@ -138,14 +143,13 @@ void ActionDrawCircle::coordinateEvent(Vector * e) break; case SetRadius: - if (data.center.valid) { graphicView->moveRelativeZero(mouse); data.radius = data.center.distanceTo(mouse); trigger(); } - //setStatus(SetCenter); + break; default: diff --git a/src/actions/actiondrawcircle2p.cpp b/src/actions/actiondrawcircle2p.cpp index d580bb3..676db76 100644 --- a/src/actions/actiondrawcircle2p.cpp +++ b/src/actions/actiondrawcircle2p.cpp @@ -12,6 +12,7 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 06/03/2010 Added this text. :-) +// JLH 09/11/2010 Fixed preview/snapper rendering. // #include "actiondrawcircle2p.h" @@ -21,8 +22,9 @@ #include "graphicview.h" #include "preview.h" -ActionDrawCircle2P::ActionDrawCircle2P(EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw circles", - container, graphicView) +ActionDrawCircle2P::ActionDrawCircle2P(EntityContainer & container, + GraphicView & graphicView): + ActionInterface("Draw circles", container, graphicView) { reset(); } @@ -41,14 +43,12 @@ void ActionDrawCircle2P::reset() void ActionDrawCircle2P::init(int status) { ActionInterface::init(status); - reset(); } void ActionDrawCircle2P::trigger() { ActionInterface::trigger(); - preparePreview(); if (data.isValid()) @@ -59,24 +59,26 @@ void ActionDrawCircle2P::trigger() container->addEntity(circle); // upd. undo list: - if (document != NULL) + if (document) { document->startUndoCycle(); document->addUndoable(circle); document->endUndoCycle(); } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0, 0.0)); - graphicView->drawEntity(circle); - graphicView->moveRelativeZero(rz); - drawSnapper(); +// deleteSnapper(); +// Vector rz = graphicView->getRelativeZero(); +// graphicView->moveRelativeZero(Vector(0.0, 0.0)); +// graphicView->drawEntity(circle); +// graphicView->moveRelativeZero(rz); +// drawSnapper(); + graphicView->preview.clear(); // hm. + graphicView->redraw(); setStatus(SetPoint1); reset(); } - else if (DIALOGFACTORY != NULL) + else if (DIALOGFACTORY) DIALOGFACTORY->requestWarningDialog(tr("Invalid Circle data.")); } @@ -87,9 +89,9 @@ void ActionDrawCircle2P::preparePreview() if (point1.valid && point2.valid) { Circle circle(NULL, data); - bool suc = circle.createFrom2P(point1, point2); + bool success = circle.createFrom2P(point1, point2); - if (suc) + if (success) data = circle.getData(); } } @@ -115,12 +117,16 @@ void ActionDrawCircle2P::mouseMoveEvent(QMouseEvent * e) // clearPreview(); // preview->addEntity(circle); // drawPreview(); + graphicView->preview.clear(); + graphicView->preview.addEntity(new Circle(&(graphicView->preview), data)); } break; default: break; } + + graphicView->redraw(); } void ActionDrawCircle2P::mouseReleaseEvent(QMouseEvent * e) @@ -132,9 +138,10 @@ void ActionDrawCircle2P::mouseReleaseEvent(QMouseEvent * e) } else if (e->button() == Qt::RightButton) { - deletePreview(); - deleteSnapper(); +// deletePreview(); +// deleteSnapper(); init(getStatus() - 1); + graphicView->redraw(); } } diff --git a/src/actions/actiondrawcircle3p.cpp b/src/actions/actiondrawcircle3p.cpp index eacd6d8..a20d8f4 100644 --- a/src/actions/actiondrawcircle3p.cpp +++ b/src/actions/actiondrawcircle3p.cpp @@ -12,6 +12,7 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 06/03/2010 Added this text. :-) +// JLH 09/11/2010 Fixed preview/snapper rendering. // #include "actiondrawcircle3p.h" @@ -22,8 +23,8 @@ #include "preview.h" ActionDrawCircle3P::ActionDrawCircle3P(EntityContainer & container, - GraphicView & graphicView): ActionInterface("Draw circles", - container, graphicView) + GraphicView & graphicView): + ActionInterface("Draw circles", container, graphicView) { reset(); } @@ -50,7 +51,6 @@ void ActionDrawCircle3P::init(int status) void ActionDrawCircle3P::trigger() { ActionInterface::trigger(); - preparePreview(); if (data.isValid()) @@ -68,12 +68,14 @@ void ActionDrawCircle3P::trigger() document->endUndoCycle(); } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0, 0.0)); - graphicView->drawEntity(circle); - graphicView->moveRelativeZero(rz); - drawSnapper(); +// deleteSnapper(); +// Vector rz = graphicView->getRelativeZero(); +// graphicView->moveRelativeZero(Vector(0.0, 0.0)); +// graphicView->drawEntity(circle); +// graphicView->moveRelativeZero(rz); +// drawSnapper(); + graphicView->preview.clear(); // hm. + graphicView->redraw(); setStatus(SetPoint1); reset(); @@ -117,14 +119,18 @@ void ActionDrawCircle3P::mouseMoveEvent(QMouseEvent * e) if (data.isValid()) { // Circle * circle = new Circle(preview, data); -// // deletePreview(); // clearPreview(); // preview->addEntity(circle); // drawPreview(); + graphicView->preview.clear(); + graphicView->preview.addEntity(new Circle(&(graphicView->preview), data)); } + break; } + + graphicView->redraw(); } void ActionDrawCircle3P::mouseReleaseEvent(QMouseEvent * e) @@ -136,9 +142,10 @@ void ActionDrawCircle3P::mouseReleaseEvent(QMouseEvent * e) } else if (e->button() == Qt::RightButton) { - deletePreview(); - deleteSnapper(); +// deletePreview(); +// deleteSnapper(); init(getStatus() - 1); + graphicView->redraw(); // hm. } } diff --git a/src/actions/actiondrawcirclecr.cpp b/src/actions/actiondrawcirclecr.cpp index dfd1150..daebf4c 100644 --- a/src/actions/actiondrawcirclecr.cpp +++ b/src/actions/actiondrawcirclecr.cpp @@ -12,6 +12,7 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 06/03/2010 Added this text. :-) +// JLH 09/11/2010 Fixed preview/snapper rendering. // #include "actiondrawcirclecr.h" @@ -25,8 +26,9 @@ /** * Constructor. */ -ActionDrawCircleCR::ActionDrawCircleCR(EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw circles CR", - container, graphicView) +ActionDrawCircleCR::ActionDrawCircleCR(EntityContainer & container, + GraphicView & graphicView): + ActionInterface("Draw circles CR", container, graphicView) { reset(); } @@ -60,19 +62,21 @@ void ActionDrawCircleCR::trigger() container->addEntity(circle); // upd. undo list: - if (document != NULL) + if (document) { document->startUndoCycle(); document->addUndoable(circle); document->endUndoCycle(); } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0, 0.0)); - graphicView->drawEntity(circle); - graphicView->moveRelativeZero(circle->getCenter()); - drawSnapper(); +// deleteSnapper(); +// Vector rz = graphicView->getRelativeZero(); +// graphicView->moveRelativeZero(Vector(0.0, 0.0)); +// graphicView->drawEntity(circle); +// graphicView->moveRelativeZero(circle->getCenter()); +// drawSnapper(); + graphicView->preview.clear(); // hm. + graphicView->redraw(); setStatus(SetCenter); @@ -88,13 +92,16 @@ void ActionDrawCircleCR::mouseMoveEvent(QMouseEvent * e) { case SetCenter: data.center = mouse; - deletePreview(); - clearPreview(); +// deletePreview(); +// clearPreview(); // preview->addEntity(new Circle(preview, data)); - drawPreview(); +// drawPreview(); + graphicView->preview.clear(); + graphicView->preview.addEntity(new Circle(&(graphicView->preview), data)); break; } + graphicView->redraw(); DEBUG->print("ActionDrawCircleCR::mouseMoveEvent end"); } @@ -107,9 +114,10 @@ void ActionDrawCircleCR::mouseReleaseEvent(QMouseEvent * e) } else if (e->button() == Qt::RightButton) { - deletePreview(); - deleteSnapper(); +// deletePreview(); +// deleteSnapper(); init(getStatus() - 1); + graphicView->redraw(); // hm. } } diff --git a/src/actions/actiondrawhatch.cpp b/src/actions/actiondrawhatch.cpp index a85a58a..a7fbe9a 100644 --- a/src/actions/actiondrawhatch.cpp +++ b/src/actions/actiondrawhatch.cpp @@ -34,7 +34,7 @@ ActionDrawHatch::~ActionDrawHatch() void ActionDrawHatch::init(int status) { ActionInterface::init(status); - clearPreview(); +// clearPreview(); Hatch tmp(container, data); tmp.setLayerToActive(); @@ -55,7 +55,7 @@ void ActionDrawHatch::trigger() { DEBUG->print("ActionDrawHatch::trigger()"); - deleteSnapper(); +// deleteSnapper(); Entity * e; // deselect unhatchable entities: @@ -136,7 +136,6 @@ void ActionDrawHatch::trigger() } hatch->update(); - graphicView->drawEntity(hatch); DIALOGFACTORY->commandMessage(tr("Hatch created successfully.")); } else @@ -151,21 +150,6 @@ void ActionDrawHatch::trigger() void ActionDrawHatch::mouseMoveEvent(QMouseEvent *) { DEBUG->print("ActionDrawHatch::mouseMoveEvent begin"); - - /*if (getStatus()==SetPos) { - Vector mouse = snapPoint(e); - pos = mouse; - - - deletePreview(); - if (hatch!=NULL && !hatch->isVisible()) { - hatch->setVisible(true); - } - offset = Vector(graphicView->toGuiDX(pos.x), - -graphicView->toGuiDY(pos.y)); - drawPreview(); - }*/ - DEBUG->print("ActionDrawHatch::mouseMoveEvent end"); } @@ -186,9 +170,9 @@ void ActionDrawHatch::mouseReleaseEvent(QMouseEvent * e) } else if (e->button() == Qt::RightButton) { - //deletePreview(); - deleteSnapper(); init(getStatus() - 1); +//doesn't clear the preview or snapper. + graphicView->redraw(); // hm. } } diff --git a/src/base/entity.cpp b/src/base/entity.cpp index b963731..b9c42e3 100644 --- a/src/base/entity.cpp +++ b/src/base/entity.cpp @@ -202,10 +202,10 @@ bool Entity::isParentSelected() { p = p->getParent(); - if (p != NULL && p->isSelected() == true) + if (p && p->isSelected() == true) return true; } - while(p != NULL); + while (p); return false; } @@ -1058,7 +1058,7 @@ std::ostream & operator<<(std::ostream & os, Entity & e) } #endif - // There should be a better way then this... + // There should be a better way than this... switch (e.rtti()) { case RS2::EntityPoint: diff --git a/src/base/entitycontainer.cpp b/src/base/entitycontainer.cpp index 7babc88..ec5840f 100644 --- a/src/base/entitycontainer.cpp +++ b/src/base/entitycontainer.cpp @@ -123,13 +123,11 @@ void EntityContainer::detach() void EntityContainer::reparent(EntityContainer * parent) { - Entity::reparent(parent); + Entity::reparent(parent); - // All sub-entities: - for(Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone)) - { - e->reparent(parent); - } + // All sub-entities: + for(Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone)) + e->reparent(parent); } /** diff --git a/src/base/pattern.cpp b/src/base/pattern.cpp index 26af65b..b1f4046 100644 --- a/src/base/pattern.cpp +++ b/src/base/pattern.cpp @@ -26,29 +26,12 @@ * * @param fileName File name of a DXF file defining the pattern */ -Pattern::Pattern(const QString & fileName): EntityContainer(NULL) +Pattern::Pattern(const QString & file): EntityContainer(NULL), + filename(file), loaded(false) { DEBUG->print("Pattern::Pattern() "); - - this->fileName = fileName; - loaded = false; } -/** - * Constructor. - * - * @param fileName File name of a PAT file which defines this - * pattern among others. - * @param name Pattern name. - * - */ -/*Pattern::Pattern(const QString& fileName, const QString& name) - : EntityContainer(NULL) { - this->fileName = fileName; - this->name = name; - loaded = false; -}*/ - Pattern::~Pattern() { } @@ -66,21 +49,20 @@ bool Pattern::loadPattern() return true; DEBUG->print("Pattern::loadPattern"); - QString path; // Search for the appropriate pattern if we have only the name of the pattern: - if (!fileName.toLower().contains(".dxf")) + if (!filename.toLower().contains(".dxf")) { QStringList patterns = SYSTEM->getPatternList(); QFileInfo file; for(QStringList::Iterator it=patterns.begin(); it!=patterns.end(); it++) { - if (QFileInfo(*it).baseName().toLower() == fileName.toLower()) + if (QFileInfo(*it).baseName().toLower() == filename.toLower()) { path = *it; - DEBUG->print("Pattern found: %s", path.toLatin1().data()); + DEBUG->print("Pattern found: %s", path.toAscii().data()); break; } } @@ -88,39 +70,37 @@ bool Pattern::loadPattern() // We have the full path of the pattern: else { - path = fileName; + path = filename; } // No pattern paths found: if (path.isEmpty()) { - DEBUG->print("No pattern \"%s\"available.", fileName.toLatin1().data()); + DEBUG->print("No pattern \"%s\"available.", filename.toAscii().data()); return false; } - Drawing * gr = new Drawing(); + Drawing * drawing = new Drawing(); // TODO: Find out why the new dxf filter doesn't work for patterns: - FILEIO->fileImport(*gr, path, RS2::FormatDXF1); + FILEIO->fileImport(*drawing, path, RS2::FormatDXF1); - for(Entity * e=gr->firstEntity(); e!=NULL; e=gr->nextEntity()) + for(Entity * e=drawing->firstEntity(); e!=NULL; e=drawing->nextEntity()) { if (e->rtti() == RS2::EntityLine || e->rtti() == RS2::EntityArc) { - Layer * l = e->getLayer(); - Entity * cl = e->clone(); - cl->reparent(this); + Entity * clone = e->clone(); + clone->reparent(this); + Layer * layer = e->getLayer(); - if (l != NULL) - { - cl->setLayer(l->getName()); - } + if (layer) + clone->setLayer(layer->getName()); - addEntity(cl); + addEntity(clone); } } - delete gr; + delete drawing; loaded = true; DEBUG->print("Pattern::loadPattern: OK"); @@ -130,5 +110,5 @@ bool Pattern::loadPattern() /** @return the fileName of this pattern. */ QString Pattern::getFileName() const { - return fileName; + return filename; } diff --git a/src/base/pattern.h b/src/base/pattern.h index 8818d51..0c90a6c 100644 --- a/src/base/pattern.h +++ b/src/base/pattern.h @@ -14,7 +14,7 @@ class PatternList; class Pattern: public EntityContainer { public: - Pattern(const QString & fileName); + Pattern(const QString & file); virtual ~Pattern(); virtual bool loadPattern(); @@ -22,7 +22,7 @@ class Pattern: public EntityContainer protected: //! Pattern file name - QString fileName; + QString filename; //! Is this pattern currently loaded into memory? bool loaded; }; diff --git a/src/base/patternlist.cpp b/src/base/patternlist.cpp index 989d406..41e26ae 100644 --- a/src/base/patternlist.cpp +++ b/src/base/patternlist.cpp @@ -12,6 +12,7 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 06/01/2010 Added this text. :-) +// JLH 09/13/2010 Fixed next() function to return a valid pointer. // #include "patternlist.h" @@ -25,13 +26,11 @@ PatternList * PatternList::uniqueInstance = NULL; */ PatternList::PatternList(): patternIterator(patterns) { -#warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!" -// patterns.setAutoDelete(true); - //patternListListeners.setAutoDelete(false); } /*virtual*/ PatternList::~PatternList() { + clearPatterns(); } /** @@ -51,23 +50,19 @@ PatternList::PatternList(): patternIterator(patterns) */ void PatternList::init() { - DEBUG->print("PatternList::initPatterns"); + DEBUG->print("PatternList::initPatterns"); + QStringList list = SYSTEM->getPatternList(); +// patterns.clear(); + clearPatterns(); - QStringList list = SYSTEM->getPatternList(); - Pattern * pattern; - - patterns.clear(); - - for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it) + for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it) { - DEBUG->print("pattern: %s:", (*it).toLatin1().data()); - - QFileInfo fi(*it); - pattern = new Pattern(fi.baseName().toLower()); - patterns.append(pattern); - - DEBUG->print("base: %s", pattern->getFileName().toLatin1().data()); - } + DEBUG->print("pattern: %s:", (*it).toAscii().data()); + QFileInfo fi(*it); + Pattern * pattern = new Pattern(fi.baseName().toLower()); + patterns.append(pattern); + DEBUG->print("base: %s", pattern->getFileName().toAscii().data()); + } } /** @@ -75,7 +70,14 @@ void PatternList::init() */ void PatternList::clearPatterns() { - patterns.clear(); + patternIterator = patterns; + + while (patternIterator.hasNext()) + delete patternIterator.next(); + + // Apparently this is still needed as the list will still be populated with + // stale pointers... + patterns.clear(); } int PatternList::countPatterns() @@ -91,20 +93,10 @@ int PatternList::countPatterns() void PatternList::removePattern(Pattern * pattern) { DEBUG->print("PatternList::removePattern()"); - - // here the pattern is removed from the list but not deleted -// patterns.remove(pattern); -//Apparently we need to delete this shit here because of missing AutoDelete -//function when going from Qt3->4 int i = patterns.indexOf(pattern); if (i != -1) delete patterns.takeAt(i); - - //for (uint i=0; ipatternRemoved(pattern); - //} } /** @@ -114,15 +106,12 @@ void PatternList::removePattern(Pattern * pattern) */ Pattern * PatternList::requestPattern(const QString & name) { - DEBUG->print("PatternList::requestPattern %s", name.toLatin1().data()); - - QString name2 = name.toLower(); Pattern * foundPattern = NULL; - - DEBUG->print("name2: %s", name2.toLatin1().data()); + QString name2 = name.toLower(); + DEBUG->print("PatternList::requestPattern %s", name.toAscii().data()); + DEBUG->print("name2: %s", name2.toAscii().data()); // Search our list of available patterns: -// for(Pattern * p=patterns.first(); p!=NULL; p=patterns.next()) for(int i=0; itext(), 1.0); double angle = Math::deg2rad(Math::eval(ui.leAngle->text(), 0.0)); - if (pattern != NULL) + if (pattern) prevSize = pattern->getSize().x * 10; else prevSize = 10.0; diff --git a/src/forms/dlghatch.ui b/src/forms/dlghatch.ui index 89145e3..f8a15cf 100644 --- a/src/forms/dlghatch.ui +++ b/src/forms/dlghatch.ui @@ -276,9 +276,9 @@ cbPattern - patternChanged(RS_Pattern*) + patternChanged(Pattern*) DlgHatch - updatePreview(RS_Pattern*) + updatePreview(Pattern*) 20 diff --git a/src/widgets/patternbox.cpp b/src/widgets/patternbox.cpp index a66fd16..fe4e249 100644 --- a/src/widgets/patternbox.cpp +++ b/src/widgets/patternbox.cpp @@ -36,7 +36,7 @@ PatternBox::~PatternBox() } /** - * Initialisation (called manually and only once). + * Initialization (called manually and only once). */ void PatternBox::init() { @@ -45,8 +45,15 @@ void PatternBox::init() for(Pattern * f=PATTERNLIST->firstPattern(); f!=NULL; f=PATTERNLIST->nextPattern()) patterns.append(f->getFileName()); +#if 0 +std::cout << "patterns size = " << patterns.size() << std::endl; + +for(int i=0; iprint("PatternBox::setPattern %s\n", pName.toLatin1().data()); -// setCurrentText(pName); + DEBUG->print("PatternBox::setPattern %s\n", pName.toAscii().data()); setItemText(currentIndex(), pName); slotPatternChanged(currentIndex()); } @@ -80,8 +86,8 @@ void PatternBox::slotPatternChanged(int index) DEBUG->print("PatternBox::slotPatternChanged %d\n", index); currentPattern = PATTERNLIST->requestPattern(currentText()); - if (currentPattern!=NULL) - DEBUG->print("Current pattern is (%d): %s\n", index, currentPattern->getFileName().toLatin1().data()); + if (currentPattern) + DEBUG->print("Current pattern is (%d): %s\n", index, currentPattern->getFileName().toAscii().data()); emit patternChanged(currentPattern); } -- 2.37.2