| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <com/sun/star/chart2/LegendPosition.hpp> |
| 21 |
#include <com/sun/star/chart/ChartLegendExpansion.hpp> |
| 22 |
|
| 23 |
#include <vcl/svapp.hxx> |
| 24 |
|
| 25 |
#include "ChartElementsPanel.hxx" |
| 26 |
#include <ChartController.hxx> |
| 27 |
#include <comphelper/processfactory.hxx> |
| 28 |
|
| 29 |
#include <Legend.hxx> |
| 30 |
#include <LegendHelper.hxx> |
| 31 |
#include <AxisHelper.hxx> |
| 32 |
#include <Diagram.hxx> |
| 33 |
#include <ChartType.hxx> |
| 34 |
#include <ChartModel.hxx> |
| 35 |
#include <BaseCoordinateSystem.hxx> |
| 36 |
|
| 37 |
|
| 38 |
using namespace css; |
| 39 |
using namespace css::uno; |
| 40 |
|
| 41 |
namespace chart::sidebar { |
| 42 |
|
| 43 |
namespace { |
| 44 |
|
| 45 |
enum class GridType |
| 46 |
{ |
| 47 |
VERT_MAJOR, |
| 48 |
VERT_MINOR, |
| 49 |
HOR_MAJOR, |
| 50 |
HOR_MINOR |
| 51 |
}; |
| 52 |
|
| 53 |
enum class AxisType |
| 54 |
{ |
| 55 |
X_MAIN, |
| 56 |
Y_MAIN, |
| 57 |
Z_MAIN, |
| 58 |
X_SECOND, |
| 59 |
Y_SECOND |
| 60 |
}; |
| 61 |
|
| 62 |
ChartModel* getChartModel(const css::uno::Reference<css::frame::XModel>& xModel) |
| 63 |
{ |
| 64 |
ChartModel* pModel = dynamic_cast<ChartModel*>(xModel.get()); |
| 65 |
|
| 66 |
return pModel; |
| 67 |
} |
| 68 |
|
| 69 |
bool isLegendVisible(const css::uno::Reference<css::frame::XModel>& xModel) |
| 70 |
{ |
| 71 |
ChartModel* pModel = getChartModel(xModel); |
| 72 |
if (!pModel) |
| 73 |
return false; |
| 74 |
|
| 75 |
rtl::Reference< Legend > xLegendProp = LegendHelper::getLegend(*pModel); |
| 76 |
if( xLegendProp.is()) |
| 77 |
{ |
| 78 |
try |
| 79 |
{ |
| 80 |
bool bShow = false; |
| 81 |
if( xLegendProp->getPropertyValue( u"Show"_ustr) >>= bShow ) |
| 82 |
{ |
| 83 |
return bShow; |
| 84 |
} |
| 85 |
} |
| 86 |
catch(const uno::Exception &) |
| 87 |
{ |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
return false; |
| 92 |
} |
| 93 |
|
| 94 |
void setLegendVisible(const css::uno::Reference<css::frame::XModel>& xModel, bool bVisible) |
| 95 |
{ |
| 96 |
ChartModel* pModel = getChartModel(xModel); |
| 97 |
if (!pModel) |
| 98 |
return; |
| 99 |
|
| 100 |
if (bVisible) |
| 101 |
LegendHelper::showLegend(*pModel, comphelper::getProcessComponentContext()); |
| 102 |
else |
| 103 |
LegendHelper::hideLegend(*pModel); |
| 104 |
} |
| 105 |
|
| 106 |
bool isLegendOverlay(const css::uno::Reference<css::frame::XModel>& xModel) |
| 107 |
{ |
| 108 |
ChartModel* pModel = getChartModel(xModel); |
| 109 |
if (!pModel) |
| 110 |
return false; |
| 111 |
|
| 112 |
rtl::Reference< Legend > xLegendProp = LegendHelper::getLegend(*pModel); |
| 113 |
if( xLegendProp.is()) |
| 114 |
{ |
| 115 |
try |
| 116 |
{ |
| 117 |
bool bOverlay = false; |
| 118 |
if(xLegendProp->getPropertyValue(u"Overlay"_ustr) >>= bOverlay) |
| 119 |
{ |
| 120 |
return bOverlay; |
| 121 |
} |
| 122 |
} |
| 123 |
catch(const uno::Exception &) |
| 124 |
{ |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
return false; |
| 129 |
} |
| 130 |
|
| 131 |
void setLegendOverlay(const css::uno::Reference<css::frame::XModel>& xModel, bool bOverlay) |
| 132 |
{ |
| 133 |
ChartModel* pModel = getChartModel(xModel); |
| 134 |
if (!pModel) |
| 135 |
return; |
| 136 |
|
| 137 |
rtl::Reference<Legend> xLegendProp = LegendHelper::getLegend(*pModel); |
| 138 |
if (!xLegendProp.is()) |
| 139 |
return; |
| 140 |
|
| 141 |
xLegendProp->setPropertyValue(u"Overlay"_ustr, css::uno::Any(bOverlay)); |
| 142 |
} |
| 143 |
|
| 144 |
bool isTitleVisible(const rtl::Reference<::chart::ChartModel>& xModel, TitleHelper::eTitleType eTitle) |
| 145 |
{ |
| 146 |
rtl::Reference<Title> xTitle = TitleHelper::getTitle(eTitle, xModel); |
| 147 |
if (!xTitle.is()) |
| 148 |
return false; |
| 149 |
|
| 150 |
css::uno::Any aAny = xTitle->getPropertyValue(u"Visible"_ustr); |
| 151 |
bool bVisible = aAny.get<bool>(); |
| 152 |
return bVisible; |
| 153 |
} |
| 154 |
|
| 155 |
bool isGridVisible(const rtl::Reference<::chart::ChartModel>& xModel, GridType eType) |
| 156 |
{ |
| 157 |
rtl::Reference< Diagram > xDiagram(xModel->getFirstChartDiagram()); |
| 158 |
if(xDiagram.is()) |
| 159 |
{ |
| 160 |
sal_Int32 nDimensionIndex = 0; |
| 161 |
if (eType == GridType::HOR_MAJOR || eType == GridType::HOR_MINOR) |
| 162 |
nDimensionIndex = 1; |
| 163 |
|
| 164 |
bool bMajor = (eType == GridType::HOR_MAJOR || eType == GridType::VERT_MAJOR); |
| 165 |
|
| 166 |
bool bHasGrid = AxisHelper::isGridShown(nDimensionIndex, 0, bMajor, xDiagram); |
| 167 |
return bHasGrid; |
| 168 |
} |
| 169 |
return false; |
| 170 |
} |
| 171 |
|
| 172 |
void setGridVisible(const rtl::Reference<::chart::ChartModel>& xModel, GridType eType, bool bVisible) |
| 173 |
{ |
| 174 |
rtl::Reference< Diagram > xDiagram(xModel->getFirstChartDiagram()); |
| 175 |
if(!xDiagram.is()) |
| 176 |
return; |
| 177 |
|
| 178 |
sal_Int32 nDimensionIndex = 0; |
| 179 |
if (eType == GridType::HOR_MAJOR || eType == GridType::HOR_MINOR) |
| 180 |
nDimensionIndex = 1; |
| 181 |
sal_Int32 nCooSysIndex = 0; |
| 182 |
|
| 183 |
bool bMajor = (eType == GridType::HOR_MAJOR || eType == GridType::VERT_MAJOR); |
| 184 |
|
| 185 |
if (bVisible) |
| 186 |
AxisHelper::showGrid(nDimensionIndex, nCooSysIndex, bMajor, |
| 187 |
xDiagram); |
| 188 |
else |
| 189 |
AxisHelper::hideGrid(nDimensionIndex, nCooSysIndex, bMajor, xDiagram); |
| 190 |
} |
| 191 |
|
| 192 |
bool isAxisVisible(const rtl::Reference<::chart::ChartModel>& xModel, AxisType eType) |
| 193 |
{ |
| 194 |
rtl::Reference< Diagram > xDiagram(xModel->getFirstChartDiagram()); |
| 195 |
if(xDiagram.is()) |
| 196 |
{ |
| 197 |
sal_Int32 nDimensionIndex = 0; |
| 198 |
if (eType == AxisType::Y_MAIN || eType == AxisType::Y_SECOND) |
| 199 |
nDimensionIndex = 1; |
| 200 |
else if (eType == AxisType::Z_MAIN) |
| 201 |
nDimensionIndex = 2; |
| 202 |
|
| 203 |
bool bMajor = (eType != AxisType::X_SECOND && eType != AxisType::Y_SECOND); |
| 204 |
|
| 205 |
bool bHasAxis = AxisHelper::isAxisShown(nDimensionIndex, bMajor, xDiagram); |
| 206 |
return bHasAxis; |
| 207 |
} |
| 208 |
return false; |
| 209 |
} |
| 210 |
|
| 211 |
void setAxisVisible(const rtl::Reference<::chart::ChartModel>& xModel, AxisType eType, bool bVisible) |
| 212 |
{ |
| 213 |
rtl::Reference< Diagram > xDiagram(xModel->getFirstChartDiagram()); |
| 214 |
if(!xDiagram.is()) |
| 215 |
return; |
| 216 |
|
| 217 |
sal_Int32 nDimensionIndex = 0; |
| 218 |
if (eType == AxisType::Y_MAIN || eType == AxisType::Y_SECOND) |
| 219 |
nDimensionIndex = 1; |
| 220 |
else if (eType == AxisType::Z_MAIN) |
| 221 |
nDimensionIndex = 2; |
| 222 |
|
| 223 |
bool bMajor = (eType != AxisType::X_SECOND && eType != AxisType::Y_SECOND); |
| 224 |
|
| 225 |
if (bVisible) |
| 226 |
AxisHelper::showAxis(nDimensionIndex, bMajor, xDiagram, comphelper::getProcessComponentContext()); |
| 227 |
else |
| 228 |
AxisHelper::hideAxis(nDimensionIndex, bMajor, xDiagram); |
| 229 |
} |
| 230 |
|
| 231 |
sal_Int32 getLegendPos(const css::uno::Reference<css::frame::XModel>& xModel) |
| 232 |
{ |
| 233 |
ChartModel* pModel = getChartModel(xModel); |
| 234 |
if (!pModel) |
| 235 |
return -1; |
| 236 |
|
| 237 |
rtl::Reference< Legend > xLegendProp = LegendHelper::getLegend(*pModel); |
| 238 |
if (!xLegendProp.is()) |
| 239 |
return -1; |
| 240 |
|
| 241 |
chart2::LegendPosition eLegendPos = chart2::LegendPosition_LINE_END; |
| 242 |
xLegendProp->getPropertyValue(u"AnchorPosition"_ustr) >>= eLegendPos; |
| 243 |
switch(eLegendPos) |
| 244 |
{ |
| 245 |
case chart2::LegendPosition_LINE_START: |
| 246 |
return 3; |
| 247 |
case chart2::LegendPosition_LINE_END: |
| 248 |
return 0; |
| 249 |
case chart2::LegendPosition_PAGE_START: |
| 250 |
return 1; |
| 251 |
case chart2::LegendPosition_PAGE_END: |
| 252 |
return 2; |
| 253 |
default: |
| 254 |
return -1; |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
void setLegendPos(const css::uno::Reference<css::frame::XModel>& xModel, sal_Int32 nPos) |
| 259 |
{ |
| 260 |
ChartModel* pModel = getChartModel(xModel); |
| 261 |
if (!pModel) |
| 262 |
return; |
| 263 |
|
| 264 |
rtl::Reference< Legend > xLegendProp = LegendHelper::getLegend(*pModel); |
| 265 |
if (!xLegendProp.is()) |
| 266 |
return; |
| 267 |
|
| 268 |
chart2::LegendPosition eLegendPos = chart2::LegendPosition_LINE_END; |
| 269 |
css::chart::ChartLegendExpansion eExpansion = css::chart::ChartLegendExpansion_HIGH; |
| 270 |
switch(nPos) |
| 271 |
{ |
| 272 |
case 1: |
| 273 |
eLegendPos = chart2::LegendPosition_PAGE_START; |
| 274 |
eExpansion = css::chart::ChartLegendExpansion_WIDE; |
| 275 |
break; |
| 276 |
case 3: |
| 277 |
eLegendPos = chart2::LegendPosition_LINE_START; |
| 278 |
break; |
| 279 |
case 0: |
| 280 |
eLegendPos = chart2::LegendPosition_LINE_END; |
| 281 |
break; |
| 282 |
case 2: |
| 283 |
eLegendPos = chart2::LegendPosition_PAGE_END; |
| 284 |
eExpansion = css::chart::ChartLegendExpansion_WIDE; |
| 285 |
break; |
| 286 |
default: |
| 287 |
assert(false); |
| 288 |
} |
| 289 |
|
| 290 |
xLegendProp->setPropertyValue(u"AnchorPosition"_ustr, css::uno::Any(eLegendPos)); |
| 291 |
xLegendProp->setPropertyValue(u"Expansion"_ustr, css::uno::Any(eExpansion)); |
| 292 |
xLegendProp->setPropertyValue(u"RelativePosition"_ustr, uno::Any()); |
| 293 |
} |
| 294 |
|
| 295 |
} |
| 296 |
|
| 297 |
ChartElementsPanel::ChartElementsPanel( |
| 298 |
weld::Widget* pParent, ChartController* pController) |
| 299 |
: PanelLayout(pParent, u"ChartElementsPanel"_ustr, u"modules/schart/ui/sidebarelements.ui"_ustr) |
| 300 |
, mxCBTitle(m_xBuilder->weld_check_button(u"checkbutton_title"_ustr)) |
| 301 |
, mxEditTitle(m_xBuilder->weld_entry(u"edit_title"_ustr)) |
| 302 |
, mxCBSubtitle(m_xBuilder->weld_check_button(u"checkbutton_subtitle"_ustr)) |
| 303 |
, mxEditSubtitle(m_xBuilder->weld_entry(u"edit_subtitle"_ustr)) |
| 304 |
, mxCBXAxis(m_xBuilder->weld_check_button(u"checkbutton_x_axis"_ustr)) |
| 305 |
, mxCBXAxisTitle(m_xBuilder->weld_check_button(u"checkbutton_x_axis_title"_ustr)) |
| 306 |
, mxCBYAxis(m_xBuilder->weld_check_button(u"checkbutton_y_axis"_ustr)) |
| 307 |
, mxCBYAxisTitle(m_xBuilder->weld_check_button(u"checkbutton_y_axis_title"_ustr)) |
| 308 |
, mxCBZAxis(m_xBuilder->weld_check_button(u"checkbutton_z_axis"_ustr)) |
| 309 |
, mxCBZAxisTitle(m_xBuilder->weld_check_button(u"checkbutton_z_axis_title"_ustr)) |
| 310 |
, mxCB2ndXAxis(m_xBuilder->weld_check_button(u"checkbutton_2nd_x_axis"_ustr)) |
| 311 |
, mxCB2ndXAxisTitle(m_xBuilder->weld_check_button(u"checkbutton_2nd_x_axis_title"_ustr)) |
| 312 |
, mxCB2ndYAxis(m_xBuilder->weld_check_button(u"checkbutton_2nd_y_axis"_ustr)) |
| 313 |
, mxCB2ndYAxisTitle(m_xBuilder->weld_check_button(u"checkbutton_2nd_y_axis_title"_ustr)) |
| 314 |
, mxCBLegend(m_xBuilder->weld_check_button(u"checkbutton_legend"_ustr)) |
| 315 |
, mxCBLegendNoOverlay(m_xBuilder->weld_check_button(u"checkbutton_no_overlay"_ustr)) |
| 316 |
, mxCBGridVerticalMajor(m_xBuilder->weld_check_button(u"checkbutton_gridline_vertical_major"_ustr)) |
| 317 |
, mxCBGridHorizontalMajor(m_xBuilder->weld_check_button(u"checkbutton_gridline_horizontal_major"_ustr)) |
| 318 |
, mxCBGridVerticalMinor(m_xBuilder->weld_check_button(u"checkbutton_gridline_vertical_minor"_ustr)) |
| 319 |
, mxCBGridHorizontalMinor(m_xBuilder->weld_check_button(u"checkbutton_gridline_horizontal_minor"_ustr)) |
| 320 |
, mxTextTitle(m_xBuilder->weld_label(u"text_title"_ustr)) |
| 321 |
, mxTextSubTitle(m_xBuilder->weld_label(u"text_subtitle"_ustr)) |
| 322 |
, mxLBAxis(m_xBuilder->weld_label(u"label_axes"_ustr)) |
| 323 |
, mxLBGrid(m_xBuilder->weld_label(u"label_gri"_ustr)) |
| 324 |
, mxLBLegendPosition(m_xBuilder->weld_combo_box(u"comboboxtext_legend"_ustr)) |
| 325 |
, mxBoxLegend(m_xBuilder->weld_widget(u"box_legend"_ustr)) |
| 326 |
, mxModel(pController->getChartModel()) |
| 327 |
, mxListener(new ChartSidebarModifyListener(this)) |
| 328 |
, mbModelValid(true) |
| 329 |
{ |
| 330 |
maTextTitle = mxTextTitle->get_label(); |
| 331 |
maTextSubTitle = mxTextSubTitle->get_label(); |
| 332 |
|
| 333 |
Initialize(); |
| 334 |
} |
| 335 |
|
| 336 |
ChartElementsPanel::~ChartElementsPanel() |
| 337 |
{ |
| 338 |
doUpdateModel(nullptr); |
| 339 |
|
| 340 |
mxCBTitle.reset(); |
| 341 |
mxEditTitle.reset(); |
| 342 |
mxCBSubtitle.reset(); |
| 343 |
mxEditSubtitle.reset(); |
| 344 |
mxCBXAxis.reset(); |
| 345 |
mxCBXAxisTitle.reset(); |
| 346 |
mxCBYAxis.reset(); |
| 347 |
mxCBYAxisTitle.reset(); |
| 348 |
mxCBZAxis.reset(); |
| 349 |
mxCBZAxisTitle.reset(); |
| 350 |
mxCB2ndXAxis.reset(); |
| 351 |
mxCB2ndXAxisTitle.reset(); |
| 352 |
mxCB2ndYAxis.reset(); |
| 353 |
mxCB2ndYAxisTitle.reset(); |
| 354 |
mxCBLegend.reset(); |
| 355 |
mxCBLegendNoOverlay.reset(); |
| 356 |
mxCBGridVerticalMajor.reset(); |
| 357 |
mxCBGridHorizontalMajor.reset(); |
| 358 |
mxCBGridVerticalMinor.reset(); |
| 359 |
mxCBGridHorizontalMinor.reset(); |
| 360 |
|
| 361 |
mxLBLegendPosition.reset(); |
| 362 |
mxBoxLegend.reset(); |
| 363 |
|
| 364 |
mxLBAxis.reset(); |
| 365 |
mxLBGrid.reset(); |
| 366 |
|
| 367 |
mxTextTitle.reset(); |
| 368 |
mxTextSubTitle.reset(); |
| 369 |
} |
| 370 |
|
| 371 |
void ChartElementsPanel::Initialize() |
| 372 |
{ |
| 373 |
mxModel->addModifyListener(mxListener); |
| 374 |
updateData(); |
| 375 |
|
| 376 |
Link<weld::Toggleable&,void> aLink = LINK(this, ChartElementsPanel, CheckBoxHdl); |
| 377 |
mxCBTitle->connect_toggled(aLink); |
| 378 |
mxCBSubtitle->connect_toggled(aLink); |
| 379 |
mxCBXAxis->connect_toggled(aLink); |
| 380 |
mxCBXAxisTitle->connect_toggled(aLink); |
| 381 |
mxCBYAxis->connect_toggled(aLink); |
| 382 |
mxCBYAxisTitle->connect_toggled(aLink); |
| 383 |
mxCBZAxis->connect_toggled(aLink); |
| 384 |
mxCBZAxisTitle->connect_toggled(aLink); |
| 385 |
mxCB2ndXAxis->connect_toggled(aLink); |
| 386 |
mxCB2ndXAxisTitle->connect_toggled(aLink); |
| 387 |
mxCB2ndYAxis->connect_toggled(aLink); |
| 388 |
mxCB2ndYAxisTitle->connect_toggled(aLink); |
| 389 |
mxCBLegend->connect_toggled(aLink); |
| 390 |
mxCBLegendNoOverlay->connect_toggled(aLink); |
| 391 |
mxCBGridVerticalMajor->connect_toggled(aLink); |
| 392 |
mxCBGridHorizontalMajor->connect_toggled(aLink); |
| 393 |
mxCBGridVerticalMinor->connect_toggled(aLink); |
| 394 |
mxCBGridHorizontalMinor->connect_toggled(aLink); |
| 395 |
|
| 396 |
mxLBLegendPosition->connect_changed(LINK(this, ChartElementsPanel, LegendPosHdl)); |
| 397 |
|
| 398 |
Link<weld::Entry&, void> aEditLink = LINK(this, ChartElementsPanel, EditHdl); |
| 399 |
mxEditTitle->connect_changed(aEditLink); |
| 400 |
mxEditSubtitle->connect_changed(aEditLink); |
| 401 |
} |
| 402 |
|
| 403 |
namespace { |
| 404 |
|
| 405 |
rtl::Reference<ChartType> getChartType(const rtl::Reference<ChartModel>& xModel) |
| 406 |
{ |
| 407 |
rtl::Reference<Diagram > xDiagram = xModel->getFirstChartDiagram(); |
| 408 |
if (!xDiagram.is()) |
| 409 |
return nullptr; |
| 410 |
|
| 411 |
const std::vector<rtl::Reference<BaseCoordinateSystem>> xCooSysSequence(xDiagram->getBaseCoordinateSystems()); |
| 412 |
|
| 413 |
if (xCooSysSequence.empty()) |
| 414 |
return nullptr; |
| 415 |
|
| 416 |
const std::vector<rtl::Reference<ChartType>> & xChartTypeSequence(xCooSysSequence[0]->getChartTypes2()); |
| 417 |
|
| 418 |
if (xChartTypeSequence.empty()) |
| 419 |
return nullptr; |
| 420 |
|
| 421 |
return xChartTypeSequence[0]; |
| 422 |
} |
| 423 |
|
| 424 |
} |
| 425 |
|
| 426 |
void ChartElementsPanel::updateData() |
| 427 |
{ |
| 428 |
if (!mbModelValid) |
| 429 |
return; |
| 430 |
|
| 431 |
rtl::Reference< Diagram > xDiagram(mxModel->getFirstChartDiagram()); |
| 432 |
sal_Int32 nDimension = 0; |
| 433 |
if (xDiagram) |
| 434 |
nDimension = xDiagram->getDimension(); |
| 435 |
SolarMutexGuard aGuard; |
| 436 |
|
| 437 |
mxCBLegend->set_active(isLegendVisible(mxModel)); |
| 438 |
mxCBLegendNoOverlay->set_sensitive(isLegendVisible(mxModel)); |
| 439 |
mxCBLegendNoOverlay->set_active(!isLegendOverlay(mxModel)); |
| 440 |
mxBoxLegend->set_sensitive(isLegendVisible(mxModel)); |
| 441 |
|
| 442 |
bool hasTitle = isTitleVisible(mxModel, TitleHelper::MAIN_TITLE); |
| 443 |
mxCBTitle->set_active(hasTitle); |
| 444 |
|
| 445 |
OUString title = mxEditTitle->get_text(); |
| 446 |
OUString newTitle = TitleHelper::getCompleteString(TitleHelper::getTitle(TitleHelper::MAIN_TITLE, mxModel)); |
| 447 |
if (title != newTitle) |
| 448 |
mxEditTitle->set_text(newTitle); |
| 449 |
if (mxEditTitle->get_sensitive() != hasTitle) |
| 450 |
mxEditTitle->set_sensitive(hasTitle); |
| 451 |
|
| 452 |
bool hasSubtitle = isTitleVisible(mxModel, TitleHelper::SUB_TITLE); |
| 453 |
mxCBSubtitle->set_active(hasSubtitle); |
| 454 |
|
| 455 |
OUString subtitle = mxEditSubtitle->get_text(); |
| 456 |
OUString newSubtitle = TitleHelper::getCompleteString(TitleHelper::getTitle(TitleHelper::SUB_TITLE, mxModel)); |
| 457 |
if (subtitle != newSubtitle) |
| 458 |
mxEditSubtitle->set_text(newSubtitle); |
| 459 |
if (mxEditSubtitle->get_sensitive() != hasSubtitle) |
| 460 |
mxEditSubtitle->set_sensitive(hasSubtitle); |
| 461 |
|
| 462 |
mxCBXAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::X_AXIS_TITLE)); |
| 463 |
mxCBYAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::Y_AXIS_TITLE)); |
| 464 |
mxCBZAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::Z_AXIS_TITLE)); |
| 465 |
mxCB2ndXAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::SECONDARY_X_AXIS_TITLE)); |
| 466 |
mxCB2ndYAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::SECONDARY_Y_AXIS_TITLE)); |
| 467 |
mxCBGridVerticalMajor->set_active(isGridVisible(mxModel, GridType::VERT_MAJOR)); |
| 468 |
mxCBGridHorizontalMajor->set_active(isGridVisible(mxModel, GridType::HOR_MAJOR)); |
| 469 |
mxCBGridVerticalMinor->set_active(isGridVisible(mxModel, GridType::VERT_MINOR)); |
| 470 |
mxCBGridHorizontalMinor->set_active(isGridVisible(mxModel, GridType::HOR_MINOR)); |
| 471 |
mxCBXAxis->set_active(isAxisVisible(mxModel, AxisType::X_MAIN)); |
| 472 |
mxCBYAxis->set_active(isAxisVisible(mxModel, AxisType::Y_MAIN)); |
| 473 |
mxCBZAxis->set_active(isAxisVisible(mxModel, AxisType::Z_MAIN)); |
| 474 |
mxCB2ndXAxis->set_active(isAxisVisible(mxModel, AxisType::X_SECOND)); |
| 475 |
mxCB2ndYAxis->set_active(isAxisVisible(mxModel, AxisType::Y_SECOND)); |
| 476 |
|
| 477 |
auto xChartType = getChartType(mxModel); |
| 478 |
bool bSupportsMainAxis = xChartType.is() ? xChartType->isSupportingMainAxis(0, 0) : true; |
| 479 |
if (bSupportsMainAxis) |
| 480 |
{ |
| 481 |
mxCBXAxis->show(); |
| 482 |
mxCBYAxis->show(); |
| 483 |
mxCBZAxis->show(); |
| 484 |
mxCBXAxisTitle->show(); |
| 485 |
mxCBYAxisTitle->show(); |
| 486 |
mxCBZAxisTitle->show(); |
| 487 |
mxCBGridVerticalMajor->show(); |
| 488 |
mxCBGridVerticalMinor->show(); |
| 489 |
mxCBGridHorizontalMajor->show(); |
| 490 |
mxCBGridHorizontalMinor->show(); |
| 491 |
mxLBAxis->show(); |
| 492 |
mxLBGrid->show(); |
| 493 |
} |
| 494 |
else |
| 495 |
{ |
| 496 |
mxCBXAxis->hide(); |
| 497 |
mxCBYAxis->hide(); |
| 498 |
mxCBZAxis->hide(); |
| 499 |
mxCBXAxisTitle->hide(); |
| 500 |
mxCBYAxisTitle->hide(); |
| 501 |
mxCBZAxisTitle->hide(); |
| 502 |
mxCBGridVerticalMajor->hide(); |
| 503 |
mxCBGridVerticalMinor->hide(); |
| 504 |
mxCBGridHorizontalMajor->hide(); |
| 505 |
mxCBGridHorizontalMinor->hide(); |
| 506 |
mxLBAxis->hide(); |
| 507 |
mxLBGrid->hide(); |
| 508 |
} |
| 509 |
|
| 510 |
if (nDimension == 3) |
| 511 |
{ |
| 512 |
mxCBZAxis->set_sensitive(true); |
| 513 |
mxCBZAxisTitle->set_sensitive(true); |
| 514 |
} |
| 515 |
else |
| 516 |
{ |
| 517 |
mxCBZAxis->set_sensitive(false); |
| 518 |
mxCBZAxisTitle->set_sensitive(false); |
| 519 |
} |
| 520 |
|
| 521 |
mxLBLegendPosition->set_active(getLegendPos(mxModel)); |
| 522 |
} |
| 523 |
|
| 524 |
std::unique_ptr<PanelLayout> ChartElementsPanel::Create ( |
| 525 |
weld::Widget* pParent, |
| 526 |
ChartController* pController) |
| 527 |
{ |
| 528 |
if (pParent == nullptr) |
| 529 |
throw lang::IllegalArgumentException(u"no parent Window given to ChartElementsPanel::Create"_ustr, nullptr, 0); |
| 530 |
return std::make_unique<ChartElementsPanel>(pParent, pController); |
| 531 |
} |
| 532 |
|
| 533 |
void ChartElementsPanel::DataChanged(const DataChangedEvent& rEvent) |
| 534 |
{ |
| 535 |
PanelLayout::DataChanged(rEvent); |
| 536 |
updateData(); |
| 537 |
} |
| 538 |
|
| 539 |
void ChartElementsPanel::HandleContextChange( |
| 540 |
const vcl::EnumContext& rContext) |
| 541 |
{ |
| 542 |
if(maContext == rContext) |
| 543 |
{ |
| 544 |
// Nothing to do. |
| 545 |
return; |
| 546 |
} |
| 547 |
|
| 548 |
maContext = rContext; |
| 549 |
updateData(); |
| 550 |
} |
| 551 |
|
| 552 |
void ChartElementsPanel::modelInvalid() |
| 553 |
{ |
| 554 |
mbModelValid = false; |
| 555 |
} |
| 556 |
|
| 557 |
void ChartElementsPanel::doUpdateModel(const rtl::Reference<::chart::ChartModel>& xModel) |
| 558 |
{ |
| 559 |
if (mbModelValid) |
| 560 |
{ |
| 561 |
mxModel->removeModifyListener(mxListener); |
| 562 |
} |
| 563 |
|
| 564 |
mxModel = xModel; |
| 565 |
mbModelValid = mxModel.is(); |
| 566 |
|
| 567 |
if (!mbModelValid) |
| 568 |
return; |
| 569 |
|
| 570 |
mxModel->addModifyListener(mxListener); |
| 571 |
} |
| 572 |
|
| 573 |
void ChartElementsPanel::updateModel(css::uno::Reference<css::frame::XModel> xModel) |
| 574 |
{ |
| 575 |
::chart::ChartModel* pModel = dynamic_cast<::chart::ChartModel*>(xModel.get()); |
| 576 |
assert(!xModel || pModel); |
| 577 |
doUpdateModel(pModel); |
| 578 |
} |
| 579 |
|
| 580 |
IMPL_LINK(ChartElementsPanel, CheckBoxHdl, weld::Toggleable&, rCheckBox, void) |
| 581 |
{ |
| 582 |
bool bChecked = rCheckBox.get_active(); |
| 583 |
if (&rCheckBox == mxCBTitle.get()) |
| 584 |
setTitleVisible(TitleHelper::MAIN_TITLE, bChecked); |
| 585 |
else if (&rCheckBox == mxCBSubtitle.get()) |
| 586 |
setTitleVisible(TitleHelper::SUB_TITLE, bChecked); |
| 587 |
else if (&rCheckBox == mxCBXAxis.get()) |
| 588 |
setAxisVisible(mxModel, AxisType::X_MAIN, bChecked); |
| 589 |
else if (&rCheckBox == mxCBXAxisTitle.get()) |
| 590 |
setTitleVisible(TitleHelper::X_AXIS_TITLE, bChecked); |
| 591 |
else if (&rCheckBox == mxCBYAxis.get()) |
| 592 |
setAxisVisible(mxModel, AxisType::Y_MAIN, bChecked); |
| 593 |
else if (&rCheckBox == mxCBYAxisTitle.get()) |
| 594 |
setTitleVisible(TitleHelper::Y_AXIS_TITLE, bChecked); |
| 595 |
else if (&rCheckBox == mxCBZAxis.get()) |
| 596 |
setAxisVisible(mxModel, AxisType::Z_MAIN, bChecked); |
| 597 |
else if (&rCheckBox == mxCBZAxisTitle.get()) |
| 598 |
setTitleVisible(TitleHelper::Z_AXIS_TITLE, bChecked); |
| 599 |
else if (&rCheckBox == mxCB2ndXAxis.get()) |
| 600 |
setAxisVisible(mxModel, AxisType::X_SECOND, bChecked); |
| 601 |
else if (&rCheckBox == mxCB2ndXAxisTitle.get()) |
| 602 |
setTitleVisible(TitleHelper::SECONDARY_X_AXIS_TITLE, bChecked); |
| 603 |
else if (&rCheckBox == mxCB2ndYAxis.get()) |
| 604 |
setAxisVisible(mxModel, AxisType::Y_SECOND, bChecked); |
| 605 |
else if (&rCheckBox == mxCB2ndYAxisTitle.get()) |
| 606 |
setTitleVisible(TitleHelper::SECONDARY_Y_AXIS_TITLE, bChecked); |
| 607 |
else if (&rCheckBox == mxCBLegend.get()) |
| 608 |
{ |
| 609 |
mxBoxLegend->set_sensitive(bChecked); |
| 610 |
mxCBLegendNoOverlay->set_sensitive(bChecked); |
| 611 |
setLegendVisible(mxModel, bChecked); |
| 612 |
} |
| 613 |
else if (&rCheckBox == mxCBLegendNoOverlay.get()) |
| 614 |
setLegendOverlay(mxModel, !bChecked); |
| 615 |
else if (&rCheckBox == mxCBGridVerticalMajor.get()) |
| 616 |
setGridVisible(mxModel, GridType::VERT_MAJOR, bChecked); |
| 617 |
else if (&rCheckBox == mxCBGridHorizontalMajor.get()) |
| 618 |
setGridVisible(mxModel, GridType::HOR_MAJOR, bChecked); |
| 619 |
else if (&rCheckBox == mxCBGridVerticalMinor.get()) |
| 620 |
setGridVisible(mxModel, GridType::VERT_MINOR, bChecked); |
| 621 |
else if (&rCheckBox == mxCBGridHorizontalMinor.get()) |
| 622 |
setGridVisible(mxModel, GridType::HOR_MINOR, bChecked); |
| 623 |
|
| 624 |
updateData(); |
| 625 |
} |
| 626 |
|
| 627 |
IMPL_LINK(ChartElementsPanel, EditHdl, weld::Entry&, rEdit, void) |
| 628 |
{ |
| 629 |
// title or subtitle? |
| 630 |
TitleHelper::eTitleType aTitleType = TitleHelper::MAIN_TITLE; |
| 631 |
if (&rEdit == mxEditSubtitle.get()) |
| 632 |
aTitleType = TitleHelper::SUB_TITLE; |
| 633 |
|
| 634 |
// set it |
| 635 |
OUString aText(rEdit.get_text()); |
| 636 |
TitleHelper::setCompleteString(aText, TitleHelper::getTitle(aTitleType, mxModel), |
| 637 |
comphelper::getProcessComponentContext(), nullptr, true); |
| 638 |
} |
| 639 |
|
| 640 |
IMPL_LINK_NOARG(ChartElementsPanel, LegendPosHdl, weld::ComboBox&, void) |
| 641 |
{ |
| 642 |
sal_Int32 nPos = mxLBLegendPosition->get_active(); |
| 643 |
setLegendPos(mxModel, nPos); |
| 644 |
} |
| 645 |
|
| 646 |
void ChartElementsPanel::setTitleVisible(TitleHelper::eTitleType eTitle, bool bVisible) |
| 647 |
{ |
| 648 |
if (bVisible) |
| 649 |
{ |
| 650 |
OUString aText = eTitle == TitleHelper::SUB_TITLE ? maTextSubTitle : maTextTitle; |
| 651 |
TitleHelper::createOrShowTitle(eTitle, aText, mxModel, comphelper::getProcessComponentContext()); |
| 652 |
} |
| 653 |
else |
| 654 |
{ |
| 655 |
TitleHelper::hideTitle(eTitle, mxModel); |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
} // end of namespace ::chart::sidebar |
| 660 |
|
| 661 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |