Files
loongoffice/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx
Tomaž Vajngerl 9009663deb tdf#83257 [API-CHANGE] Pivot chart implementation
This is a squashed commit of the pivot chart implementation.

Some of the changes:
- Add pivot chart specific (pivot table) data provider which
  provides the data from a pivot table to the associated chart.
- When inserting a chart and the cursor is in a pivot table,
  in that case insert a pivot chart
- Modify the pivot chart when the pivot table changes
- Collect and set the number format for the values
- isDataFromSpreadsheet check for the creation wizard
- In ChartView (and VLegend) check if the data provider is a
  pivot chart data provider and get the pivot table field names
  to create the buttons on the UI.
- Adds the functionallity to show a filter pop-up (from calc)
  when clicking on row / column / page field buttons.
- Remove (X)PopupRequest as we won't need it.
- Add ODF import/export for pivot charts:
  + Added loext:data-pilot-source attribute on chart:chart
    which is the internal name of the pivot table with which the
    pivot chart is associated with. If the element is present, then
    the it means the chart is a pivot chart, else it is a normal
    chart
  + Added service to create pivot chart data provider through UNO
  + Add new methods to XPivotChartDataProvider to create value and
    label data sequences separately from the data source, which is
    needed for pivot chart import
  + When importing defer setting the data provider until a later
    time when we know if we are creating a chart od a pivot chart
- Pivot chart ODF round-trip test
- Add table pivot chart supplier API:
  This adds the XTablePivotChartSupplier and related interfaces so
  we can access, create, delete pivot charts from UNO in a sheet
  document. With this we now distinguish between normal charts
  and pivot charts. This was mainly needed because we can't extend
  the "published" interfaces of TableChartSupplier.
- Added an extensive test, which uses the API to create a new
  pivot chart when there was none, and checks that the pivot chart
  updates when the pivot table updates.

Change-Id: Ia9ed96fd6b1d342e61c2f7f9fa33a5e03dda21af
Reviewed-on: https://gerrit.libreoffice.org/36023
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
2017-04-04 13:39:29 +00:00

