Commit Graph

95 Commits

Author SHA1 Message Date
Benjamin Nauck
a2c980f7d6 Revert "Address the poor performance of the existing unique-name generation (#17944)"
This reverts commit 83202d8ad6.

# Conflicts:
#	src/Base/Tools.cpp
#	src/Base/Tools.h
2024-12-16 17:31:43 +01:00
Kevin Martin
83202d8ad6 Address the poor performance of the existing unique-name generation (#17944)
* Address the poor performance of the existing unique-name generation

As described in Issue 16849, the existing Tools::getUniqueName method
requires calling code to form a vector of existing names to be avoided.

This leads to poor performance both in the O(n) cost of building such a
vector and also getUniqueName's O(n) algorithm for actually generating
the unique name (where 'n' is the number of pre-existing names).

This has  particularly noticeable cost in documents with large numbers
of DocumentObjects because generating both Names and Labels for each new
object incurs this cost. During an operation such as importing this
results in an O(n^2) time spent generating names.

The other major cost is in the saving of the temporary backup file,
which uses name generation for the "files" embedded in the Zip file.
Documents can easily need several such "files" for each object in the
document.

This update includes the following changes:

Create UniqueNameManager to keep a list of existing names organized in
a manner that eases unique-name generation. This class essentially acts
as a set of names, with the ability to add and remove names and check if
a name is already there, with the added ability to take a prototype name
and generate a unique form for it which is not already in the set.

Eliminate Tools::getUniqueName

Make DocumentObject naming use the new UniqueNameManager class

Make DocumentObject Label naming use the new UniqueNameManager class.
Labels are not always unique; unique labels are generated if the
settings at the time request it (and other conditions). Because of this
the Label management requires additionally keeping a map of counts
for labels which already exist more than once.
These collections are maintained via notifications of value changes on
the Label properties of the objects in the document.

Add Document::containsObject(DocumentObject*) for a definitive
test of an object being in a Document. This is needed because
DocumentObjects can be in a sort of limbo (e.g. when they are in the
Undo/Redo lists) where they have a parent linkage to the Document but
should not participate in Label collision checks.

Rename Document.getStandardObjectName to getStandardObjectLabel
to better represent what it does.

Use new UniqueNameManager for Writer internal filenames within the zip
file.

Eliminate unneeded Reader::FileNames collection. The file names
already exist in the FileList collection elements. The only existing
use for the FileNames collection was to determine if there were any
files at all, and with FileList and FileNames being parallel
vectors, they both had the same length so FileList could be used
for this test..

Use UniqueNameManager for document names and labels. This uses ad hoc
UniqueNameManager objects created on the spot on the assumption that
document creation is relatively rare and there are few documents, so
although the cost is O(n), n itself is small.

Use an ad hoc UniqueNameManager to name new DymanicProperty entries.
This is only done if a property of the proposed name already exists,
since such a check is more-or-less O(log(n)), almost never finds a
collision, and avoids the O(n) building of the UniqueNameManager.
If there is a collision an ad-hoc UniqueNameManager is built
and discarded after use.
The property management classes have a bit of a mess of methods
including several to populate various collection types with all
existing properties. Rather than introducing yet another such
collection-specific method to fill a UniqueNameManager, a
visitProperties method was added which calls a passed function for
each property. The existing code would be simpler if existing
fill-container methods all used this.
Ideally the PropertyContainer class would keep a central directory of
all properties ("static", Dynamic, and exposed by ExtensionContainer and
other derivations) and a permanent UniqueNameManager. However the
Property management is a bit of a mess making such a change a project
unto itself.

The unit tests for Tools:getUniqueName have been changed to test
UniqueNameManager.makeUniqueName instead.
This revealed a small regression insofar as passing a prototype name
like "xyz1234" to the old code would yield "xyz1235" whether or
not "xyz1234" already existed, while the new code will return the next
name above the currently-highest name on the "xyz" model, which could
be "xyz" or "xyz1".

* Correct wrong case on include path

* Implement suggested code changes
Also change the semantics of visitProperties to not have any short-circuit return

* Remove reference through undefined iterator

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix up some comments for DOxygen

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-12-13 10:54:46 -06:00
Chris Hennes
cdf6af935e Merge pull request #17315 from mwganson/ssclearall
[Spreadsheet] avoid removing user dynamic properties when clearing ce…
2024-12-06 11:57:45 -05:00
Ladislav Michl
0ee3c9f8e6 Base: Drop QString-std::string conversion functions from Tools
Convenience helpers function Tools::toStdString and Tools::fromStdString
were implemented for Qt4 or older to perform utf8 aware conversion as
QString::toStdString/QString::fromStdString were using toAscii/fromAscii
internally (see https://dreamswork.github.io/qt4/classQString.html).

Since Qt5 QString uses toUtf8/fromUTf8, which makes the helper functions
obsolete (see https://doc.qt.io/qt-5/qstring.html#fromStdString).
2024-12-02 23:30:53 -05:00
mwganson
7d378a7cf5 [Spreadsheet] avoid removing user dynamic properties when clearing cells, addresses issue #8655 2024-11-03 23:03:04 +00:00
H. Tsubota
4ce0f19c4f Change to enclose field values ​​with quotation character in exported CSV file if they contain delimiters in Spreadsheet workbench (#17140)
* Change to enclose field values ​​with quotation character in exported CSV file if they contain delimiters

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-10-14 17:52:38 +02:00
wmayer
f5a87bc620 Spreadsheet: Fix SheetPython::getViewProviderName() to return the correct type name
For more details see: https://forum.freecad.org/viewtopic.php?t=88642
2024-07-04 22:21:03 +02:00
PaddleStroke
3fa0b68878 Assembly: Implement Bill Of Materials (#14198)
* Assembly: Implementation of BOM

* Assembly: BOM: make it possible for BOM to be made without an assembly.
2024-06-17 11:16:32 -05:00
pre-commit-ci[bot]
222a2520b1 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2023-09-12 13:02:35 -04:00
wmayer
159525084d Sheet: Apply clang format 2023-09-10 16:01:37 +02:00
wmayer
e541c7d3dd Sheet: modernize C++: return braced init list 2023-08-19 11:35:41 +02:00
wmayer
a49e104993 Sheet: modernize C++: use range-based for loop 2023-08-15 20:21:20 +02:00
wmayer
0af4990817 modernize C++: make unique 2023-08-07 19:51:30 -06:00
wmayer
ca84a0662d Sheet: modernize C++: redundant void arg 2023-08-05 16:50:31 +02:00
0penBrain
719339657d Sheet: display an error in console when a cyclic dependency is detected 2023-05-17 10:09:41 +02:00
Chris Hennes
51eb8ed813 Spreadsheet: Fix unintended copies 2023-02-27 15:58:32 -06:00
luz paz
219d1edd6a Spreadsheet: [skip ci] fix doxygen typo 2022-10-25 23:54:35 +02:00
Zheng, Lei
05e0aba701 Spreadsheet: fix cell span synchronization with SheetTableView
Also, allow merge cell with overlaps, by auto split overlapped cells
first
2022-10-20 16:03:20 -05:00
Uwe
2d50fd36df [Spread] remove unused includes
- also sort includes
- also additions to precompiled header
2022-10-09 20:31:31 +02:00
wmayer
c3279b82b4 Mod: modernize C++: replace 'typedef' with 'using' 2022-08-29 23:21:15 +02:00
wmayer
5014bab534 Mod: replace std::ifstream/std::ofstream with Base::ifstream/Base::ofstream 2022-08-21 12:46:53 +02:00
berniev
da9ebc572f Mod: redundant void 2 2022-08-08 10:27:50 +02:00
wmayer
f2cbd9ebb4 Mod: [skip ci] minor improvements 2022-08-06 20:32:37 +02:00
Uwe
6f9a4ebc7f [App] [Spreadsheet] fix compilation errors
- introduced by #7318 and #7319
2022-08-06 19:59:06 +02:00
berniev
b796a0d376 Mod: use empty 2022-08-06 19:30:13 +02:00
Uwe
88a06f8f10 Mod: remove some unnecessary nullptr checks 2022-07-18 12:58:12 +02:00
Uwe
5d76afe0a5 re-add some nullptr
to be safe since their removal within assert() or bools might have some impact I don't know
2022-07-18 02:32:36 +02:00
Uwe
ce86b03e0a [Spreadsheet] remove superfluous nullptr checks 2022-07-18 01:49:41 +02:00
Zheng, Lei
75546946db Spreadsheet: fix border rendering for merged cells 2022-06-12 16:11:59 +02:00
Zheng Lei
9d7b7af48c Spreadsheet: fix range checking (#6997)
* App: add option to normalize a Range

- To make sure the range starts from top left and ends with bottom right
corner.
- Default is to not normalize on construction for backward compatibility.
-  fix range checking in range binding
2022-06-09 12:20:08 +02:00
Zheng Lei
5864e17d9d Spreadsheet: improve range binding feature (#6995)
* Spreadsheet: improve range binding feature
2022-06-08 19:19:41 +02:00
Zheng, Lei
ef2db349f8 Spreadsheet: fix cell clearing 2022-05-09 10:25:49 +02:00
Zheng, Lei
6d6af2dd3b Spreadsheet: add new API PropertySheet::getNonEmptyCells()
To exclude cells without any text content. Used when printing (among
other cases) to skip empty cells.
2022-05-06 08:40:11 -05:00
Zheng, Lei
5ec19fc5a1 Reduce debug log output 2022-04-23 16:21:49 +02:00
Zheng, Lei
f8ae185c15 Spreadsheet: improve efficiency when pasting many cells 2022-04-22 12:28:56 -05:00
Zheng, Lei
070bdf5b4c Spreadsheet: do not create string property for empty cell
Otherwise may cause massive slow down when, for example, the user
changes the entire row/column color, which results in large amount of
empty cells.
2022-04-22 12:28:56 -05:00
Zheng, Lei
8d97b2bcb8 Spreadsheet: fix owner property reference in PropertySheet
PropertySheet used to only work when refereceing its own cell either
through cell address or alias. It does not work for reference to other
property of the owner Spreadsheet object.
2022-03-26 10:19:20 -04:00
wmayer
2c229d3bc0 Spreadsheet: modernize C++11
* use nullptr
2022-03-23 19:26:14 +01:00
wmayer
26f9e7869f App: replace three boolean of CellAddress::toString() with a bitmask of enums 2022-01-09 10:39:54 +01:00
Zheng, Lei
0029f3206d Spreadsheet: improve copy/cut/paste cells
Add color bound around user copy/cut ranges. Do not touch Spreadsheet
object when cutting, only do so when pasting.
2021-12-21 21:41:02 -07:00
Zheng, Lei
caa29060cf Spreadsheet: fix handling of absolute cell address 2021-12-21 21:41:02 -07:00
Zheng, Lei
2a3951ca32 Spreadsheet: change alias handling
No longer add dynamic property for alias, simply rely on
get(Dynamic)PropertyByName() to check for aliases.

Add new API PropertyContainer::getPropertyNamedList() so that
ExpressionCompleter can discover properties with aliases.
2021-12-21 21:41:02 -07:00
Zheng, Lei
68fca40983 Spreadsheet: support cell binding
Cell binding allows one to bind a range of cells of one sheet to another
range of cells of an arbitary sheet, including any empty cells in the
range.

The binding is implemented with PropertyExpressionEngine and
PropertySheet::setPathValue(), which binds a special path of
PropertySheet, such as

    .cells.Bind.A1.D1

to an expression, such as

     tuple(.cells, <<A2>>, <<A5>>)

The A1 and D1 in the example above specifies the binding start and end
cell address. And <<A2>> and <<A5>> are the range of cells to bind to.
Note that you can use any expression that evalutes to string for the
binding destination, e.g. <<A%d>> % B1, which uses the value inside B1
to construct the binding destination. The '.cells' in the tuple shown
above is an example to bind cells of the same PropertySheet. It can be
change to to reference to any other spreadsheet, even those outside the
current document, e.g. Document#Spreadsheet001.cells
2021-12-21 21:41:02 -07:00
Zheng, Lei
127e8098e8 Spreadsheet: add a few context menu options 2021-10-12 14:34:58 -05:00
Chris Hennes
403a569315 [Spreadsheet] Refactor keyboard handling
LineEdit no longer actually handles motion, it simply indicates which
action was taken to cause it to lose focus (e.g. which key was pressed).
It's up to the client code to determine what this means. This allows
significant consolidation of keyboard-handling logic, and the
implementation of more extensive keyboard navigation features.

New keyboard shortcuts include a tab counter to implement auto-return,
plus Ctrl->Arrow, End, Home, Ctrl-End, and Ctrl-Home, matching the
behavior of OpenOffice, LibreOffice, etc.

Block selection via keyboard has also been added by holding down the
shift key during navigation with the arrow keys (this also works in
combination with the Ctrl modifier for region navigation).
2021-10-08 14:55:39 -05:00
mwganson
0be3565dbe [Spreadsheet] add preference page and 3 import/export parameters 2021-09-27 22:05:36 -05:00
0penBrain
2a3edfd83e [SpreadSheet] Fixes #4563 exported range issue 2021-02-12 18:06:07 +01:00
Benjamin Nauck
d525b29fa5 [Spreadsheet] Remove alias from dynamic properties on removeRows/Columns
When removing a row in a spreadsheet which has an assigned alias, the
alias will not be removed from the list of dynamic properties.

This makes it impossible to create a new alias which uses the same name
even if the original was removed (using removeRows/removeColumns)

Fixes #4492
2021-01-04 22:10:58 +01:00
luz paz
44636aca2f Spreadsheet: Make all file headers uniform [skip-ci] 2020-11-03 14:52:53 +01:00
wmayer
4ec45b545e boost 1.73.0: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated 2020-06-12 17:51:33 +02:00