36#include <com/sun/star/chart2/XDataSeries.hpp>
37#include <com/sun/star/chart2/data/XDataProvider.hpp>
44using ::com::sun::star::uno::Reference;
49constexpr OUStringLiteral lcl_aLabelRole( u
"label" );
51void lcl_UpdateCurrentRange(
weld::TreeView& rOutListBox,
const OUString & rRole,
52 const OUString& rRange)
58 rOutListBox.
set_text(nEntry, rRange, 1);
75 pEntry->
m_xChartType->getRoleOfSequenceForSeriesLabel()));
78 rOutListBox.
set_text(nEntry, aLabel);
85OUString lcl_GetSelectedRole(
const weld::TreeView& rRoleListBox,
bool bUITranslated =
false)
91 return rRoleListBox.
get_text(nEntry);
98OUString lcl_GetSelectedRolesRange(
const weld::TreeView& rRoleListBox )
103 aResult = rRoleListBox.
get_text(nEntry, 1);
107OUString lcl_GetSequenceNameForLabel(const ::chart::SeriesEntry* pEntry)
109 OUString aResult(
"values-y");
110 if (pEntry && pEntry->m_xChartType.is())
111 aResult = pEntry->m_xChartType->getRoleOfSequenceForSeriesLabel();
124void lcl_addLSequenceToDataSource(
125 const uno::Reference< chart2::data::XLabeledDataSequence > & xLSequence,
126 const Reference< ::chart::DataSeries > & xSource )
130 std::vector< uno::Reference< chart2::data::XLabeledDataSequence > >
aData = xSource->getDataSequences2();
131 aData.push_back( xLSequence );
132 xSource->setData( aData );
139 uno::Reference< chart2::data::XLabeledDataSequence > xResult;
141 for( uno::Reference< chart2::data::XLabeledDataSequence >
const & labeledDataSeq : xDataSource->getDataSequences2() )
144 if( ! labeledDataSeq->getValues().is() &&
145 labeledDataSeq->getLabel().is())
147 xResult = labeledDataSeq;
163 bool bHideDescription )
164 : ::
vcl::OWizardPage(pPage, pController,
"modules/schart/ui/tp_DataSource.ui",
"tp_DataSource")
165 , m_pTemplateProvider(pTemplateProvider)
166 , m_rDialogModel(rDialogModel)
167 , m_pCurrentRangeChoosingField( nullptr )
168 , m_bIsDirty( false )
169 , m_pTabPageNotifiable(dynamic_cast<TabPageNotifiable*>(pController))
170 , m_xFT_CAPTION(m_xBuilder->weld_label(
"FT_CAPTION_FOR_WIZARD"))
171 , m_xFT_SERIES(m_xBuilder->weld_label(
"FT_SERIES"))
172 , m_xLB_SERIES(m_xBuilder->weld_tree_view(
"LB_SERIES"))
173 , m_xBTN_ADD(m_xBuilder->weld_button(
"BTN_ADD"))
174 , m_xBTN_REMOVE(m_xBuilder->weld_button(
"BTN_REMOVE"))
175 , m_xBTN_UP(m_xBuilder->weld_button(
"BTN_UP"))
176 , m_xBTN_DOWN(m_xBuilder->weld_button(
"BTN_DOWN"))
177 , m_xFT_ROLE(m_xBuilder->weld_label(
"FT_ROLE"))
178 , m_xLB_ROLE(m_xBuilder->weld_tree_view(
"LB_ROLE"))
179 , m_xFT_RANGE(m_xBuilder->weld_label(
"FT_RANGE"))
180 , m_xEDT_RANGE(m_xBuilder->weld_entry(
"EDT_RANGE"))
181 , m_xIMB_RANGE_MAIN(m_xBuilder->weld_button(
"IMB_RANGE_MAIN"))
182 , m_xFT_CATEGORIES(m_xBuilder->weld_label(
"FT_CATEGORIES"))
183 , m_xFT_DATALABELS(m_xBuilder->weld_label(
"FT_DATALABELS"))
184 , m_xEDT_CATEGORIES(m_xBuilder->weld_entry(
"EDT_CATEGORIES"))
185 , m_xIMB_RANGE_CAT(m_xBuilder->weld_button(
"IMB_RANGE_CAT"))
213 std::vector<int> aWidths { o3tl::narrowing<int>(
m_xLB_ROLE->get_approximate_digit_width() * 20) };
240 OWizardPage::Activate();
275 bool bIsValid = aRange.isEmpty() ||
283 bool bRoleRangeValid =
true;
284 bool bCategoriesRangeValid =
true;
285 bool bHasSelectedEntry = (
m_xLB_SERIES->get_selected_index() != -1);
287 if (bHasSelectedEntry)
291 bool bValid = ( bRoleRangeValid && bCategoriesRangeValid );
328 pEntry = weld::fromId<SeriesEntry*>(
m_xLB_SERIES->get_id(nEntry));
332 bool bHasSelectedEntry = (pEntry !=
nullptr);
333 int nSelectedEntry = -1;
338 std::vector< DialogModel::tSeriesWithChartTypeByName > aSeries(
341 sal_Int32 nUnnamedSeriesIndex = 1;
343 for (
auto const& series : aSeries)
345 OUString
aLabel(series.first);
348 if( nUnnamedSeriesIndex > 1 )
353 static constexpr OUStringLiteral aReplacementStr(
u"%NUMBER" );
354 sal_Int32
nIndex = aResString.indexOf( aReplacementStr );
356 aLabel = aResString.replaceAt(
357 nIndex, aReplacementStr.getLength(),
358 OUString::number(nUnnamedSeriesIndex));
363 ++nUnnamedSeriesIndex;
371 if (bHasSelectedEntry && series.second.first == xSelected)
372 nSelectedEntry = nEntry;
378 if (bHasSelectedEntry && nSelectedEntry != -1)
386 if (nSeriesEntry != -1)
387 pSeriesEntry = weld::fromId<SeriesEntry*>(
m_xLB_SERIES->get_id(nSeriesEntry));
388 bool bHasSelectedEntry = (pSeriesEntry !=
nullptr);
390 int nRoleIndex =
m_xLB_ROLE->get_selected_index();
391 if (!bHasSelectedEntry)
397 lcl_GetSequenceNameForLabel( pSeriesEntry ),
404 for (
auto const& elemRole : aRoles)
414 if (nRoleIndex == -1 || nRoleIndex >=
m_xLB_ROLE->n_children())
423 bool bHasSelectedSeries = nSeriesEntry != -1;
424 bool bHasValidRole =
false;
427 if( bHasSelectedSeries )
429 int nRoleEntry =
m_xLB_ROLE->get_selected_index();
430 bHasValidRole = nRoleEntry != -1;
436 m_xBTN_UP->set_sensitive(bHasSelectedSeries && (nSeriesEntry != 0));
443 bool bShowIB = bHasRangeChooser;
447 m_xFT_ROLE->set_sensitive(bHasSelectedSeries);
448 m_xLB_ROLE->set_sensitive(bHasSelectedSeries);
463 m_rDialogModel.startControllerLockTimer();
464 if (m_xLB_SERIES->get_selected_index() != -1)
467 RoleSelectionChangedHdl(*m_xLB_ROLE);
469 updateControlState();
474 m_rDialogModel.startControllerLockTimer();
475 int nEntry = m_xLB_ROLE->get_selected_index();
479 OUString aSelectedRoleUI = lcl_GetSelectedRole( *m_xLB_ROLE,
true );
480 OUString aSelectedRange = lcl_GetSelectedRolesRange( *m_xLB_ROLE );
483 static constexpr OUStringLiteral aReplacementStr(
u"%VALUETYPE" );
484 sal_Int32
nIndex = m_aFixedTextRange.indexOf( aReplacementStr );
487 m_xFT_RANGE->set_label(
488 m_aFixedTextRange.replaceAt(
489 nIndex, aReplacementStr.getLength(), aSelectedRoleUI ));
492 m_xEDT_RANGE->set_text(aSelectedRange);
498 OSL_ASSERT( m_pCurrentRangeChoosingField ==
nullptr );
499 m_pCurrentRangeChoosingField = m_xEDT_RANGE.get();
500 if (!m_xEDT_RANGE->get_text().isEmpty() &&
501 !updateModelFromControl( m_pCurrentRangeChoosingField))
504 int nEntry = m_xLB_SERIES->get_selected_index();
505 bool bHasSelectedEntry = (nEntry != -1);
507 OUString aSelectedRolesRange = lcl_GetSelectedRolesRange(*m_xLB_ROLE);
509 if (bHasSelectedEntry && (m_xLB_ROLE->get_selected_index() != -1))
511 OUString aUIStr(
SchResId(STR_DATA_SELECT_RANGE_FOR_SERIES));
514 OUString aReplacement(
"%VALUETYPE" );
515 sal_Int32
nIndex = aUIStr.indexOf( aReplacement );
518 aUIStr = aUIStr.replaceAt(
nIndex, aReplacement.getLength(),
519 lcl_GetSelectedRole( *m_xLB_ROLE,
true ));
522 aReplacement =
"%SERIESNAME";
523 nIndex = aUIStr.indexOf( aReplacement );
526 aUIStr = aUIStr.replaceAt(
nIndex, aReplacement.getLength(),
527 m_xLB_SERIES->get_text(nEntry));
530 lcl_enableRangeChoosing(
true, m_pDialogController);
531 m_rDialogModel.getRangeSelectionHelper()->chooseRange( aSelectedRolesRange, aUIStr, *
this );
534 m_pCurrentRangeChoosingField =
nullptr;
539 OSL_ASSERT( m_pCurrentRangeChoosingField ==
nullptr );
540 m_pCurrentRangeChoosingField = m_xEDT_CATEGORIES.get();
541 if( !m_xEDT_CATEGORIES->get_text().isEmpty() &&
542 ! updateModelFromControl( m_pCurrentRangeChoosingField ))
545 OUString
aStr(
SchResId(m_xFT_CATEGORIES->get_visible() ? STR_DATA_SELECT_RANGE_FOR_CATEGORIES : STR_DATA_SELECT_RANGE_FOR_DATALABELS));
546 lcl_enableRangeChoosing(
true, m_pDialogController);
547 m_rDialogModel.getRangeSelectionHelper()->chooseRange(
548 m_rDialogModel.getCategoriesRange(),
aStr, *
this );
553 m_rDialogModel.startControllerLockTimer();
554 int nEntry = m_xLB_SERIES->get_selected_index();
557 if( m_pTemplateProvider )
558 m_rDialogModel.setTemplate( m_pTemplateProvider->getCurrentTemplate());
562 ::chart::SeriesEntry* pEntry = weld::fromId<::chart::SeriesEntry*>(m_xLB_SERIES->get_id(nEntry));
568 std::vector< rtl::Reference< ChartType > > aCntVec(
569 m_rDialogModel.getAllDataSeriesContainers());
570 if( ! aCntVec.empty())
571 xChartTypeForNewSeries = aCntVec.front();
573 OSL_ENSURE( xChartTypeForNewSeries.is(),
"Cannot insert new series" );
575 m_rDialogModel.insertSeriesAfter( xSeriesToInsertAfter, xChartTypeForNewSeries );
581 int nSelEntry = m_xLB_SERIES->get_selected_index();
585 if (nSelEntry < m_xLB_SERIES->n_children())
586 m_xLB_SERIES->select(nSelEntry);
588 SeriesSelectionChangedHdl(*m_xLB_SERIES);
593 m_rDialogModel.startControllerLockTimer();
594 int nEntry = m_xLB_SERIES->get_selected_index();
598 SeriesEntry* pEntry = weld::fromId<::chart::SeriesEntry*>(m_xLB_SERIES->get_id(nEntry));
601 if (nEntry + 1 < m_xLB_SERIES->n_children())
602 pNewSelEntry = weld::fromId<::chart::SeriesEntry*>(m_xLB_SERIES->get_id(nEntry + 1));
604 pNewSelEntry = weld::fromId<::chart::SeriesEntry*>(m_xLB_SERIES->get_id(nEntry - 1));
611 m_xLB_SERIES->remove(nEntry);
615 if (xNewSelSeries.is())
617 for (
int i = 0;
i < m_xLB_SERIES->n_children(); ++
i)
619 pEntry = weld::fromId<::chart::SeriesEntry*>(m_xLB_SERIES->get_id(
i));
622 m_xLB_SERIES->select(
i);
627 SeriesSelectionChangedHdl(*m_xLB_SERIES);
632 m_rDialogModel.startControllerLockTimer();
634 int nEntry = m_xLB_SERIES->get_selected_index();
637 pEntry = weld::fromId<SeriesEntry*>(m_xLB_SERIES->get_id(nEntry));
639 bool bHasSelectedEntry = (pEntry !=
nullptr);
641 if (bHasSelectedEntry)
646 SeriesSelectionChangedHdl(*m_xLB_SERIES);
652 m_rDialogModel.startControllerLockTimer();
654 int nEntry = m_xLB_SERIES->get_selected_index();
657 pEntry = weld::fromId<SeriesEntry*>(m_xLB_SERIES->get_id(nEntry));
659 bool bHasSelectedEntry = (pEntry !=
nullptr);
661 if (bHasSelectedEntry)
666 SeriesSelectionChangedHdl(*m_xLB_SERIES);
673 if( isRangeFieldContentValid( rEdit ))
676 updateModelFromControl( &rEdit );
677 if (&rEdit == m_xEDT_RANGE.get())
679 if( ! lcl_UpdateCurrentSeriesName( *m_xLB_SERIES ))
689 const OUString & rNewRange )
692 OUString aRange( rNewRange );
741 bool bAll = (pField ==
nullptr);
747 if( xDataProvider.is())
750 if (!aRange.isEmpty())
753 if( !xLabeledSeq.is())
760 xLabeledSeq->setValues( xDataProvider->createDataSequenceByRangeRepresentation( aRange ));
762 catch(
const uno::Exception & )
768 else if( xLabeledSeq.is())
771 xLabeledSeq.set(
nullptr);
779 if (nSeriesEntry != -1)
780 pSeriesEntry = weld::fromId<SeriesEntry*>(
m_xLB_SERIES->get_id(nSeriesEntry));
781 bool bHasSelectedEntry = (pSeriesEntry !=
nullptr);
783 if( bHasSelectedEntry )
789 OUString aSelectedRole = lcl_GetSelectedRole( *
m_xLB_ROLE );
791 OUString aSequenceRole( aSelectedRole );
792 bool bIsLabel = (aSequenceRole == lcl_aLabelRole );
793 OUString aSequenceNameForLabel( lcl_GetSequenceNameForLabel( pSeriesEntry ));
796 aSequenceRole = aSequenceNameForLabel;
801 if( xDataProvider.is())
805 if( ! xLabeledSeq.is())
809 if( ! xLabeledSeq.is())
813 lcl_addLSequenceToDataSource( xLabeledSeq, pSeriesEntry->
m_xDataSeries );
816 if( xLabeledSeq.is())
818 if( !aRange.isEmpty())
823 xNewSeq.set( xDataProvider->createDataSequenceByRangeRepresentation( aRange ));
825 catch(
const uno::Exception & )
835 aRange = xNewSeq->getSourceRangeRepresentation();
837 xProp->setPropertyValue(
"Role" ,
uno::Any( OUString(lcl_aLabelRole) ));
840 xProp->setPropertyValue(
"IncludeHiddenCells",
uno::Any(
true));
841 xLabeledSeq->setLabel( xNewSeq );
852 if( !aRange.isEmpty())
857 xNewSeq.set( xDataProvider->createDataSequenceByRangeRepresentation( aRange ));
859 catch(
const uno::Exception & )
869 aRange = xNewSeq->getSourceRangeRepresentation();
872 xProp->setPropertyValue(
"Role" ,
uno::Any( aSelectedRole ));
873 if( !xLabeledSeq.is())
875 if( aSelectedRole == aSequenceNameForLabel )
877 if( ! xLabeledSeq.is())
880 lcl_addLSequenceToDataSource( xLabeledSeq, pSeriesEntry->
m_xDataSeries );
883 xLabeledSeq->setValues( xNewSeq );
889 lcl_UpdateCurrentRange( *
m_xLB_ROLE, aSelectedRole, aRange );
891 catch(
const uno::Exception & )
913 catch(
const uno::Exception & )
void SetPageTitle(const OUString &rPageTitle)
virtual void Deactivate()
weld::DialogController * m_pDialogController
This guard calls lockControllers at the given Model in the CTOR and unlockControllers in the DTOR.
static rtl::Reference< LabeledDataSequence > createLabeledDataSequence()
bool isRangeFieldContentValid(weld::Entry &rEdit)
std::unique_ptr< weld::Label > m_xFT_SERIES
TabPageNotifiable * m_pTabPageNotifiable
virtual void initializePage() override
virtual void listeningFinished(const OUString &rNewRange) override
void updateControlsFromDialogModel()
std::unique_ptr< weld::Label > m_xFT_CAPTION
std::unique_ptr< weld::Button > m_xBTN_UP
std::unique_ptr< weld::Button > m_xBTN_REMOVE
std::unique_ptr< weld::TreeView > m_xLB_SERIES
DialogModel & m_rDialogModel
std::unique_ptr< weld::Button > m_xBTN_ADD
std::unique_ptr< weld::Label > m_xFT_RANGE
std::unique_ptr< weld::Entry > m_xEDT_CATEGORIES
std::unique_ptr< weld::Entry > m_xEDT_RANGE
bool updateModelFromControl(const weld::Entry *pField=nullptr)
updates the internal data according to the content of the given edit field.
std::unique_ptr< weld::Button > m_xIMB_RANGE_MAIN
std::unique_ptr< weld::Label > m_xFT_CATEGORIES
std::vector< std::unique_ptr< SeriesEntry > > m_aEntries
std::unique_ptr< weld::Button > m_xBTN_DOWN
virtual void Deactivate() override
weld::Entry * m_pCurrentRangeChoosingField
std::unique_ptr< weld::Label > m_xFT_DATALABELS
virtual void Activate() override
OUString m_aFixedTextRange
std::unique_ptr< weld::Button > m_xIMB_RANGE_CAT
std::unique_ptr< weld::Label > m_xFT_ROLE
DataSourceTabPage(weld::Container *pPage, weld::DialogController *pController, DialogModel &rDialogModel, ChartTypeTemplateProvider *pTemplateProvider, bool bHideDescription=false)
void updateControlState()
virtual void disposingRangeSelection() override
virtual ~DataSourceTabPage() override
void InsertRoleLBEntry(const OUString &rRole, const OUString &rRange)
std::unique_ptr< weld::TreeView > m_xLB_ROLE
const rtl::Reference<::chart::ChartModel > & getChartModel() const
bool isCategoryDiagram() const
void setCategories(const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xCategories)
std::vector< tSeriesWithChartTypeByName > getAllDataSeriesWithLabel() const
void setTimeBasedRange(bool bTimeBased, sal_Int32 nStart, sal_Int32 nEnd) const
std::map< OUString, OUString > tRolesWithRanges
css::uno::Reference< css::chart2::data::XDataProvider > getDataProvider() const
static OUString ConvertRoleFromInternalToUI(const OUString &rRoleString)
std::shared_ptr< RangeSelectionHelper > const & getRangeSelectionHelper() const
void startControllerLockTimer()
css::uno::Reference< css::chart2::data::XLabeledDataSequence > getCategories() const
static tRolesWithRanges getRolesWithRanges(const css::uno::Reference< css::chart2::XDataSeries > &xSeries, const OUString &aRoleOfSequenceForLabel, const rtl::Reference< ::chart::ChartType > &xChartType)
const DialogModelTimeBasedInfo & getTimeBasedInfo() const
OUString getCategoriesRange() const
rtl::Reference< ::chart::ChartType > m_xChartType
the chart type that contains the series (via XDataSeriesContainer)
rtl::Reference< ::chart::DataSeries > m_xDataSeries
the corresponding data series
virtual Dialog * getDialog()=0
virtual void set_text(const OUString &rText)=0
virtual void set_message_type(EntryMessageType eType)=0
virtual OUString get_text() const=0
virtual void set_text(int row, const OUString &rText, int col=-1)=0
virtual OUString get_text(int row, int col=-1) const=0
virtual int get_selected_index() const=0
virtual OUString get_id(int pos) const=0
virtual void set_modal(bool bModal)=0
#define DBG_UNHANDLED_EXCEPTION(...)
#define LINK(Instance, Class, Member)
constexpr OUStringLiteral aData
OOO_DLLPUBLIC_CHARTTOOLS css::uno::Reference< css::chart2::data::XLabeledDataSequence > getDataSequenceByRole(const css::uno::Reference< css::chart2::data::XDataSource > &xSource, const OUString &aRole, bool bMatchPrefix=false)
Retrieves the data sequence in the given data source that matches the given role.
static Reference< chart2::data::XLabeledDataSequence > lcl_findLSequenceWithOnlyLabel(const Sequence< Reference< chart2::data::XLabeledDataSequence > > &rDataSequences)
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
IMPL_LINK(StackingResourceGroup, StackingChangeHdl, weld::Toggleable &, rRadio, void)
IMPL_LINK_NOARG(SplinePropertiesDialog, SplineTypeListBoxHdl, weld::ComboBox &, void)
OUString toId(const void *pValue)