Commit Graph
521 Commits
Author SHA1 Message Date
Magne Sjaastad 64361c2f78 #14746 Fix duplicate AppEnum serialization text and detect it in addItem
RimGridCalculation::AdditionalCasesType::ALL_CASES and
RimIntersectionFilterEnum::INTERSECT_FILTER_BETWEEN both reused the
serialization text of a sibling enum value (NONE and
INTERSECT_SHOW_BELOW respectively), so they would silently round-trip
as the wrong value when read back from a project file.

AppEnumMapperBase::addItem only asserted alias uniqueness, not text
uniqueness, so this class of bug went undetected. Add a CAF_ASSERT
checking that a new enum value's serialization text does not match an
existing value's text or aliases.

Found while investigating the AppEnum alias-duplication note in #14654.
2026-09-14 08:14:19 -04:00
Magne Sjaastad c9d118f2de Copy Qt pdb files to the build folder when present
Qt is distributed both with and without pdb files. When they are present,
copy them next to the Qt dlls so symbols are available when debugging.

Pass --pdb to windeployqt for the configurations built with debug
information, and copy the matching pdb file in the AppFwk test
applications and unit tests using a helper script that skips missing
files.
2026-08-10 13:48:34 +02:00
Magne Sjaastad 94da54c4f5 Remove AsyncPdmObjectVectorDeleter and delete PDM objects synchronously
Deleting PDM objects on a worker thread is not safe. PdmObjectHandle::prepareForDelete()
mutates state owned by other objects, it nulls the guarded pointers held by other objects
and clears m_pointersReferencingMe, an unsynchronised std::set that every PdmPointer
construction and destruction touches. Destroying an object off the main thread therefore
races with the main thread on the shared object graph. See issue 14491.

Profiling a summary ensemble teardown shows the mechanism does not pay for itself. Releasing
397 Drogon realizations takes 0.24 s sequentially and 0.24 s in parallel, and for a heavy
case the parallel release is slower than the sequential one, because free() is serialised
inside the allocator. The PDM bookkeeping itself is 0.4 to 2.8 percent of the teardown.

Remove the class and deleteChildrenAsync(), and delete synchronously instead. The call sites
that used clearWithoutDelete() and a manual delete loop to work around the race can now call
deleteChildren() directly. Add caf::PdmObjectHandleTools::deleteObjects() for the case where
the objects are no longer owned by a child array field.

The observer disconnection from issue 12262 does not depend on clearWithoutDelete(). ~Signal()
unregisters itself from every observer, so a deleted child detaches itself. That fix addressed
the async race, where ~Signal() mutated the observer list from a worker thread. The unit test
is updated to assert the observed signal count directly instead of relying on a crash.
2026-08-10 09:40:33 +02:00
Magne Sjaastad 21694b11e7 #14476 Align CAF_ASSERT with standard assert semantics
CAF_ASSERT was unconditionally active in every build configuration. Make it
follow the semantics of the standard assert(): active in Debug, compiled out in
optimized builds (NDEBUG).

Add the CMake option RESINSIGHT_ENABLE_ASSERTS_IN_RELEASE (default OFF) for
developers who want the asserts to stay active in an optimized build, which is
useful when reproducing a problem in RelWithDebInfo with a debugger attached.

When compiled out, the expression is kept inside an unevaluated sizeof rather
than discarded. It is not evaluated, so there is no run-time cost and no side
effects, but it is still type checked and any variable used only by the assert
still counts as referenced, avoiding a wave of unused-variable warnings.

CAF_ENABLE_ASSERTS is given a default in cafAssert.h so the header stays
self-contained and include order can never silently switch the asserts off.

Document in docs/agents/coding-style.md that CAF_ASSERT is the assert to use,
that CVF_ASSERT is legacy, and that asserts are for broken invariants rather
than for run-time conditions that need real error handling.
2026-08-07 15:05:57 +02:00
Magne Sjaastad ebf75c09a1 #14411 Enforce name uniqueness for surfaces, polygons and folders
* #14411 Enforce name uniqueness for surfaces, polygons and folders

Names must be unique among siblings sharing the same parent folder. Items in different folders may keep identical names, and comparison is case sensitive.

Siblings are the objects held by the same caf::PdmChildArrayField. Items and folders live in two distinct child arrays in caf::PdmNestedCollection, so a folder and an item may share a name under the same parent.

The Python API gets an OnNameConflict flag on AddFolder, CreatePolygon, ImportSurface and NewRegularSurface, supporting FAIL (default), AUTO_RENAME and OVERWRITE. NewSurface is left out, as grid case surfaces derive their tree label from the case and K index and carry no name of their own.
2026-08-07 08:34:58 +02:00
Magne Sjaastad 5efcf88949 #14446 Initialize loggers before reading cloud config files
Cloud services are configured from RiaApplication::initialize(), which runs before the subclasses append their logger instances. All messages from the cloud config file search were therefore dropped. Add a virtual initializeLoggers() called before the cloud configuration is read, and move creation of the file logger and the std out logger into the overrides. The message panel logger depends on the main windows, and is still created in RiaGuiApplication::initialize().

Do not write fields with IO disabled to the application store, mirroring the check already present when reading. This stops the cloud service configuration from being persisted into the user preferences file.
2026-08-04 13:05:03 +02:00
Magne Sjaastad 9ccca3e20a #14401 Introduce initAfterInsert() to combine resolveReferencesRecursively() and initAfterReadRecursively() 2026-08-03 15:34:10 +02:00
Magne Sjaastad 4c39ce3e6c #14404 Guard against whitespace in AppEnum serialization text and fix affected enums 2026-07-30 08:41:27 +02:00
Magne Sjaastad 442d62cf6d #14368 Make AppEnum mapper initialization thread safe 2026-07-28 15:19:58 +02:00
Magne Sjaastad 1858529f7d #14266 Fix crash when activating combo box with stale option index 2026-06-23 07:31:55 +02:00
Magne Sjaastad 98ea83146a #14122 Allow tree selection editor to grow only when it is the last row
The tree selection editor can grow to a large height, which is useful when it is the last field editor in the property dialog. When other field editors are located below, the heightHint is now used as the maximum height instead. The form layout tracks whether an editor occupies the bottom-most row of the form and passes this to the editor. In the Analysis Plot, the time step selection is constrained to its height hint because other input fields are located below it.
2026-06-05 16:28:22 +02:00
Magne Sjaastad 99fdcc9a9a AppFwk: make PdmUiTreeOrdering::add null-tolerant and clean up containsField
The add() overloads aborted via CAF_ASSERT when passed a null field or
object, forcing every call site that adds an optional child to pre-guard.
Adding an optional node is inherently an "add it if it exists" operation,
so make both overloads a no-op on null instead: the field overload returns,
and the object overload returns nullptr. This removes a class of latent
release crashes and the need for repetitive null checks at call sites.

Also remove a redundant dynamic_cast (and its "// What ???" comment) in
containsField, since child() already returns PdmUiTreeOrdering*.
2026-06-04 16:07:12 +02:00
Magne Sjaastad 022d77bef8 macOS: Initial Apple Silicon and x86_64 build support
* Refactor: add MACOSX_BUNDLE option to qt_add_executable in multiple CMakeLists.txt files
* #14045 macOS: Guard std::stacktrace usage and skip ucontext on Apple platforms
* #14045 macOS: Guard std::ispanstream with std::istringstream fallback
* #14045 macOS: Add vcpkg overlay triplets for osx and exclude grpc on osx
* #14045 macOS: CMake macOS build support and openzgy OpenMP-disable patch
* #14045 CI: Add macOS build workflow
* #14045 macOS: Use feature-test macros to detect <stacktrace> and <spanstream>
* #14045 macOS: Make MAX_STIMPLAN_LAYERS constexpr to fix arm64 link error
* #14045 CI: Ship README-macOS.txt with artifact to document Gatekeeper workaround
* #14045 CI: Pin macOS runner to macos-14 and set deployment target to 14.0
* #14045 CI: Move macOS runner to macos-15 and fix README step on configure failure
2026-06-01 12:38:55 +02:00
Magne Sjaastad fe59babf21 #13987 PDM: Fix IconProvider operator= clearing pixmap + regression test
IconProvider::operator= copied a new resource-string but never cleared
the existing m_pixmap. icon() prefers the pixmap when present, so a
pixmap-based default stamped earlier (e.g. by a base class) would
silently shadow a later resource-string-only assignment in a derived
class.

Reset m_pixmap in operator= so resource-string-only assignments fully
replace pixmap-based ones, and cover the replacement semantics with a
caf::IconProvider regression test: default-overwriting-pixmap,
resource-string-overwriting-pixmap and pixmap-overwriting-pixmap.

Needed for the upcoming nested-collection migration where a base class
stamps a folder pixmap and the topmost instance applies a branded
resource-string icon on top.
2026-05-13 14:53:00 +02:00
Magne Sjaastad 92da6633bb #13987 PDM: Add caf::PdmNestedCollection framework
Introduce a shared base for tree-shaped folder containers that hold a
list of leaf items together with a list of subcontainers of the same
kind. Replaces the per-class plumbing (subcollections field, top-folder
flag, add/remove/find sub-collection, factory) that is duplicated across
RimSurfaceCollection, RimPolygonCollection and similar candidates.

- caf::PdmNestedCollectionBase: non-templated PdmObject base exposing
  collection-name, add-new-subcollection, leaf-check and topmost-folder
  marking for generic command features and script methods.
- caf::PdmNestedCollection<SelfT, ItemT>: CRTP template that owns the
  typed m_subCollections field and inherits the m_items array from
  PdmObjectCollection<ItemT>. Provides allItems(), find-sub-collection,
  and a typed factory hook.
- RimNestedMirrorCollectionInView: view-side analogue for in-view
  collections that mirror a nested source collection, with orphan-sweep
  + find-or-create + reorder sync.

Design rationale (templated vs non-templated, break-even on derived
class count) lives in docs/pdm-nested-collection-design.md.

No callers migrated in this commit.
2026-05-13 14:53:00 +02:00
Magne Sjaastad aaa95bdcf3 PdmObjectCollection: Move PdmObject base check to constructor
Replace the class-level static_assert with a DerivedFromPdmObject concept
checked inside the constructor body. The constructor is lazily instantiated,
so T can be forward-declared at the point PdmObjectCollection<T> is used
as a base class.
2026-05-11 13:42:13 +02:00
Magne Sjaastad 7fcd192b71 AppEnum: Type-erase the mapping machinery into a non-template base
Move the loops, lookups, and QString machinery out of
AppEnum<T>::EnumMapper into a new non-template AppEnumMapperBase defined
in cafAppEnum.cpp. Each member is now compiled once for the whole
program rather than once per enum type, cutting build time and binary
size for a class template instantiated across hundreds of enums.

AppEnum<T> becomes a thin static_cast shim around the base methods.
Enum values are stored as int in the mapping; a static_assert rejects
enum types whose underlying type is wider than int. The widest
underlying type currently in use in ResInsight is short, so all current
instantiations are unaffected.

Use std::optional<int> for the mapper default value, and assert against
an empty mapping in defaultValue() (the prior code returned m_mapping[0]
unconditionally, which is undefined behavior on empty).

Document why mapper() uses an explicit init flag rather than
std::call_once or a magic-static lambda: setUp() re-enters mapper() via
addItem, so anything that locks on first init would deadlock.
First-access must therefore be single-threaded, as already exercised by
BaseTest.CreateObjectInMultipleThreads.

Add AppEnumTest.MappingRoundTrip covering text <-> enum, index <-> enum,
isValid, and the failure paths of setFromText / setFromIndex (resets to
default, returns false).
2026-05-05 14:27:12 +02:00
Magne Sjaastad bd3836ba25 #13901 ShowPlotData: Invert dependencies via capability mixins and text-dialog signal 2026-04-20 14:09:25 +02:00
Magne Sjaastad 4ae60f1818 Fix GCC warning by specializing PdmVariantEqualImpl for QString 2026-04-14 14:25:41 +02:00
Magne Sjaastad 52329d567d Fix clang issues
* Remove unnecessary message parameter from PdmFieldScriptingCapabilityIOHandler readFromField calls
* Add checks for QFile open operations in BaseTest ReadWrite tests
* Fix integer size assertions in AppEnum and PdmLogging tests
2026-04-10 06:57:52 +02:00
Magne Sjaastad e8223485b1 Fix ADL lookup for cvf pdmToVariant/pdmFromVariant overloads
Move pdmToVariant/pdmFromVariant overloads for cvf::Color3f, Vec3d, Mat4d, and
Mat3d from namespace caf to namespace cvf. Templates in
cafInternalPdmFieldTypeSpecializations.h use "using caf::pdmToVariant" followed
by an unqualified call, so ADL searches the argument's namespace (cvf). With the
overloads only in caf, the default template was selected, causing cvf::Color3f to
be stored raw in a QVariant instead of as QColor — breaking color field editing
and producing QVariant::save warnings.

All call sites now use the unqualified "using caf::pdmXxx; pdmXxx(value)" pattern
so ADL finds the correct overload without depending on cvf:: as a visible prefix.
Add AdlVariantTest to cafPdmCoreColor3fTest.cpp that exercises this exact pattern.

Adds caf::toVariant<T> and caf::fromVariant<T> to cafPdmFieldTraits.h as
thin wrappers that encapsulate the ADL two-step internally. Client code can
now call caf::toVariant(x) directly instead of requiring a using-declaration
at every call site.
2026-04-08 23:12:49 +02:00
Magne Sjaastad 700549fb3b Add baseline compile benchmark results 2026-04-08 12:37:36 +02:00
Magne Sjaastad ab97381d94 Add ADL-based field traits, migrate all call sites, remove cafInternalPdmValueFieldSpecializations.h
Introduce cafPdmFieldTraits.h with ADL-based pdmToVariant/pdmFromVariant/pdmVariantEqual
as a replacement for PdmValueFieldSpecialization. Migrate all types (AppEnum, FilePath,
PdmPointer, cvf types) and all call sites (PdmDataValueField, PdmProxyValueField, UI
framework, ApplicationLibCode). Delete cafInternalPdmValueFieldSpecializations.h.
Add cafPdmFieldTraits unit tests and fix std::optional support.
2026-04-08 12:37:36 +02:00
Magne Sjaastad e0a3606ae1 Add cafPdm_CompileBench target for compile-time benchmarking
Adds an OBJECT library with UNITY_BUILD OFF to measure per-file compile
cost of PDM field types in isolation. Wired into both Fwk/CMakeLists.txt
and the main CMakeLists.txt (under RESINSIGHT_INCLUDE_APPFWK_TESTS).
Also adds build-bench to .gitignore.
2026-04-08 12:37:36 +02:00
Magne Sjaastad 64a7546660 Fix Unity build conflict: remove duplicate PdmObjectCollection from cafPdmObjectGroup
Remove the unused non-template PdmObjectCollection class from cafPdmObjectGroup.h/.cpp.
This class conflicted with the template caf::PdmObjectCollection<T> in cafPdmObjectCollection.h,
causing MSVC redefinition errors in Unity builds. The class was dead code with no usages
in application code.

Also correct forward declarations in test MainWindow headers from PdmObjectCollection
to PdmObjectGroup, matching actual usage in the .cpp files.
2026-03-21 17:24:22 +01:00
Magne Sjaastad 04ca172893 PdmObjectHandle: Add createDerivedObjectsRecursively() lifecycle hook
Add createDerivedObjectsRecursively() which traverses the object tree using
direct recursion and calls the virtual createDerivedObjects() on each node.
Called between the two resolveReferencesRecursively() passes in RiaApplication,
allowing objects to create child objects based on already-resolved ptr fields.
The second resolve pass then handles references in the newly created children.
2026-03-19 15:10:26 +01:00
Magne Sjaastad 06016d18e3 cafPdmUiButton: Add fillWidth property and expose createButton as protected
Add fillWidth() to PdmUiButton to allow buttons to expand horizontally
instead of sizing to content. Make createButton protected so subclasses
can reuse button creation logic.
2026-03-04 09:52:17 +01:00
Magne Sjaastad 494d0fe064 Do not read field value from registry if not readable 2026-02-26 08:23:53 +01:00
Magne Sjaastad dbe08064ce Refactor double editor config to use attribute map
Remove custom editor attribute classes and migrate all double field validation and formatting (range, decimals, number format) to the attribute map system. Refactor PdmUiDoubleValueEditor to read settings from the field's attributes and always display formatted values. Remove redundant defineEditorAttribute overrides. Add tests for pair<bool, double> field validation. Centralize and simplify double field UI configuration for improved maintainability.
2026-02-16 16:54:22 +01:00
Magne Sjaastad 483a4a9b7b Clamp UI values if field supports clampValue method
Added a compile-time check to call clampValue on fields that support it before setting values from the UI. This ensures values are clamped to valid limits automatically when applicable.
2026-02-16 16:54:22 +01:00
Magne Sjaastad 945dd574bf Improve reliability of validation error tooltips in UI
Enhance validation error tooltip handling by introducing a 100 ms delay before display to prevent premature dismissal from key events. Ensure tooltips are shown at the correct widget position and only when visible. Also, improve removal of error icons and support for composite editor widgets. These changes make error feedback more consistent and user-friendly.
2026-02-16 16:54:22 +01:00
Magne Sjaastad ba4752e005 Add support for std::pair<bool, T> in PdmDataValueField
Extend PdmDataValueField to handle std::pair<bool, ArithmeticType> as DataType. This makes it possible to perform validation on these fields.
2026-02-16 16:54:22 +01:00
Magne Sjaastad cb8a069ccd Add support for custom validation callbacks on fields
* Add support for custom validation callbacks on fields

Introduce setCustomValidationCallback to PdmFieldHandle, allowing custom validation logic via user-provided lambdas or functions. The validate() method now invokes this callback if set, in addition to built-in checks. Includes comprehensive unit tests for custom and combined validation scenarios. Backward compatible: default behavior unchanged if no callback is set.
2026-02-09 16:48:42 +01:00
Magne Sjaastad de3758cf60 Set PdmUiButton default alignment to right
Removed manual setAlignment(Qt::AlignRight) calls for UI buttons,
as PdmUiButton now defaults to right alignment. Also removed
unused cafPdmUiButton.h includes from several files.
2026-01-27 13:37:26 +01:00
Magne Sjaastad caaf799229 Refactors PdmUiFieldSpecialization implementation
* Simplifies PdmUiFieldSpecialization implementation.

Refactors the PdmUiFieldSpecialization implementation to reduce code duplication.

Introduces a base class `PdmUiFieldSpecializationForValueSpec` that delegates to `PdmValueFieldSpecialization`, avoiding boilerplate code for common types.

The primary template now inherits from the new base class, providing default behavior for types with custom `PdmValueFieldSpecialization`.

* Improve AppEnum subset handling to avoid key collisions

Refactored AppEnum to use a unique key combining owner class name and field keyword for enum subset storage, preventing collisions when different object types use the same field keyword. Updated setEnumSubset and enumSubset to accept PdmFieldHandle pointers. Added tests to verify correct and independent subset behavior across object types and handle edge cases.

* Refactor PdmValueFieldSpecialization with base helpers

