/UpdateFieldsFromExpression

Update Fields From Expression (QGIS Plugin)

Primary LanguagePythonMIT LicenseMIT

Update Fields From Expression (QGIS Plugin)

Update multiple attribute fields of selected features from a compact, readable expression. Unquoted right-hand sides that match an existing field name copy values from that field; quoted values are taken literally. The plugin remembers your last expressions, supports quick recall, and keeps the dialog’s size/position between runs.

image

Key benefits

  • Fast bulk updates with a short expression instead of multiple field calculator steps.

  • Field reference vs. literal handled automatically:

    • FieldA = FieldB → copy values from FieldB (case-insensitive field lookup).

    • FieldA = "FieldB" → set the literal text FieldB.

  • Multiple assignments at once: A = B, C = "x", D = 42, E = null.

  • History & recall: recent expressions list (click to copy, double-click to run; Enter executes).

  • Manage recents: remove selected or clear all; reorder by drag-and-drop (most recent stays on top).

  • Non-intrusive feedback: messages appear in QGIS’s info bar and auto-hide after 5s.

  • Remembers UI: dialog size and position are persisted via QSettings.

Requirements

  • QGIS 3.22 or newer.

Installation

  1. Download or clone this repository.

  2. Copy the folder UpdateFieldsFromExpression into your QGIS profile’s plugin directory, e.g.

    • Windows: %APPDATA%\QGIS\QGIS3\profiles\default\python\plugins\

    • Linux: ~/.local/share/QGIS/QGIS3/profiles/default/python/plugins/

    • macOS: ~/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/

  3. Start QGIS (or restart it), open Plugins → Manage and Install Plugins…, and enable Update Fields From Expression.

Alternatively, zip the folder and use Install from ZIP in the Plugin Manager.

Usage

  1. Select the features you want to modify in the active vector layer.

  2. Click the Update Fields From Expression toolbar button (or find it under the Plugins menu).

  3. In the dialog:

    • Type an expression (or pick one from Recent expressions).

    • Press Enter to execute, or click Run.

    • Double-click a recent expression to copy and run immediately.

    • Click a recent expression to copy it into the editor without running.

    • Right-click the recent list to Remove selected or Clear all; you can also delete with the Delete key.

    • Drag to reorder recents for convenience (the most recent stays pinned at the top).

  4. Results and warnings are shown in the QGIS info bar.

Expression format

  • Copy from field (case-insensitive):

    Target = SourceField

  • Set literal text:

    Target = "SourceField" # literal string Target = 'hello'

  • Set numeric or null:

    Target = 42 Target = 3.14 Target = null

  • Multiple assignments in one run (comma-separated):

    A = B, C = "x", D = 100, E = null

  • Multiple targets share the same value:

    A, B, C = D A, B, C = "same literal"

Notes

  • Destination field names are matched case-insensitively.

  • Unquoted right-hand sides are treated as:

    1. another field name if it matches an existing field, otherwise

    2. a number (int/float) if it parses as one, otherwise

    3. a string literal (unquoted).

  • The plugin updates selected features only.

Managing recent expressions

  • The most recent expression is inserted at the top after a successful run and remains pinned there.

  • You can reorder other entries via drag-and-drop.

  • Remove unwanted entries via context menu or the Delete key.

  • Recents are saved even if you cancel the dialog.

UI persistence

  • The dialog’s size and position are stored in QSettings and restored on next use.

  • A legacy, project-variable fallback is supported for backward compatibility.

Limitations

  • The parser targets compact “assignment list” syntax as shown above; it is not a full expression evaluator.

  • The plugin does not commit edits automatically; it relies on QGIS’s standard edit session model. (You can commit/rollback from QGIS as usual.)

Privacy & storage

  • Recent expressions and window geometry are stored locally in QGIS settings (and, for compatibility, the project variable may mirror the geometry).

  • No data is sent outside your environment.

Contributing

Issues and pull requests are welcome. Please include:

  • QGIS version and OS,

  • steps to reproduce,

  • sample layer/fields and the expression used (if relevant).

License

MIT License. See LICENSE for details.

Changelog

  • 1.0.0

    • Initial public release with field/literal handling, multi-assignment, recents (click/double-click), drag-reorder with pinned top, deletion/clear, info-bar messages with timeouts, and geometry persistence.