Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix grid views to show without measurements #1478

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This is a *minor release* that aims to be fully compatible with v0.5.0, while fi
* Extensions can't be loaded from sub-directories of the extension directory (https://github.com/qupath/qupath/pull/1461)
* OpenSlide is not available when running from command line (https://github.com/qupath/qupath/pull/1447)
* `convert-ome` always returns 0 even if it fails (https://github.com/qupath/qupath/issues/1451)
* Grid views don't show objects by default if no measurements are available (https://github.com/qupath/qupath/issues/1472)

### Enhancement
* Add keyboard shortcuts to tooltips (https://github.com/qupath/qupath/issues/1450)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ private static List<PathObject> getAnnotations(PathObjectHierarchy hierarchy) {
* @return
*/
public Stage getStage() {
if (stage == null)
if (stage == null) {
initializeGUI();
stage.setWidth(600);
}
return stage;
}

Expand Down Expand Up @@ -306,9 +307,7 @@ private void initializeData(ImageData<BufferedImage> imageData) {

String m = measurement.getValue();
sortPathObjects(backingList, model, m, descending.get());
filteredList.setPredicate(p -> {
return !(isMissingCore(p) || Double.isNaN(model.getNumericValue(p, m)));
});
filteredList.setPredicate(p -> m == null || !(isMissingCore(p) || Double.isNaN(model.getNumericValue(p, m))));
grid.getItems().setAll(filteredList);

// Select the first measurement if necessary
Expand Down Expand Up @@ -345,6 +344,7 @@ private void initializeGUI() {


comboMeasurement = new ComboBox<>();
comboMeasurement.setPlaceholder(createPlaceholderText("No measurements!"));
comboMeasurement.setItems(model.getMeasurementNames());
if (!comboMeasurement.getItems().isEmpty())
comboMeasurement.getSelectionModel().select(0);
Expand Down Expand Up @@ -375,14 +375,7 @@ private void initializeGUI() {

CheckBox cbShowMeasurement = new CheckBox("Show measurement");
showMeasurement.bind(cbShowMeasurement.selectedProperty());
showMeasurement.addListener(c -> {
String m = measurement.getValue();
sortPathObjects(backingList, model, m, descending.get());
filteredList.setPredicate(p -> {
return m == null || !(isMissingCore(p) || Double.isNaN(model.getNumericValue(p, m)));
});
grid.getItems().setAll(filteredList);
}); // Force an update
showMeasurement.addListener(c -> updateMeasurement()); // Force an update


CheckBox cbAnimation = new CheckBox("Animate");
Expand Down Expand Up @@ -440,6 +433,14 @@ private void initializeGUI() {
stage.setOnShowing(e -> refresh());
stage.show();
}


private void updateMeasurement() {
String m = measurement.getValue();
sortPathObjects(backingList, model, m, descending.get());
filteredList.setPredicate(p -> m == null || !(isMissingCore(p) || Double.isNaN(model.getNumericValue(p, m))));
grid.getItems().setAll(filteredList);
}


/**
Expand Down Expand Up @@ -479,8 +480,13 @@ public void hierarchyChanged(PathObjectHierarchyEvent event) {
requestUpdate(imageData);
}
}




private static Text createPlaceholderText(String text) {
var textNode = new Text(text);
textNode.setStyle("-fx-fill: -fx-text-base-color;");
return textNode;
}

class QuPathGridView extends StackPane {

Expand All @@ -490,7 +496,7 @@ class QuPathGridView extends StackPane {

private IntegerProperty imageSize = new SimpleIntegerProperty();

private Text textEmpty = new Text("No objects available!");
private Text textEmpty = createPlaceholderText("No objects available!");

QuPathGridView() {
imageSize.addListener(v -> {
Expand All @@ -503,7 +509,6 @@ public void onChanged(javafx.collections.ListChangeListener.Change<? extends Pat
}
});
updateChildren();
textEmpty.setStyle("-fx-fill: -fx-text-base-color;");
StackPane.setAlignment(textEmpty, Pos.CENTER);
}

Expand Down Expand Up @@ -603,15 +608,15 @@ protected void layoutChildren() {
TranslateTransition translate = translationMap.get(node);
boolean doChanges = false;
if (translate == null) {
translate = new TranslateTransition(Duration.seconds(0.5));
translate = new TranslateTransition(Duration.seconds(0.25));
translate.setNode(node);
translationMap.put(node, translate);
doChanges = true;
} else {
if (!GeneralTools.almostTheSame(x, translate.getToX(), 0.001)
|| !GeneralTools.almostTheSame(y, translate.getToY(), 0.001)) {
translate.stop();
translate.setDuration(Duration.seconds(0.5));
translate.setDuration(Duration.seconds(0.25));
doChanges = true;
}
}
Expand Down
Loading