Changeset 14206 in josm


Ignore:
Timestamp:
2018-08-31T00:57:57+02:00 (7 weeks ago)
Author:
Don-vip
Message:

fix #16698, see #15670 - make sure filters are executed (costly operation) only when necessary:

  • data changes imply execution of filters only when at least a filter is enabled
  • filter changes imply execution of filters even is no filter is enabled
  • filter dataset change events should not trigger a new filter execution!
Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r14169 r14206  
    4242import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
    4343import org.openstreetmap.josm.data.osm.event.DataSetListener;
     44import org.openstreetmap.josm.data.osm.event.FilterChangedEvent;
    4445import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
    4546import org.openstreetmap.josm.data.osm.event.PrimitiveFlagsChangedEvent;
     
    10301031
    10311032    void fireFilterChanged() {
    1032         fireEvent(new DataChangedEvent(this));
     1033        fireEvent(new FilterChangedEvent(this));
    10331034    }
    10341035
  • trunk/src/org/openstreetmap/josm/data/osm/FilterMatcher.java

    r13309 r14206  
    114114
    115115    /**
     116     * Determines if at least one filter is enabled.
     117     * @return {@code true} if at least one filter is enabled
     118     * @since 14206
     119     */
     120    public boolean hasFilters() {
     121        return !hiddenFilters.isEmpty() || !disabledFilters.isEmpty();
     122    }
     123
     124    /**
    116125     * Adds a filter to the currently used filters
    117126     * @param filter the filter to add
  • trunk/src/org/openstreetmap/josm/data/osm/FilterModel.java

    r14153 r14206  
    373373
    374374    /**
     375     * Determines if at least one filter is enabled.
     376     * @return {@code true} if at least one filter is enabled
     377     * @since 14206
     378     */
     379    public boolean hasFilters() {
     380        return filterMatcher.hasFilters();
     381    }
     382
     383    /**
    375384     * Returns the list of primitives whose filtering can be affected by change in primitive
    376385     * @param primitives list of primitives to check
  • trunk/src/org/openstreetmap/josm/data/osm/event/AbstractDatasetChangedEvent.java

    r12189 r14206  
    4949         */
    5050        CHANGESET_ID_CHANGED,
     51        /**
     52         * The filtered state changed for a list of primitives
     53         */
     54        FILTERS_CHANGED,
    5155        /**
    5256         * The flags changed for a primitive and have not been covered in an other event
  • trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterButton.java

    r12987 r14206  
    3636                if (filter.equals(afm.getCurrentAutoFilter())) {
    3737                    afm.setCurrentAutoFilter(null);
    38                     MainApplication.getMap().filterDialog.getFilterModel().executeFilters();
     38                    MainApplication.getMap().filterDialog.getFilterModel().executeFilters(true);
    3939                } else {
    4040                    afm.setCurrentAutoFilter(filter);
  • trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java

    r13434 r14206  
    394394        MapFrame map = MainApplication.getMap();
    395395        if (map != null) {
    396             map.filterDialog.getFilterModel().executeFilters();
     396            map.filterDialog.getFilterModel().executeFilters(true);
    397397        }
    398398    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/FilterDialog.java

    r14138 r14206  
    3030import org.openstreetmap.josm.data.osm.FilterModel;
    3131import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
     32import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent.DatasetEventType;
    3233import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
    3334import org.openstreetmap.josm.data.osm.event.DataSetListener;
     
    8384        DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT_CONSOLIDATED);
    8485        MapFrame.addMapModeChangeListener(this);
    85         filterModel.executeFilters();
     86        filterModel.executeFilters(true);
    8687    }
    8788
     
    326327    @Override
    327328    public void otherDatasetChange(AbstractDatasetChangedEvent event) {
    328         filterModel.executeFilters();
     329        if (!DatasetEventType.FILTERS_CHANGED.equals(event.getType())) {
     330            filterModel.executeFilters();
     331        }
    329332    }
    330333
  • trunk/src/org/openstreetmap/josm/gui/dialogs/FilterTableModel.java

    r12630 r14206  
    6363    private void updateFilters() {
    6464        AutoFilterManager.getInstance().setCurrentAutoFilter(null);
    65         executeFilters();
    66     }
    67 
    68     /**
    69      * Runs the filters on the current edit data set.
     65        executeFilters(true);
     66    }
     67
     68    /**
     69     * Runs the filters on the current edit data set, if any. Does nothing if no filter is enabled.
    7070     */
    7171    public void executeFilters() {
    72         if (AutoFilterManager.getInstance().getCurrentAutoFilter() == null) {
     72        executeFilters(false);
     73    }
     74
     75    /**
     76     * Runs the filter on a list of primitives that are part of the edit data set, if any. Does nothing if no filter is enabled.
     77     * @param primitives The primitives
     78     */
     79    public void executeFilters(Collection<? extends OsmPrimitive> primitives) {
     80        executeFilters(primitives, false);
     81    }
     82
     83    /**
     84     * Runs the filters on the current edit data set, if any.
     85     * @param force force execution of filters even if no filter is enabled. Useful to reset state after change of filters
     86     * @since 14206
     87     */
     88    public void executeFilters(boolean force) {
     89        if (AutoFilterManager.getInstance().getCurrentAutoFilter() == null && (force || model.hasFilters())) {
    7390            model.executeFilters();
    7491            updateMap();
     
    7794
    7895    /**
    79      * Runs the filter on a list of primitives that are part of the edit data set.
     96     * Runs the filter on a list of primitives that are part of the edit data set, if any.
     97     * @param force force execution of filters even if no filter is enabled. Useful to reset state after change of filters
    8098     * @param primitives The primitives
    81      */
    82     public void executeFilters(Collection<? extends OsmPrimitive> primitives) {
    83         if (AutoFilterManager.getInstance().getCurrentAutoFilter() == null) {
     99     * @since 14206
     100     */
     101    public void executeFilters(Collection<? extends OsmPrimitive> primitives, boolean force) {
     102        if (AutoFilterManager.getInstance().getCurrentAutoFilter() == null && (force || model.hasFilters())) {
    84103            model.executeFilters(primitives);
    85104            updateMap();
Note: See TracChangeset for help on using the changeset viewer.