Commit Graph

71 Commits

Author SHA1 Message Date
Krzysztof
9329a0d2e3 Core: Extend completer popup list in 'Expression editor', fix size and position adjustment (#25242)
* Core: Fix completer popup adjustment after 'Tab' pressing
Completer popup in Expression Editor is now positioned and sized after pressing 'Tab'. This was missing when feature was added.

* Core: Extend completer popup list to up 20 elements or up to screen edge
Completer popup will now show up to 20 elements or will be limited to screen edge; if limited < 3 rows, popup will be displayed over cursor.

* Core: Fix completer wrapping on secondary screens

* Core: Fix completer positioning when includes long entries

* Core: Fix linter complaints
2025-12-25 09:11:00 +01:00
Syres916
5bcfa0e263 [Gui] Fix string encoding for document name 2025-11-20 18:37:50 +00:00
tetektoza
efbbfdbfb5 Gui: Differentiate completion activation modes in Expression Editor
Currently if user tries to press TAB during Expression Editor, it
inserts both the entry and its first subentry. Also, if user browses the
dropdown with arrows keys, it inserts it's values.

Root cause of that is the regression made in latest changes to chaining
completion logic which is triggered for all completion modes including
TAB, which already has its own refresh mechanism. Also,
ExpressionTextEdit connected both activated (Enter/click) and highlight
signals to the same slot, resulting in arrow key navigation inserting
completions.

So, this adds separate slots for ExpressionTextEdit to differentiate
completion modes. And also updates tab handling to pass
ActivationMode::Highlighted to prevent double chaining.
2025-11-12 00:23:04 +01:00
pre-commit-ci[bot]
9fe130cd73 All: Reformat according to new standard 2025-11-11 13:49:01 +01:00
tetektoza
fcd8354cbf Gui: Force Expression Completer to show drop-down upon clicking on item (#25011)
As the title says - currently if user clicks "Box" from the autocomplete
dropdown, it adds "Box.", but the property drop-down is never resolved
further, so user has to delete the separator and write it by hand.

When a completion ends with '.' or '#' and is being selected by
clicking, code sets `block=true` and calls `slotTextChanged()` which
prevents the `textChanged2` signal from being emitted. This results in
completer being blocked from updating next level of properties.

So, this patch adds a direct call to `completer->slotUpdate()`, which
triggers completer to parse the expression and show the drop-down.
2025-11-03 11:11:55 +01:00
Markus Reitböck
a72a0d6405 Gui: use CMake to generate precompiled headers on all platforms
"Professional CMake" book suggest the following:

"Targets should build successfully with or without compiler support for precompiled headers. It
should be considered an optimization, not a requirement. In particular, do not explicitly include a
precompile header (e.g. stdafx.h) in the source code, let CMake force-include an automatically
generated precompile header on the compiler command line instead. This is more portable across
the major compilers and is likely to be easier to maintain. It will also avoid warnings being
generated from certain code checking tools like iwyu (include what you use)."

Therefore, removed the "#include <PreCompiled.h>" from sources, also
there is no need for the "#ifdef _PreComp_" anymore
2025-09-14 09:47:03 +02:00
B0cho
3f24b767d2 Core: Fix 'Expression editor' handling with keyboard 2025-09-05 21:59:08 +02:00
B0cho
ae8679b8f6 Core: Show 'Expression' completer under cursor position 2025-09-02 01:09:12 +02:00
B0cho
c158fd9cf6 Core: Switch widget from 'ExpressionLineEdit' to 'ExpressionTextEdit'
+ minor dialog layout adjustments
2025-09-01 23:47:16 +02:00
Max Wilfinger
6692dacc0a Gui: Update UI strings for consistency
Closes: #22135
2025-08-04 20:14:45 +02:00
Benjamin Nauck
0fd4f2bac6 Spreadsheet: Only use validator when when prefix is not '=' 2025-06-23 16:14:35 +02:00
wmayer
d09055501d Gui: Implement validator for ExpressionLineEdit
As requested in issue 21426 a leading '=' shouldn't be allowed in the edit field. The validator now explicitly disallows a leading
'=' in the text. In the future the validator can be extended.

This fixes issue 21426
2025-06-03 16:11:48 -05:00
Benjamin Nauck
df3c324b7d Gui: use contains() and isEmpty() instead of count() where possible 2025-05-03 22:19:51 +02:00
xtemp09
14b2b254a4 [Spreadsheet] Fix input in expression editor (#19934)
* [Spreadsheet] Fix input in expression editor

Closes #19804

* [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>
2025-03-22 11:25:17 -05:00
Ladislav Michl
e62b91ada4 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
wwmayer
7b0a23337c Gui: Prepare for clang-format (#16051)
* Gui: Prepare for clang-format

* [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-09-02 17:48:55 +02:00
xtemp09
4d0c607c07 Fix the crash described in #12785
Closes #12785. The cause of the segmentation fault is access to the
already deleted _QMenu_. Simple setting attribute `Qt::WA_DeleteOnClose`
and removal of `delete menu` prevented it. To reproduce the crash, one
needs to mess up the `user.cfg` file in the way described in the issue.

Here is the fragment from the issue to mess up the `user.cfg` file:

```xml
<FCParamGroup Name="Expression">
<FCText Name="EditorTrigger">=</FCText>
<FCBool Name="AntoHideEditorIcon" Value="1"/>
<FCBool Name="NoSystemBackground" Value="1"/>
<FCInt Name="EditDialogBGAlpha" Value="1"/>
<FCInt Name="EditDialogWidth" Value="300"/>
<FCInt Name="EditDialogHeight" Value="214"/>
<FCInt Name="EditDialogTextHeight" Value="35"/>
</FCParamGroup>
```

---

This commit changes also unconnected things:

- usage of `QObject::connect` instead of if statements
- relocation of a separator and an action inside the if statement (I saw
no reason to have a separator and an action for _ExpressionCompleter_ if
there is no expression completer)
- usage of asynchronous `QMenu::popup()` instead of synchronous
`QMenu::exec()`. This way is used within [the source code of Qt]
(https://github.com/qt/qtbase/blob/5.15/src/widgets/widgets/
qlineedit.cpp#L2191-L2197).
2024-03-09 16:12:47 +01:00
André Caldas
89dbab9b0e Avoids using getNameInDocument() to test if DocumentObject is attached to a Document.
This patch substitutes by isAttachedToDocument() (almost) everywhere where
getNameInDocument() is used for this purpose.

The very few places not touched by this patch demand a (just a little) less trivial change.
When we change the returning type of getNameInDocument() to std::string,
those places will be easily found, because they shall generate a compiler error
(converting std::string to bool).

Rationale:
The fact that getNameInDocument() return nullptr to indicate
that the object is not attached to a document is responsible for lots of bugs
where the developer does not check for "nullptr".

The idea is to eliminate all those uses of getNameInDocument() and, in the near future,
make getNameInDocument() return always a valid std::string.
2023-12-11 17:37:58 +01:00
wmayer
fa8978ce99 Gui: modernize C++: return braced init list 2023-08-18 00:36:24 +02:00
wmayer
7a3106d31b modernize C++: use bool literals 2023-08-06 01:35:39 +02:00
wmayer
a72ca7f424 Gui: fixes #8501: FreeCAD crashes when constraining a sketch with an expression containing . (dot) 2023-03-09 12:45:16 +01:00
wmayer
62c05414d1 App: split tokenizer handling of ExpressionCompleter to its own class 2023-02-26 09:00:27 +01:00
0penBrain
76aa8c1534 [Bugfix] Gui: fix bug in expression completer tokenizing, fixes #8590 2023-02-23 13:49:03 +01:00
Uwe
58a008120d [Gui] ExpressionCompleter: fix some GitHub Action reports (#8264)
* [Gui] ExpressionCompleter: fix some GitHub Action reports

- too long lines
- too short variable names
- use .empty()

- also some reformatting according to our current clang file
2023-01-27 00:37:54 +01:00
Adrian Popescu
3914792cec Fix8228 warnings (#8262)
* Cleaned up Expression Completer
2023-01-26 00:19:05 +01:00
wmayer
95444519dc Gui: fix several compiler warnings 2023-01-25 23:05:29 +01:00
wmayer
7b8c6335a3 Gui: improve formatation and use of curly braces 2023-01-25 23:05:29 +01:00
luzpaz
3c9f48e696 Gui: fix trailing whitespace 2023-01-25 15:23:47 +01:00
Adrian Popescu
21a4d4827e Expressions: path auto-completion fixes (#8228)
PR #8228 consisted of the following:
* Added Documentation for the expression completer
* Working PATH completion
* Allow completes on trailing separator
* Fixed paths appearing with a . at first
* Chaining completions on enter
* Fixed Missing Separator and Document Completions
- fixed missing separator for contextual Properties (ConstraintsHeight instead of Constraints.Height)
- fixed retries on filename#objectname so that they work better
2023-01-24 14:57:59 -06:00
wmayer
3354fa033b Gui: move to new style connect() 2023-01-12 17:40:20 +01:00
wmayer
3f615bbe05 Gui: fix possible problems with new style connect
* In UIntSpinBox rename the signal to not overwrite the signal of the base class
* In UIntSpinBox use the (ambiguous) signal 'valueChanged' of the base class QSpinBox
* To avoid that connect() fails use the function pointer of the Qt class where the signal is defined
2023-01-12 17:02:59 +01:00
Uwe
5ad737ccdc [Gui] modernize some connect() settings
- addresses #6166
2023-01-12 15:13:16 +01:00
Uwe
a39c497437 [skip ci] [Gui] ExpressionCompleter: fix a typo
- found by the CI
2023-01-12 04:20:40 +01:00
luz paz
818e2b2841 Gui: fix trailing whitespace 2022-12-02 19:18:54 -06:00
berniev
ae53c9b0a4 Gui: Use auto and range-based for (#7481)
* On lines where the variable type is obvious from inspection, avoid repeating the type using auto. 
* When possible use a ranged for loop instead of begin() and end() iterators
2022-09-14 13:25:13 -05:00
berniev
75fa455c5d Gui: Use override etc 2 2022-08-09 12:43:23 +02:00
berniev
2db561561e Gui: use empty 2022-08-06 16:35:45 +02:00
Uwe
bb2b49fb1f [Gui] remove superfluous nullptr checks 2022-07-18 03:17:42 +02:00
wmayer
6d4f22a970 Gui: fix crash in ExpressionCompleter::slotUpdate
Forum thread: https://forum.freecadweb.org/viewtopic.php?f=3&t=69931
2022-07-16 18:23:42 +02:00
wmayer
72e464b1cc Conda: ssize_t is a POSIX type and thus not necessarily defined on Windows. Currently this causes build failures with Conda + Py3.10.
The solution is to get rid off all occurrences of ssize_t in FreeCAD code
2022-05-17 11:43:40 +02:00
wmayer
1178df06b4 Gui: modernize C++11
* use nullptr
2022-03-23 18:41:21 +01:00
Uwe
99191c6679 [Gui] So headers: remove unused includes
- also sort out some headers to be used in precompiled headers
- also move a boost header to precompiled headers
2022-03-16 02:01:32 +01:00
Uwe
119001733e [Gui] compilation fix for ExpressionCompleter
MSVC complained that ssize_t was undefined
2022-03-05 01:12:30 +01:00
Uwe
a8c679c370 [Gui] Expression: remove unused includes 2022-03-02 05:00:21 +01:00
Zheng, Lei
753d51aedf 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
0c2c334f87 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
Chris Hennes
098d7b9aee [GUI] Remove code for Qt < 5.9 2021-04-02 10:10:37 +02:00
Benjamin Nauck
1f3627c938 [Gui] Switch from boost::tuple to std::tuple
It's better to use the standard lib when possible
2021-03-06 19:31:06 +01:00
Benjamin Nauck
8fb44c3aa6 Gui: Minor cleanup
Cleans up code which was touched in previous commit.

* Don't call popup() twice when not needed
* use nullptr instead of 0 for pointers
2021-02-19 16:22:41 +01:00
Benjamin Nauck
eb400fe249 Spreadsheet: Don't autocomplete when writing strings
After pull request https://github.com/FreeCAD/FreeCAD/pull/4215 it
doesn't make much sense helping the user to write expressions without
leading '=', as that content will be parsed as a string.

This change adjusts the behaviour in SpreadsheetGui's LineEdit to avoid
popping up the ExpressionCompleter when no leading equal sign is used.
2021-02-19 16:22:41 +01:00