Introduce base classes for default isEqual and QVariant conversion. Update specializations to inherit from these helpers, removing redundant code and centralizing default behaviors.
2026-01-26 16:53:53 +01:00
Magne Sjaastad 9851afc621 #2070 AppFwk : Disable default IO for proxy fields
Proxy fields usually reads and transforms data from other sources, usually other Pdm fields. This commit disables IO for proxy fields in the constructor. If XML serialization is required, this must be set on the proxy field, like this

field.xmlCapability()->setIOWritable(true)
field.xmlCapability()->setIOReadable(true)
2026-01-19 16:10:14 +01:00
Magne Sjaastad 6e23037bb8 Refactors PdmUiItemInfo and PdmOptionItemInfo
Refactors PdmUiItem and moves PdmUiItemInfo and PdmOptionItemInfo classes.

Adds attribute support as a replacement for defineEditorAttributes
2026-01-08 21:44:58 +01:00
Kristian Bendiksen bd7e5ac1b9 Refactor: reduce duplicated code for collections 2026-01-05 13:15:47 +01:00
Magne Sjaastad 4488a7215d Replaces stylesheet-based validation styling with icon indicator
Uses QWidget::addAction() to show a warning icon for validation errors, similar to the information icon for optional fields. The error message appears in the icon's tooltip, avoiding stylesheet manipulation that was causing tooltip rendering issues.

- Adds warning icon to widgets with validation errors
- Preserves field tooltips (e.g., "Valid range: ...")
- Uses QPointer for automatic null-safety
- Works with QLineEdit and other widgets
2025-12-22 10:17:00 +01:00
Magne Sjaastad 4d312ecc82 #13358 Clamp values to valid range when reading project files 2025-12-19 13:06:13 +01:00
Magne Sjaastad e09baf3e80 Show red frame around editor widget, and show validation message in tooltip 2025-12-16 13:01:31 +01:00
Magne Sjaastad f342ca7757 Add validation to field and object
Add support for optional range checking in PdmDataValueField
2025-12-16 13:01:31 +01:00
Magne Sjaastad 9fa002abec Reduce number of objects to avoid long-running unit test in some cases 2025-12-16 13:01:31 +01:00
Magne Sjaastad e71172fa39 Fix more qt 6.10 bugs 2025-11-30 10:35:30 +01:00
Magne Sjaastad 40fbb6038f #13203 Replaces UiTreeItem with UiTreeManager
Substitutes the template-based UiTreeItem with an index-based UiTreeManager.
2025-11-20 12:39:57 +01:00
Magne Sjaastad 544e9eedd9 Improve spell checker using codespell
* Configures automated spell checking with codespell
Adds GitHub workflows and configuration files for automated spell checking using `codespell`.

This includes:
- A workflow for checking pull requests and preventing new typos
- A workflow for automatically fixing typos in the main codebase
- Configuration files for `codespell` to ignore specific terms and file types
- Documentation on how to use and configure the spell checking workflows.

* Corrects minor spelling and grammar errors.
2025-11-19 10:25:32 +01:00
Magne Sjaastad 2012c003dc #13044 Add support for labels and push buttons without a Pdm field
Introduces `PdmUiLabel` and `PdmUiButton` classes to enable the addition of labels and buttons directly within the UI configuration, without requiring a bound PDM field.

This enhancement provides greater flexibility in constructing user interfaces and allows direct user interaction via button callbacks.

It also updates the `PdmUiOrdering` to support label and button components, and modifies the `PdmUiFormLayoutObjectEditor` to properly render these new UI elements.
2025-10-20 09:23:06 +02:00
Magne Sjaastad e6fca7c06c Enables labels to display hyperlinks
Introduces the ability for labels to display hyperlinks.

This is achieved by adding a `setLabelText` function to handle both regular and shortened labels and allowing a callback function to be executed when the link is activated.

Adds a test object with labels and hyperlinks to the test application.
2025-10-17 07:43:51 +02:00
Magne Sjaastad cfb2dfa9c9 Add testing to CAF logging 2025-09-30 14:22:03 +02:00
Magne Sjaastad 8251562cd9 Add logging to CAF 2025-09-11 13:42:56 +02:00