Bug 87111 - Add warning about data loss when creating pivot table and deleting data source
Summary: Add warning about data loss when creating pivot table and deleting data source
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: Other All
: highest major
Assignee: abhilash300singh
URL:
Whiteboard: target:5.4.0
Keywords: difficultyInteresting, easyHack, skillCpp
Depends on:
Blocks: Pivot-Table
  Show dependency treegraph
 
Reported: 2014-12-08 17:40 UTC by raal
Modified: 2017-02-14 08:58 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
It's now fixed in master. See screenshot. (22.99 KB, image/png)
2017-01-09 09:29 UTC, Kevin Suo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description raal 2014-12-08 17:40:26 UTC
Inherited from bug 79332. According to comment 22 new bug - Add warning about data loss when creating pivot table and deleting data source

How to reproduce

Create pivot table on new sheet
Delete Sheet1 (sheet with data).  --> *add warning here*
Save file.
	You can filter in pivot table, data are in the pivot cache.
Close file.
Open File
Pivot table broken
Comment 1 Robinson Tryon (qubit) 2014-12-08 18:23:01 UTC
(In reply to raal from comment #0)
> How to reproduce
> Create pivot table on new sheet
> Delete Sheet1 (sheet with data).  --> *add warning here*
> Save file.
> 	You can filter in pivot table, data are in the pivot cache.
> Close file.
> Open File
> Pivot table broken

CONFIRMED with LO 4.4.0.0.beta2 + Ubuntu 14.04.

Pivot table is broken after reopening file.

Bug 79332 was marked as a MAB due to potential for data loss. As such, I'll add this back to mab4.3 and increase the priority; it would behoove us to look at the broader category of all generated data in Calc (pivot tables, charts, etc..) and warn users if they delete required data.

Status -> NEW
Comment 2 Michael Meeks 2016-05-01 13:27:42 UTC
The warning on sheet deletion is here:

sc/source/ui/view/tabvwshf.cxx:

                    // no parameter given, ask for confirmation
                    bDoIt = ( RET_YES ==
                              ScopedVclPtr<QueryBox>::Create( GetDialogParent(),
                                        WinBits( WB_YES_NO | WB_DEF_YES ),
                                        ScGlobal::GetRscString(STR_QUERY_DELTAB)
                                  )->Execute() );

And I imagine we need a more complex dialog here that will mention that if there are pivot tables pointing to these sheets (in TheTabs) - and we should build the list of TheTabs before prompting instead of after as we do now.

Then we should warn harder =)
Comment 3 Michael Meeks 2016-05-01 13:43:14 UTC
To find all the pivot tables use:

sc/inc/document.hxx (ScDocument)'s:

    SC_DLLPUBLIC ScDPCollection*       GetDPCollection();

sc/inc/dpobject.hxx (ScDPCollection): -> a list of Pivot Tables (Data Pilot)
    ultimately this:

    typedef std::vector< std::unique_ptr<ScDPObject> > TablesType;
    TablesType maTables;

Where a 'ScDPObject' - is really a Pivot Table.

So we need to find all of the sheets that may reference us in this case - by poking at ScDPObjects ...

Quite probably this:

    const ScSheetSourceDesc* GetSheetDesc() const   { return pSheetDesc; }

Tells us about the source ranges this comes from.

This is defined in:

sc/inc/dpshttab.hxx

Which has:

SC_DLLPUBLIC const ScRange& GetSourceRange() const;

sc/inc/address.hxx:

//  ScRange
class ScRange
{
public:
    ScAddress aStart;
    ScAddress aEnd;


class ScAddress
{
private:
    SCROW   nRow;
    SCCOL   nCol;
    SCTAB   nTab;

=)

Beware: a source range can be 3D - ie. it can span rows, columns -and- sheets =)

Thanks !
Comment 4 jani 2016-05-02 12:42:02 UTC
Converted to easyhacks as discussed pr email
Comment 5 Commit Notification 2017-01-03 13:29:06 UTC
Abhilash Singh committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=65d10c4dedbf72f87888e14984393c222a5b31f9

tdf#87111 Warn about data loss when deleting source data of pivot table

It will be available in 5.4.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 jani 2017-01-09 08:53:36 UTC
Seems solved
Comment 7 Kevin Suo 2017-01-09 09:29:16 UTC
Created attachment 130274 [details]
It's now fixed in master. See screenshot.

Confirm fixed in
Version: 5.4.0.0.alpha0+
Build ID: d1bad9c12d61c9f662abe6439b87a057bb54c8ca
CPU Threads: 4; OS Version: Linux 4.4; UI Render: default; VCL: gtk3; 
Locale: zh-CN (zh_CN.UTF-8); Calc: group