]> Shamusworld >> Repos - architektonas/commitdiff
Fixed hatch dialog, added snap/preview to circle tools.
authorShamus Hammons <jlhamm@acm.org>
Mon, 13 Sep 2010 21:40:56 +0000 (21:40 +0000)
committerShamus Hammons <jlhamm@acm.org>
Mon, 13 Sep 2010 21:40:56 +0000 (21:40 +0000)
14 files changed:
src/actions/actiondimleader.cpp
src/actions/actiondrawcircle.cpp
src/actions/actiondrawcircle2p.cpp
src/actions/actiondrawcircle3p.cpp
src/actions/actiondrawcirclecr.cpp
src/actions/actiondrawhatch.cpp
src/base/entity.cpp
src/base/entitycontainer.cpp
src/base/pattern.cpp
src/base/pattern.h
src/base/patternlist.cpp
src/forms/dlghatch.cpp
src/forms/dlghatch.ui
src/widgets/patternbox.cpp

index f65ff3192240e4f884381be10541baa88097b7de..52165067c872072bc6e80fdf6729c1aaeaf0bf84 100644 (file)
@@ -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; i<points.size(); i++)
                        leader->addVertex(*(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(", "));
 
index 7c19be06412e87f7781e5eea632c0b239fafd763..9f64a0ee1c23ab2b13ac7838e50964ecc9c5a7c8 100644 (file)
@@ -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:
index d580bb33f7e30aca5369e0c894b9f4aa8810fea4..676db76006406b822195676f43652fbb4fe0b510 100644 (file)
@@ -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();
        }
 }
 
index eacd6d89b02b8fdbdd9a0dc33f4b380fbc6727f3..a20d8f49d533a6fc5269bf5f329d684dbabc6458 100644 (file)
@@ -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.
        }
 }
 
index dfd1150790067a17b02a030df4999069639fc70b..daebf4cc9cd3afc40220a934e22741e143690d91 100644 (file)
@@ -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.
        }
 }
 
index a85a58af7022ca419d316702443e9fa14f1f965c..a7fbe9a15bc287ff82dfafc153140465e04df726 100644 (file)
@@ -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.
        }
 }
 
index b963731bf22d411f902d2d59b36c30a6ab4aa200..b9c42e3f5df5e08c4cd1525bf0acbae0f0ba1628 100644 (file)
@@ -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:
index 7babc889d54de73a4465a732d57777d8745b45bf..ec5840fb906d91896914db8cd22d471980941138 100644 (file)
@@ -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);
 }
 
 /**
index 26af65b4593b35a13a209940d2308f6d1f983ee5..b1f404623178ead5a330954d2f9e1e03eb822755 100644 (file)
  *
  * @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;
 }
index 8818d516decf8a18a7a5792fc4bc55260c75576b..0c90a6cf5983665904350f7592c94746d1bb6836 100644 (file)
@@ -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;
 };
index 989d406bf3ef6c2b021344791e58cbc84f033df5..41e26aed6b3045261a8b7a94530ec3db24352b1d 100644 (file)
@@ -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; i<patternListListeners.count(); ++i) {
-       //    PatternListListener* l = patternListListeners.at(i);
-       //    l->patternRemoved(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; i<patterns.size(); i++)
        {
                Pattern * p = patterns[i];
@@ -136,18 +125,16 @@ Pattern * PatternList::requestPattern(const QString & name)
                }
        }
 
-       //if (foundPattern==NULL && name!="standard") {
-       //    foundPattern = requestPattern("standard");
-       //}
-
        return foundPattern;
 }
 
 //! @return First pattern of the list.
 Pattern * PatternList::firstPattern()
 {
-       patternIterator.toFront();
-       return patternIterator.next();
+       // Looks like this is necessary--constructor doesn't do it...
+       // Constructor is necessary, apparently, even though we do this.
+       patternIterator = patterns;
+       return nextPattern();
 }
 
 /**
@@ -156,7 +143,9 @@ Pattern * PatternList::firstPattern()
  */
 Pattern * PatternList::nextPattern()
 {
-       return patternIterator.next();
+       // We absolutely HAVE to do a hasNext() check or we'll hand back a bogus
+       // pointer/object. Not good!
+       return (patternIterator.hasNext() ? patternIterator.next() : NULL);
 }
 
 bool PatternList::contains(const QString & name)
@@ -164,7 +153,6 @@ bool PatternList::contains(const QString & name)
        QString name2 = name.toLower();
 
        // Search our list of available patterns:
-//     for(Pattern * p=patterns.first(); p!=NULL; p=patterns.next())
        for(int i=0; i<patterns.size(); i++)
        {
                Pattern * p = patterns[i];
@@ -181,9 +169,10 @@ bool PatternList::contains(const QString & name)
  */
 std::ostream & operator<<(std::ostream & os, PatternList & l)
 {
-    os << "Patternlist: \n";
-    for(Pattern * p=l.firstPattern(); p!=NULL; p=l.nextPattern())
-        os << *p << "\n";
+       os << "Patternlist: \n";
+
+       for(Pattern * p=l.firstPattern(); p!=NULL; p=l.nextPattern())
+               os << *p << "\n";
 
-    return os;
+       return os;
 }
index 514c32415966eb10680a16296048b6a33d4981d0..79e0711ddf514f5837b1eb47b40f7f671efbbca3 100644 (file)
@@ -156,7 +156,7 @@ void DlgHatch::updatePreview(Pattern *)
        //double scale = Math::eval(leScale->text(), 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;
index 89145e3954130480ff97d6bf6965a628cb68a7b3..f8a15cf2a6a44bf4bb4b1f18f36b92694720be39 100644 (file)
   </connection>
   <connection>
    <sender>cbPattern</sender>
-   <signal>patternChanged(RS_Pattern*)</signal>
+   <signal>patternChanged(Pattern*)</signal>
    <receiver>DlgHatch</receiver>
-   <slot>updatePreview(RS_Pattern*)</slot>
+   <slot>updatePreview(Pattern*)</slot>
    <hints>
     <hint type="sourcelabel">
      <x>20</x>
index a66fd169d3b222e56b4ab50803c6ed1978f7f878..fe4e2498764874d8f1a2c7e22bda67695fbd0cfb 100644 (file)
@@ -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; i<patterns.size(); i++)
+       std::cout << patterns.at(i).toLocal8Bit().constData() << std::endl;
+
+std::cout.flush();
+#endif
        patterns.sort();
-//     insertStringList(patterns);
        addItems(patterns);
 
        connect(this, SIGNAL(activated(int)), this, SLOT(slotPatternChanged(int)));
@@ -65,8 +72,7 @@ Pattern * PatternBox::getPattern()
  */
 void PatternBox::setPattern(const QString & pName)
 {
-       DEBUG->print("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);
 }