[Libreoffice-commits] core.git: chart2/source

Markus Mohrhard markus.mohrhard at googlemail.com
Fri Jul 31 08:39:15 PDT 2015


 chart2/source/controller/sidebar/ChartAreaPanel.cxx     |   14 ++++++++++----
 chart2/source/controller/sidebar/ChartAreaPanel.hxx     |    1 +
 chart2/source/controller/sidebar/ChartAxisPanel.cxx     |   15 ++++++++++++---
 chart2/source/controller/sidebar/ChartAxisPanel.hxx     |    2 ++
 chart2/source/controller/sidebar/ChartElementsPanel.cxx |   16 ++++++++++++----
 chart2/source/controller/sidebar/ChartElementsPanel.hxx |    2 ++
 chart2/source/controller/sidebar/ChartErrorBarPanel.cxx |   15 ++++++++++++---
 chart2/source/controller/sidebar/ChartErrorBarPanel.hxx |    2 ++
 chart2/source/controller/sidebar/ChartLinePanel.cxx     |   14 ++++++++++----
 chart2/source/controller/sidebar/ChartLinePanel.hxx     |    1 +
 chart2/source/controller/sidebar/ChartSeriesPanel.cxx   |   16 ++++++++++++----
 chart2/source/controller/sidebar/ChartSeriesPanel.hxx   |    2 ++
 12 files changed, 78 insertions(+), 22 deletions(-)

New commits:
commit 8b0109f28e48c8ba3fc2d77467351ec2c7b87629
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Jul 31 17:34:56 2015 +0200

    avoid crash when chart model is disposed
    
    Change-Id: I70c3a06e2aa9112cd5a47b7d8839c4bd701cfc1e

diff --git a/chart2/source/controller/sidebar/ChartAreaPanel.cxx b/chart2/source/controller/sidebar/ChartAreaPanel.cxx
index 233371a..3230e7c 100644
--- a/chart2/source/controller/sidebar/ChartAreaPanel.cxx
+++ b/chart2/source/controller/sidebar/ChartAreaPanel.cxx
@@ -236,7 +236,8 @@ ChartAreaPanel::ChartAreaPanel(vcl::Window* pParent,
     mxModel(pController->getModel()),
     mxListener(new ChartSidebarModifyListener(this)),
     mxSelectionListener(new ChartSidebarSelectionListener(this)),
-    mbUpdate(true)
+    mbUpdate(true),
+    mbModelValid(true)
 {
     std::vector<ObjectType> aAcceptedTypes { OBJECTTYPE_PAGE, OBJECTTYPE_DIAGRAM, OBJECTTYPE_DATA_SERIES, OBJECTTYPE_TITLE, OBJECTTYPE_LEGEND};
     mxSelectionListener->setAcceptedTypes(aAcceptedTypes);
@@ -366,7 +367,7 @@ void ChartAreaPanel::setFillStyleAndBitmap(const XFillStyleItem* pStyleItem,
 
 void ChartAreaPanel::updateData()
 {
-    if (!mbUpdate)
+    if (!mbUpdate || !mbModelValid)
         return;
 
     css::uno::Reference<css::beans::XPropertySet> xPropSet = getPropSet(mxModel);
@@ -423,6 +424,7 @@ void ChartAreaPanel::updateData()
 
 void ChartAreaPanel::modelInvalid()
 {
+    mbModelValid = false;
 }
 
 void ChartAreaPanel::selectionChanged(bool bCorrectType)
@@ -438,10 +440,14 @@ void ChartAreaPanel::SelectionInvalid()
 void ChartAreaPanel::updateModel(
         css::uno::Reference<css::frame::XModel> xModel)
 {
-    css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
-    xBroadcaster->removeModifyListener(mxListener);
+    if (mbModelValid)
+    {
+        css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
+        xBroadcaster->removeModifyListener(mxListener);
+    }
 
     mxModel = xModel;
+    mbModelValid = true;
 
     css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW);
     xBroadcasterNew->addModifyListener(mxListener);
diff --git a/chart2/source/controller/sidebar/ChartAreaPanel.hxx b/chart2/source/controller/sidebar/ChartAreaPanel.hxx
index 2d2920e..48df2ac 100644
--- a/chart2/source/controller/sidebar/ChartAreaPanel.hxx
+++ b/chart2/source/controller/sidebar/ChartAreaPanel.hxx
@@ -91,6 +91,7 @@ private:
     void Initialize();
 
     bool mbUpdate;
+    bool mbModelValid;
 };
 
 } } // end of namespace svx::sidebar
diff --git a/chart2/source/controller/sidebar/ChartAxisPanel.cxx b/chart2/source/controller/sidebar/ChartAxisPanel.cxx
index fa6100e..3866b98 100644
--- a/chart2/source/controller/sidebar/ChartAxisPanel.cxx
+++ b/chart2/source/controller/sidebar/ChartAxisPanel.cxx
@@ -191,7 +191,8 @@ ChartAxisPanel::ChartAxisPanel(
     mxFrame(rxFrame),
     mxModel(pController->getModel()),
     mxModifyListener(new ChartSidebarModifyListener(this)),
-    mxSelectionListener(new ChartSidebarSelectionListener(this, OBJECTTYPE_AXIS))
+    mxSelectionListener(new ChartSidebarSelectionListener(this, OBJECTTYPE_AXIS)),
+    mbModelValid(true)
 {
     get(mpCBShowLabel, "checkbutton_show_label");
     get(mpCBReverse, "checkbutton_reverse");
@@ -246,6 +247,9 @@ void ChartAxisPanel::Initialize()
 
 void ChartAxisPanel::updateData()
 {
+    if (!mbModelValid)
+        return;
+
     OUString aCID = getCID(mxModel);
     SolarMutexGuard aGuard;
 
@@ -291,15 +295,20 @@ void ChartAxisPanel::NotifyItemUpdate(
 
 void ChartAxisPanel::modelInvalid()
 {
+    mbModelValid = false;
 }
 
 void ChartAxisPanel::updateModel(
         css::uno::Reference<css::frame::XModel> xModel)
 {
-    css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
-    xBroadcaster->removeModifyListener(mxModifyListener);
+    if (mbModelValid)
+    {
+        css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
+        xBroadcaster->removeModifyListener(mxModifyListener);
+    }
 
     mxModel = xModel;
+    mbModelValid = true;
 
     css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW);
     xBroadcasterNew->addModifyListener(mxModifyListener);
diff --git a/chart2/source/controller/sidebar/ChartAxisPanel.hxx b/chart2/source/controller/sidebar/ChartAxisPanel.hxx
index e6d878b..b38a32f 100644
--- a/chart2/source/controller/sidebar/ChartAxisPanel.hxx
+++ b/chart2/source/controller/sidebar/ChartAxisPanel.hxx
@@ -88,6 +88,8 @@ private:
     css::uno::Reference<css::util::XModifyListener> mxModifyListener;
     css::uno::Reference<css::view::XSelectionChangeListener> mxSelectionListener;
 
+    bool mbModelValid;
+
     void Initialize();
 
     DECL_LINK(CheckBoxHdl, CheckBox*);
diff --git a/chart2/source/controller/sidebar/ChartElementsPanel.cxx b/chart2/source/controller/sidebar/ChartElementsPanel.cxx
index 08d1fea..2545e49 100644
--- a/chart2/source/controller/sidebar/ChartElementsPanel.cxx
+++ b/chart2/source/controller/sidebar/ChartElementsPanel.cxx
@@ -289,7 +289,8 @@ ChartElementsPanel::ChartElementsPanel(
     mxFrame(rxFrame),
     maContext(),
     mxModel(pController->getModel()),
-    mxListener(new ChartSidebarModifyListener(this))
+    mxListener(new ChartSidebarModifyListener(this)),
+    mbModelValid(true)
 {
     get(mpCBTitle,  "checkbutton_title");
     get(mpCBSubtitle,  "checkbutton_subtitle");
@@ -379,6 +380,9 @@ void ChartElementsPanel::Initialize()
 
 void ChartElementsPanel::updateData()
 {
+    if (!mbModelValid)
+        return;
+
     Reference< chart2::XDiagram > xDiagram(ChartModelHelper::findDiagram(mxModel));
     sal_Int32 nDimension = DiagramHelper::getDimension(xDiagram);
     SolarMutexGuard aGuard;
@@ -452,16 +456,20 @@ void ChartElementsPanel::NotifyItemUpdate(
 
 void ChartElementsPanel::modelInvalid()
 {
-
+    mbModelValid = false;
 }
 
 void ChartElementsPanel::updateModel(
         css::uno::Reference<css::frame::XModel> xModel)
 {
-    css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
-    xBroadcaster->removeModifyListener(mxListener);
+    if (mbModelValid)
+    {
+        css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
+        xBroadcaster->removeModifyListener(mxListener);
+    }
 
     mxModel = xModel;
+    mbModelValid = true;
 
     css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW);
     xBroadcasterNew->addModifyListener(mxListener);
diff --git a/chart2/source/controller/sidebar/ChartElementsPanel.hxx b/chart2/source/controller/sidebar/ChartElementsPanel.hxx
index 47265fb..50ceb72 100644
--- a/chart2/source/controller/sidebar/ChartElementsPanel.hxx
+++ b/chart2/source/controller/sidebar/ChartElementsPanel.hxx
@@ -104,6 +104,8 @@ private:
     css::uno::Reference<css::frame::XModel> mxModel;
     css::uno::Reference<css::util::XModifyListener> mxListener;
 
+    bool mbModelValid;
+
     void Initialize();
 
     DECL_LINK(CheckBoxHdl, CheckBox*);
diff --git a/chart2/source/controller/sidebar/ChartErrorBarPanel.cxx b/chart2/source/controller/sidebar/ChartErrorBarPanel.cxx
index 3163f95..c319943 100644
--- a/chart2/source/controller/sidebar/ChartErrorBarPanel.cxx
+++ b/chart2/source/controller/sidebar/ChartErrorBarPanel.cxx
@@ -244,7 +244,8 @@ ChartErrorBarPanel::ChartErrorBarPanel(
   : PanelLayout(pParent, "ChartErrorBarPanel", "modules/schart/ui/sidebarerrorbar.ui", rxFrame),
     mxFrame(rxFrame),
     mxModel(pController->getModel()),
-    mxListener(new ChartSidebarModifyListener(this))
+    mxListener(new ChartSidebarModifyListener(this)),
+    mbModelValid(true)
 {
 
     get(mpRBPosAndNeg, "radiobutton_positive_negative");
@@ -302,6 +303,9 @@ void ChartErrorBarPanel::Initialize()
 
 void ChartErrorBarPanel::updateData()
 {
+    if (!mbModelValid)
+        return;
+
     OUString aCID = getCID(mxModel);
     bool bPos = showPositiveError(mxModel, aCID);
     bool bNeg = showNegativeError(mxModel, aCID);
@@ -379,15 +383,20 @@ void ChartErrorBarPanel::NotifyItemUpdate(
 
 void ChartErrorBarPanel::modelInvalid()
 {
+    mbModelValid = false;
 }
 
 void ChartErrorBarPanel::updateModel(
         css::uno::Reference<css::frame::XModel> xModel)
 {
-    css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
-    xBroadcaster->removeModifyListener(mxListener);
+    if (mbModelValid)
+    {
+        css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
+        xBroadcaster->removeModifyListener(mxListener);
+    }
 
     mxModel = xModel;
+    mbModelValid = true;
 
     css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW);
     xBroadcasterNew->addModifyListener(mxListener);
diff --git a/chart2/source/controller/sidebar/ChartErrorBarPanel.hxx b/chart2/source/controller/sidebar/ChartErrorBarPanel.hxx
index e9c102b..bdfd954 100644
--- a/chart2/source/controller/sidebar/ChartErrorBarPanel.hxx
+++ b/chart2/source/controller/sidebar/ChartErrorBarPanel.hxx
@@ -84,6 +84,8 @@ private:
     css::uno::Reference<css::frame::XModel> mxModel;
     css::uno::Reference<css::util::XModifyListener> mxListener;
 
+    bool mbModelValid;
+
     void Initialize();
 
     DECL_LINK(RadioBtnHdl, void*);
diff --git a/chart2/source/controller/sidebar/ChartLinePanel.cxx b/chart2/source/controller/sidebar/ChartLinePanel.cxx
index eead55d..d025c5e 100644
--- a/chart2/source/controller/sidebar/ChartLinePanel.cxx
+++ b/chart2/source/controller/sidebar/ChartLinePanel.cxx
@@ -121,7 +121,8 @@ ChartLinePanel::ChartLinePanel(vcl::Window* pParent,
     mxModel(pController->getModel()),
     mxListener(new ChartSidebarModifyListener(this)),
     mxSelectionListener(new ChartSidebarSelectionListener(this)),
-    mbUpdate(true)
+    mbUpdate(true),
+    mbModelValid(true)
 {
     std::vector<ObjectType> aAcceptedTypes { OBJECTTYPE_PAGE, OBJECTTYPE_DIAGRAM, OBJECTTYPE_DATA_SERIES, OBJECTTYPE_TITLE, OBJECTTYPE_LEGEND};
     mxSelectionListener->setAcceptedTypes(aAcceptedTypes);
@@ -160,7 +161,7 @@ void ChartLinePanel::Initialize()
 
 void ChartLinePanel::updateData()
 {
-    if (!mbUpdate)
+    if (!mbUpdate || !mbModelValid)
         return;
 
     css::uno::Reference<css::beans::XPropertySet> xPropSet = getPropSet(mxModel);
@@ -188,6 +189,7 @@ void ChartLinePanel::updateData()
 
 void ChartLinePanel::modelInvalid()
 {
+    mbModelValid = false;
 }
 
 void ChartLinePanel::selectionChanged(bool bCorrectType)
@@ -203,10 +205,14 @@ void ChartLinePanel::SelectionInvalid()
 void ChartLinePanel::updateModel(
         css::uno::Reference<css::frame::XModel> xModel)
 {
-    css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
-    xBroadcaster->removeModifyListener(mxListener);
+    if (mbModelValid)
+    {
+        css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
+        xBroadcaster->removeModifyListener(mxListener);
+    }
 
     mxModel = xModel;
+    mbModelValid = true;
 
     css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW);
     xBroadcasterNew->addModifyListener(mxListener);
diff --git a/chart2/source/controller/sidebar/ChartLinePanel.hxx b/chart2/source/controller/sidebar/ChartLinePanel.hxx
index a2b2ea5..1b614b0 100644
--- a/chart2/source/controller/sidebar/ChartLinePanel.hxx
+++ b/chart2/source/controller/sidebar/ChartLinePanel.hxx
@@ -95,6 +95,7 @@ private:
     void Initialize();
 
     bool mbUpdate;
+    bool mbModelValid;
 };
 
 } } // end of namespace svx::sidebar
diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx
index 85336ff..7632620 100644
--- a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx
+++ b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx
@@ -292,7 +292,8 @@ ChartSeriesPanel::ChartSeriesPanel(
     mxFrame(rxFrame),
     mxModel(pController->getModel()),
     mxListener(new ChartSidebarModifyListener(this)),
-    mxSelectionListener(new ChartSidebarSelectionListener(this, OBJECTTYPE_DATA_SERIES))
+    mxSelectionListener(new ChartSidebarSelectionListener(this, OBJECTTYPE_DATA_SERIES)),
+    mbModelValid(true)
 {
     get(mpCBLabel, "checkbutton_label");
     get(mpCBTrendline, "checkbutton_trendline");
@@ -366,6 +367,9 @@ void ChartSeriesPanel::Initialize()
 
 void ChartSeriesPanel::updateData()
 {
+    if (!mbModelValid)
+        return;
+
     OUString aCID = getCID(mxModel);
     SolarMutexGuard aGuard;
     bool bLabelVisible = isDataLabelVisible(mxModel, aCID);
@@ -422,16 +426,20 @@ void ChartSeriesPanel::NotifyItemUpdate(
 
 void ChartSeriesPanel::modelInvalid()
 {
-
+    mbModelValid = false;
 }
 
 void ChartSeriesPanel::updateModel(
         css::uno::Reference<css::frame::XModel> xModel)
 {
-    css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
-    xBroadcaster->removeModifyListener(mxListener);
+    if (mbModelValid)
+    {
+        css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
+        xBroadcaster->removeModifyListener(mxListener);
+    }
 
     mxModel = xModel;
+    mbModelValid = true;
 
     css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW);
     xBroadcasterNew->addModifyListener(mxListener);
diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.hxx b/chart2/source/controller/sidebar/ChartSeriesPanel.hxx
index d125c2f..be580cb 100644
--- a/chart2/source/controller/sidebar/ChartSeriesPanel.hxx
+++ b/chart2/source/controller/sidebar/ChartSeriesPanel.hxx
@@ -104,6 +104,8 @@ private:
     css::uno::Reference<css::util::XModifyListener> mxListener;
     css::uno::Reference<css::view::XSelectionChangeListener> mxSelectionListener;
 
+    bool mbModelValid;
+
     void Initialize();
 
     DECL_LINK(CheckBoxHdl, CheckBox*);


More information about the Libreoffice-commits mailing list