388 lines
13 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "DrawViewWrapper.hxx"
#include "chartview/DrawModelWrapper.hxx"
#include "ConfigurationAccess.hxx"
#include "macros.hxx"
#include <unotools/lingucfg.hxx>
#include <editeng/langitem.hxx>
#include <svl/itempool.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdmodel.hxx>
#include <svx/scene3d.hxx>
#include <svx/svdetc.hxx>
#include <svx/svdoutl.hxx>
#include <svx/svxids.hrc>
#include <svx/unoshape.hxx>
#include <tools/globname.hxx>
#include <editeng/fhgtitem.hxx>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <sfx2/objsh.hxx>
#include <svx/helperhittest3d.hxx>
using namespace ::com::sun::star;
namespace chart
{
namespace
{
short lcl_getHitTolerance( OutputDevice* pOutDev )
{
const short HITPIX=2; //hit-tolerance in pixel
short nHitTolerance = 50;
if(pOutDev)
nHitTolerance = static_cast<short>(pOutDev->PixelToLogic(Size(HITPIX,0)).Width());
return nHitTolerance;
}
// this code is copied from sfx2/source/doc/objembed.cxx
SfxObjectShell * lcl_GetParentObjectShell( const uno::Reference< frame::XModel > & xModel )
{
SfxObjectShell* pResult = nullptr;
try
{
uno::Reference< container::XChild > xChildModel( xModel, uno::UNO_QUERY );
if ( xChildModel.is() )
{
uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
if ( xParentTunnel.is() )
{
SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
pResult = reinterpret_cast< SfxObjectShell * >(
xParentTunnel->getSomething( uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
}
}
}
catch( const uno::Exception& )
{
// TODO: error handling
}
return pResult;
}
// this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
// get the reference device (e.g. printer) fromthe parent document
OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel )
{
SfxObjectShell * pParent = lcl_GetParentObjectShell( xModel );
if ( pParent )
return pParent->GetDocumentRefDev();
return nullptr;
}
}
DrawViewWrapper::DrawViewWrapper( SdrModel* pSdrModel, OutputDevice* pOut)
: E3dView(pSdrModel, pOut)
, m_pMarkHandleProvider(nullptr)
, m_apOutliner(SdrMakeOutliner(OutlinerMode::TextObject, *pSdrModel))
, m_bRestoreMapMode( false )
{
SetBufferedOutputAllowed(true);
SetBufferedOverlayAllowed(true);
SetPagePaintingAllowed(true);
// #i12587# support for shapes in chart
SdrOutliner* pOutliner = getOutliner();
SfxItemPool* pOutlinerPool = ( pOutliner ? pOutliner->GetEditTextObjectPool() : nullptr );
if ( pOutlinerPool )
{
SvtLinguConfig aLinguConfig;
SvtLinguOptions aLinguOptions;
if ( aLinguConfig.GetOptions( aLinguOptions ) )
{
pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
}
// set font height without changing SdrEngineDefaults
pOutlinerPool->SetPoolDefaultItem( SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ) ); // 12pt
}
// #i121463# Use big handles by default
SetMarkHdlSizePixel(9);
ReInit();
}
void DrawViewWrapper::ReInit()
{
OutputDevice* pOutDev = this->GetFirstOutputDevice();
Size aOutputSize(100,100);
if(pOutDev)
aOutputSize = pOutDev->GetOutputSize();
mbPageVisible = false;
mbPageBorderVisible = false;
mbBordVisible = false;
mbGridVisible = false;
mbHlplVisible = false;
this->SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object)
//a correct work area is at least necessary for correct values in the position and size dialog
tools::Rectangle aRect(Point(0,0), aOutputSize);
this->SetWorkArea(aRect);
this->ShowSdrPage(this->GetModel()->GetPage(0));
}
DrawViewWrapper::~DrawViewWrapper()
{
maComeBackIdle.Stop();//@todo this should be done in destructor of base class
UnmarkAllObj();//necessary to avoid a paint call during the destructor hierarchy
}
SdrPageView* DrawViewWrapper::GetPageView() const
{
SdrPageView* pSdrPageView = this->GetSdrPageView();
return pSdrPageView;
};
void DrawViewWrapper::SetMarkHandles(SfxViewShell* pOtherShell)
{
if( m_pMarkHandleProvider && m_pMarkHandleProvider->getMarkHandles( maHdlList ) )
return;
else
SdrView::SetMarkHandles(pOtherShell);
}
SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const
{
SdrSearchOptions nOptions = SdrSearchOptions::DEEP | SdrSearchOptions::TESTMARKABLE;
SdrPageView* pSdrPageView = this->GetPageView();
SdrObject* pRet = this->SdrView::PickObj(rPnt, lcl_getHitTolerance( this->GetFirstOutputDevice() ), pSdrPageView, nOptions);
if( pRet )
{
// ignore some special shapes
OUString aShapeName = pRet->GetName();
// return right away if it is a field button
if (aShapeName.startsWith("FieldButton"))
return pRet;
if( aShapeName.match("PlotAreaIncludingAxes") || aShapeName.match("PlotAreaExcludingAxes") )
{
pRet->SetMarkProtect( true );
return getHitObject( rPnt );
}
//3d objects need a special treatment
//because the simple PickObj method is not accurate in this case for performance reasons
E3dObject* pE3d = dynamic_cast< E3dObject* >(pRet);
if( pE3d )
{
E3dScene* pScene = pE3d->GetScene();
if( pScene )
{
// prepare result vector and call helper
std::vector< const E3dCompoundObject* > aHitList;
const basegfx::B2DPoint aHitPoint(rPnt.X(), rPnt.Y());
getAllHit3DObjectsSortedFrontToBack(aHitPoint, *pScene, aHitList);
if(!aHitList.empty())
{
// choose the frontmost hit 3D object of the scene
pRet = const_cast< E3dCompoundObject* >(aHitList[0]);
}
}
}
}
return pRet;
}
void DrawViewWrapper::MarkObject( SdrObject* pObj )
{
bool bFrameDragSingles = true;//true == green == surrounding handles
if(pObj)
pObj->SetMarkProtect(false);
if( m_pMarkHandleProvider )
bFrameDragSingles = m_pMarkHandleProvider->getFrameDragSingles();
this->SetFrameDragSingles(bFrameDragSingles);//decide whether each single object should get handles
this->SdrView::MarkObj( pObj, this->GetPageView() );
this->showMarkHandles();
}
void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider* pMarkHandleProvider )
{
m_pMarkHandleProvider = pMarkHandleProvider;
}
void DrawViewWrapper::CompleteRedraw(OutputDevice* pOut, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* /* pRedirector */)
{
svtools::ColorConfig aColorConfig;
Color aFillColor( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
this->SetApplicationBackgroundColor(aFillColor);
this->E3dView::CompleteRedraw( pOut, rReg );
}
SdrObject* DrawViewWrapper::getSelectedObject() const
{
SdrObject* pObj(nullptr);
const SdrMarkList& rMarkList = this->GetMarkedObjectList();
if(rMarkList.GetMarkCount() == 1)
{
SdrMark* pMark = rMarkList.GetMark(0);
pObj = pMark->GetMarkedSdrObj();
}
return pObj;
}
SdrObject* DrawViewWrapper::getTextEditObject() const
{
SdrObject* pObj = this->getSelectedObject();
SdrObject* pTextObj = nullptr;
if( pObj && pObj->HasTextEdit())
pTextObj = static_cast<SdrTextObj*>(pObj);
return pTextObj;
}
void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel )
{
OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel ));
SdrOutliner * pOutliner( getOutliner());
if( pParentRefDev && pOutliner )
{
pOutliner->SetRefDevice( pParentRefDev );
}
}
SdrOutliner* DrawViewWrapper::getOutliner() const
{
return m_apOutliner.get();
}
SfxItemSet DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const
{
SfxItemSet aFullSet( GetModel()->GetItemPool(),
SID_ATTR_TRANSFORM_POS_X, SID_ATTR_TRANSFORM_ANGLE,
SID_ATTR_TRANSFORM_PROTECT_POS, SID_ATTR_TRANSFORM_AUTOHEIGHT,
SDRATTR_ECKENRADIUS, SDRATTR_ECKENRADIUS,
SID_ATTR_METRIC, SID_ATTR_METRIC,
0);
SfxItemSet aGeoSet( E3dView::GetGeoAttrFromMarked() );
aFullSet.Put( aGeoSet );
aFullSet.Put( SfxUInt16Item(SID_ATTR_METRIC,static_cast< sal_uInt16 >( ConfigurationAccess::getFieldUnit())));
return aFullSet;
}
SdrObject* DrawViewWrapper::getNamedSdrObject( const OUString& rName ) const
{
if(rName.isEmpty())
return nullptr;
SdrPageView* pSdrPageView = this->GetPageView();
if( pSdrPageView )
{
return DrawModelWrapper::getNamedSdrObject( rName, pSdrPageView->GetObjList() );
}
return nullptr;
}
bool DrawViewWrapper::IsObjectHit( SdrObject* pObj, const Point& rPnt )
{
if(pObj)
{
tools::Rectangle aRect(pObj->GetCurrentBoundRect());
return aRect.IsInside(rPnt);
}
return false;
}
void DrawViewWrapper::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
{
//prevent wrong reselection of objects
SdrModel* pSdrModel( this->GetModel() );
if( pSdrModel && pSdrModel->isLocked() )
return;
const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
//#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created )
SdrPageView* pSdrPageView = this->GetPageView();
if( pSdrHint && pSdrPageView )
{
if( pSdrPageView->GetPage() != pSdrHint->GetPage() )
return;
}
E3dView::Notify(rBC, rHint);
if( pSdrHint != nullptr )
{
SdrHintKind eKind = pSdrHint->GetKind();
if( eKind == SdrHintKind::BeginEdit )
{
// #i79965# remember map mode
OSL_ASSERT( ! m_bRestoreMapMode );
OutputDevice* pOutDev = this->GetFirstOutputDevice();
if( pOutDev )
{
m_aMapModeToRestore = pOutDev->GetMapMode();
m_bRestoreMapMode = true;
}
}
else if( eKind == SdrHintKind::EndEdit )
{
// #i79965# scroll back view when ending text edit
OSL_ASSERT( m_bRestoreMapMode );
if( m_bRestoreMapMode )
{
OutputDevice* pOutDev = this->GetFirstOutputDevice();
if( pOutDev )
{
pOutDev->SetMapMode( m_aMapModeToRestore );
m_bRestoreMapMode = false;
}
}
}
}
}
SdrObject* DrawViewWrapper::getSdrObject( const uno::Reference<
drawing::XShape >& xShape )
{
SdrObject* pRet = nullptr;
uno::Reference< lang::XUnoTunnel > xUnoTunnel( xShape, uno::UNO_QUERY );
uno::Reference< lang::XTypeProvider > xTypeProvider( xShape, uno::UNO_QUERY );
if(xUnoTunnel.is()&&xTypeProvider.is())
{
SvxShape* pSvxShape = reinterpret_cast<SvxShape*>(xUnoTunnel->getSomething( SvxShape::getUnoTunnelId() ));
if(pSvxShape)
pRet = pSvxShape->GetSdrObject();
}
return pRet;
}
} //namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */