]> Shamusworld >> Repos - architektonas/blobdiff - src/widgets/qg_dialogfactory.cpp
Start of bringing back missing forms/dialogs
[architektonas] / src / widgets / qg_dialogfactory.cpp
index f698cdb363eb8c51ee613894c441f844d6ba4f5b..632ce8dc174b21c78bfe7e92a1b79b77c58db9ea 100644 (file)
 #include "rs_text.h"
 
 #if 0
-#include "ui/qg_arcoptions.h"
-#include "ui/qg_arctangentialoptions.h"
-#include "ui/qg_beveloptions.h"
+       #include "ui/qg_arcoptions.h"
+       #include "ui/qg_arctangentialoptions.h"
+       #include "ui/qg_beveloptions.h"
        #include "ui/qg_blockdialog.h"
        #include "ui/qg_cadtoolbar.h"
-#include "ui/qg_circleoptions.h"
+       #include "ui/qg_circleoptions.h"
        #include "ui/qg_commandwidget.h"
        #include "ui/qg_coordinatewidget.h"
 #include "ui/qg_dimlinearoptions.h"
        #include "ui/qg_textoptions.h"
 #include "ui/qg_trimamountoptions.h"
 #endif
+#include "arcoptions.h"
+#include "arctangentialoptions.h"
+#include "beveloptions.h"
 #include "blockdialog.h"
 #include "cadtoolbar.h"
+#include "circleoptions.h"
 #include "commandwidget.h"
 #include "coordinatewidget.h"
 #include "dlgattributes.h"
  * @param parent Pointer to parent widget which can host dialogs.
  * @param ow Pointer to widget that can host option widgets.
  */
-QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
+//QG_DialogFactory::QG_DialogFactory(QWidget * parent, QWidget * ow):
+QG_DialogFactory::QG_DialogFactory(QWidget * parent, QToolBar * ow):
        RS_DialogFactoryInterface()
 {
        RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory");
@@ -138,7 +143,8 @@ QG_DialogFactory::~QG_DialogFactory()
 /**
  * Links factory to a widget that can host tool options.
  */
-/*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
+///*virtual*/ void QG_DialogFactory::setOptionWidget(QWidget * ow)
+/*virtual*/ void QG_DialogFactory::setOptionWidget(QToolBar * ow)
 {
        RS_DEBUG->print("QG_DialogFactory::setOptionWidget");
        optionWidget = ow;
@@ -859,18 +865,19 @@ void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, b
 {
        static PrintPreviewOptions * toolWidget = NULL;
 
-       if (optionWidget != NULL)
+       if (!optionWidget)
+               return;
+
+       if (toolWidget)
        {
-               if (toolWidget != NULL)
-               {
-                       delete toolWidget;
-                       toolWidget = NULL;
-               }
-               if (on && toolWidget == NULL)
-               {
-                       toolWidget = new PrintPreviewOptions(optionWidget);
-                       toolWidget->setAction(action, update);
-               }
+               delete toolWidget;
+               toolWidget = NULL;
+       }
+
+       if (on)
+       {
+               toolWidget = new PrintPreviewOptions(optionWidget);
+               toolWidget->setAction(action, update);
        }
 }
 
@@ -879,21 +886,29 @@ void QG_DialogFactory::requestPrintPreviewOptions(RS_ActionInterface * action, b
  */
 void QG_DialogFactory::requestLineOptions(RS_ActionInterface * action, bool on)
 {
+/*
+The way I see it, this is failure. We're constantly creating & deleting
+these objects all the time when we could create them once, and then reuse
+them over and over. May need to do some more refactoring based on this idea...
+*/
+       //ugh.
        static LineOptions * toolWidget = NULL;
 
-       if (optionWidget != NULL)
+       if (!optionWidget)
+               return;
+
+       // Get rid of the LineOptions object if it exists...
+       if (toolWidget)
        {
-               if (toolWidget != NULL)
-               {
-                       delete toolWidget;
-                       toolWidget = NULL;
-               }
+               delete toolWidget;
+               toolWidget = NULL;
+       }
 
-               if (on == true && toolWidget == NULL)
-               {
-                       toolWidget = new LineOptions(optionWidget);
-                       toolWidget->setAction(action);
-               }
+       // Create a new one for the passed in action
+       if (on)
+       {
+               toolWidget = new LineOptions(optionWidget);
+               toolWidget->setAction(action);
        }
 
        RS_DEBUG->print("QG_DialogFactory::requestLineOptions: OK");
@@ -1065,68 +1080,6 @@ void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action,
     }
 }
 
-/**
- * Shows a widget for arc options.
- */
-void QG_DialogFactory::requestArcOptions(RS_ActionInterface* action,
-        bool on, bool update)
-{
-    static QG_ArcOptions* toolWidget = NULL;
-
-    if (optionWidget!=NULL) {
-        if (toolWidget!=NULL) {
-            delete toolWidget;
-            toolWidget = NULL;
-        }
-        if (on==true && toolWidget==NULL) {
-            toolWidget = new QG_ArcOptions(optionWidget);
-            toolWidget->setAction(action, update);
-            //toolWidget->setData(&data);
-        }
-    }
-}
-
-/**
- * Shows a widget for tangential arc options.
- */
-void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface* action,
-        bool on, bool update)
-{
-    static QG_ArcTangentialOptions* toolWidget = NULL;
-
-    if (optionWidget!=NULL) {
-        if (toolWidget!=NULL) {
-            delete toolWidget;
-            toolWidget = NULL;
-        }
-        if (on==true && toolWidget==NULL) {
-            toolWidget = new QG_ArcTangentialOptions(optionWidget);
-            toolWidget->setAction(action, update);
-            //toolWidget->setData(&data);
-        }
-    }
-}
-
-/**
- * Shows a widget for arc options.
- */
-void QG_DialogFactory::requestCircleOptions(RS_ActionInterface* action,
-        bool on, bool update)
-{
-    static QG_CircleOptions* toolWidget = NULL;
-
-    if (optionWidget!=NULL) {
-        if (toolWidget!=NULL) {
-            delete toolWidget;
-            toolWidget = NULL;
-        }
-        if (on==true && toolWidget==NULL) {
-            toolWidget = new QG_CircleOptions(optionWidget);
-            toolWidget->setAction(action, update);
-        }
-    }
-}
-
 /**
  * Shows a widget for spline options.
  */
@@ -1147,26 +1100,6 @@ void QG_DialogFactory::requestSplineOptions(RS_ActionInterface* action,
     }
 }
 
-/**
- * Shows a widget for text options.
- */
-void QG_DialogFactory::requestTextOptions(RS_ActionInterface* action,
-        bool on, bool update)
-{
-    static QG_TextOptions* toolWidget = NULL;
-
-    if (optionWidget!=NULL) {
-        if (toolWidget!=NULL) {
-            delete toolWidget;
-            toolWidget = NULL;
-        }
-        if (on==true && toolWidget==NULL) {
-            toolWidget = new QG_TextOptions(optionWidget);
-            toolWidget->setAction(action, update);
-        }
-    }
-}
-
 /**
  * Shows a widget for insert options.
  */
@@ -1308,26 +1241,6 @@ void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface* action,
     }
 }
 
-/**
- * Shows a widget for beveling options.
- */
-void QG_DialogFactory::requestBevelOptions(RS_ActionInterface* action,
-        bool on, bool update)
-{
-    static QG_BevelOptions* toolWidget = NULL;
-
-    if (optionWidget!=NULL) {
-        if (toolWidget!=NULL) {
-            delete toolWidget;
-            toolWidget = NULL;
-        }
-        if (on==true && toolWidget==NULL) {
-            toolWidget = new QG_BevelOptions(optionWidget);
-            toolWidget->setAction(action, update);
-        }
-    }
-}
-
 /**
  * Shows a widget for rounding options.
  */
@@ -1396,16 +1309,75 @@ void QG_DialogFactory::requestLinePolygon2Options(RS_ActionInterface* action, bo
 {
 }
 
-void QG_DialogFactory::requestArcOptions(RS_ActionInterface* action, bool on, bool update)
+/**
+ * Shows a widget for arc options.
+ */
+void QG_DialogFactory::requestArcOptions(RS_ActionInterface * action, bool on, bool update)
 {
+       static ArcOptions * toolWidget = NULL;
+
+       if (optionWidget != NULL)
+       {
+               if (toolWidget != NULL)
+               {
+                       delete toolWidget;
+                       toolWidget = NULL;
+               }
+
+               if (on && toolWidget == NULL)
+               {
+                       toolWidget = new ArcOptions(optionWidget);
+                       toolWidget->setAction(action, update);
+                       //toolWidget->setData(&data);
+               }
+       }
 }
 
-void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface* action, bool on, bool update)
+/**
+ * Shows a widget for tangential arc options.
+ */
+void QG_DialogFactory::requestArcTangentialOptions(RS_ActionInterface * action, bool on, bool update)
 {
+       static ArcTangentialOptions * toolWidget = NULL;
+
+       if (!optionWidget)
+               return;
+
+       if (toolWidget)
+       {
+               delete toolWidget;
+               toolWidget = NULL;
+       }
+
+       if (on)
+       {
+               toolWidget = new ArcTangentialOptions(optionWidget);
+               toolWidget->setAction(action, update);
+               //toolWidget->setData(&data);
+       }
 }
 
-void QG_DialogFactory::requestCircleOptions(RS_ActionInterface* action, bool on, bool update)
+/**
+ * Shows a widget for circle options.
+ */
+void QG_DialogFactory::requestCircleOptions(RS_ActionInterface * action, bool on, bool update)
 {
+    static CircleOptions * toolWidget = NULL;
+
+    if (optionWidget)
+       {
+        if (toolWidget)
+               {
+            delete toolWidget;
+            toolWidget = NULL;
+        }
+
+        if (on && toolWidget == NULL)
+               {
+            toolWidget = new CircleOptions(optionWidget);
+            toolWidget->setAction(action, update);
+        }
+    }
 }
 
 void QG_DialogFactory::requestSplineOptions(RS_ActionInterface* action, bool on, bool update)
@@ -1419,19 +1391,19 @@ void QG_DialogFactory::requestTextOptions(RS_ActionInterface * action, bool on,
 {
        static TextOptions * toolWidget = NULL;
 
-       if (optionWidget != NULL)
+       if (!optionWidget)
+               return;
+
+       if (toolWidget)
        {
-               if (toolWidget != NULL)
-               {
-                       delete toolWidget;
-                       toolWidget = NULL;
-               }
+               delete toolWidget;
+               toolWidget = NULL;
+       }
 
-               if (on == true && toolWidget == NULL)
-               {
-                       toolWidget = new TextOptions(optionWidget);
-                       toolWidget->setAction(action, update);
-               }
+       if (on)
+       {
+               toolWidget = new TextOptions(optionWidget);
+               toolWidget->setAction(action, update);
        }
 }
 
@@ -1463,8 +1435,27 @@ void QG_DialogFactory::requestTrimAmountOptions(RS_ActionInterface* action, bool
 {
 }
 
-void QG_DialogFactory::requestBevelOptions(RS_ActionInterface* action, bool on, bool update)
+/**
+ * Shows a widget for beveling options.
+ */
+void QG_DialogFactory::requestBevelOptions(RS_ActionInterface * action, bool on, bool update)
 {
+    static BevelOptions * toolWidget = NULL;
+
+    if (optionWidget != NULL)
+       {
+        if (toolWidget != NULL)
+               {
+            delete toolWidget;
+            toolWidget = NULL;
+        }
+
+               if (on && toolWidget == NULL)
+               {
+            toolWidget = new BevelOptions(optionWidget);
+            toolWidget->setAction(action, update);
+        }
+    }
 }
 
 void QG_DialogFactory::requestRoundOptions(RS_ActionInterface* action, bool on, bool update)