Skip to content

QGIS project import runs off the window, with progress and Cancel #2476

Done

Description

@pick2510

project.importQgis runs on the UI thread. It adds a project's layers one after another, each through the command that adds its kind, and no step looks at Cancel. Since #2471 a QGIS project's web service layers come in from their services: each asks for the service's capabilities, then a WFS, OGC API or feature service layer's features (page by page, within the read limits) or a WCS coverage. A project with several such layers, or a slow service, holds the window until every service has answered. Before #2471 only file reads and a WMS layer's capabilities did this.

What's wanted (AGENTS.md, "Never hold the window"): the import runs off the window, with progress (layers done of layers in the project) and Cancel. Cancelling leaves the project as it was, as other cancelled commands do.

Why it isn't a small change:

  • The import changes the session as it goes. Later layers, groups and relations read the layers added before them, and tile layers that land on the same tiles are merged.
  • There is no background path yet for a command that runs other commands on the session. Models and scripts run on a copy (workflows::ahead_on_copy), whose results are then taken. Read-ahead commands (reads::prepare) read one source before they run.

Possible approaches:

  • Read ahead. Collect every file and service read the import will make: each layer's source is known from the project text before anything is added. Read them all off the window with progress and Cancel, then add the layers from what was read, as service.add and layer.addData already take fetched documents and files.
  • Run on a copy. Run the import on a copy of the session, as models and scripts do, and take its result.

The import would then also go in long_commands (crates/engine/src/tests/cancellation.rs), and the cancellation tests would cover it.

Related: #882 (piece 10b, #2471).

Activity

  1. pick2510 commented on Nov 27, 2026

    @pick2510
    ContributorAuthor

    Taking this. Plan: the issue's read ahead option, on the path style.importQgis already uses since #2676.

    1. A project.importQgis arm in reads::prepare, off the window. It parses the project, marker images included, and works out for each layer what its add would read: files, GPX, MBTiles/PMTiles, WMS/WMTS capabilities, WFS, OGC API, feature services and WCS. It reads those through the existing layer::add_data_ahead and service prepare paths. Progress counts layers done of the project's layers, and Cancel is checked between them.
    2. Then on the window: the import itself takes what was read, in project order, so later layers, groups, relations and tile merging still see the layers added before them. It runs the same steps as today, with the fetched results passed in, as layer.addData and service.add already accept them.
    3. Anything the scan didn't foresee: it is still read as today, and a notice says how many were read that way.
    4. Tests: the command goes in reads::IN_BACKGROUND, so long_commands and both cancellation tests run it, on a corpus project with a file layer and a local service. A cancelled import leaves no new map and no Undo step, and the corpus import test is unchanged.

    Not "run on a copy": the import makes a new map, which would then have to be moved back from the copy.

  2. self-assigned this
    on Nov 27, 2026
  3. pick2510 commented on Nov 27, 2026

    @pick2510
    ContributorAuthor

    Change of plan: the import runs on a copy of the session, not as reads made ahead.

    Why: read ahead would have meant rebuilding every add command's downloads outside the command. For example, service.add reads a service's description ahead, but downloads WFS and OGC API feature pages and WCS coverages after it lands.

    How it works now:

    • The whole import runs as it does today, on a copy of the session on a thread of its own. Progress counts layers done of the project's, and Cancel is checked between layers and within each layer's reads.
    • When it lands, the map it made and any standalone tables it added move into the session, as one Undo step. Saved connections it made are made again in the session, and what it said is said there.
    • Saved web logins are tied to the session that opened them. So the login of each address the project's layers name is opened on the session first, before the read records its accounts. This is the same as a single service add does today, so it may read a saved login or ask which connection to use. The copy borrows those logins and never opens, ends or reads a login of its own.
    • The command line, scripts and the browser still run the import where they are, now with Cancel looked at between layers.
  4. pick2510 commented on Nov 27, 2026

    @pick2510
    ContributorAuthor

    PR open: #3120 (runs on a copy of the session; saved logins opened first and borrowed by the copy).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions