Skip to content

Commit

Permalink
provide parent for msg boxes in loadDataset (fix #421)
Browse files Browse the repository at this point in the history
this puts the msg box in a reasonable (and on top) position
when the dataset is loaded on K start or through an annotation

on top hints for when no toppest level widgets are passed
  • Loading branch information
Optiligence committed Sep 13, 2017
1 parent 902cb63 commit 6b9a9fb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion main.cpp
Expand Up @@ -138,7 +138,7 @@ int main(int argc, char *argv[]) {
Viewer viewer;
Scripting scripts;
state.mainWindow->loadSettings();// load settings after viewer and window are accessible through state and viewer
state.mainWindow->widgetContainer.datasetLoadWidget.loadDataset();// load last used dataset or show
state.mainWindow->widgetContainer.datasetLoadWidget.loadDataset(&splash);// load last used dataset or show
viewer.timer.start(0);
#ifdef NDEBUG
splash.finish(state.mainWindow);
Expand Down
2 changes: 1 addition & 1 deletion skeleton/skeletonizer.cpp
Expand Up @@ -395,7 +395,7 @@ std::unordered_map<decltype(treeListElement::treeID), std::reference_wrapper<tre
const auto path = attributes.value("path").toString();
const bool overlay = attributes.value("overlay").isEmpty() ? Dataset::current.overlay : static_cast<bool>(attributes.value("overlay").toInt());
if (experimentName != Dataset::current.experimentname || overlay != Dataset::current.overlay) {
state->viewer->window->widgetContainer.datasetLoadWidget.loadDataset(overlay, path, true);
state->viewer->window->widgetContainer.datasetLoadWidget.loadDataset(state->mainWindow, overlay, path, true);
}
} else if(xml.name() == "MovementArea") {
if (!merge) {
Expand Down
29 changes: 16 additions & 13 deletions widgets/datasetloadwidget.cpp
Expand Up @@ -223,7 +223,7 @@ void DatasetLoadWidget::processButtonClicked() {
const auto dataset = tableWidget.item(tableWidget.currentRow(), 0)->text();
if (dataset.isEmpty()) {
QMessageBox::information(this, "Unable to load", "No path selected");
} else if (loadDataset(boost::none, dataset)) {
} else if (loadDataset(this, boost::none, dataset)) {
hide(); //hide datasetloadwidget only if we could successfully load a dataset
}
}
Expand All @@ -233,7 +233,7 @@ void DatasetLoadWidget::processButtonClicked() {
* 2. for multires datasets: by selecting the dataset folder (the folder containing the "magX" subfolders)
* 3. by specifying a .conf directly.
*/
bool DatasetLoadWidget::loadDataset(const boost::optional<bool> loadOverlay, QUrl path, const bool silent) {
bool DatasetLoadWidget::loadDataset(QWidget * parent, const boost::optional<bool> loadOverlay, QUrl path, const bool silent) {
if (path.isEmpty() && datasetUrl.isEmpty()) {//no dataset available to load
open();
return false;
Expand All @@ -244,11 +244,12 @@ bool DatasetLoadWidget::loadDataset(const boost::optional<bool> loadOverlay, QUr
const auto download = Network::singleton().refresh(path);
if (!download.first) {
if (!silent) {
QMessageBox box(this);
box.setIcon(QMessageBox::Warning);
box.setText("Unable to load Daataset.");
box.setInformativeText(QString("Failed to read config file from %1").arg(path.toString()));
box.exec();
QMessageBox warning(parent);
warning.setWindowFlags(Qt::WindowFlags{warning.windowFlags() | Qt::WindowStaysOnTopHint});
warning.setIcon(QMessageBox::Warning);
warning.setText("Unable to load Daataset.");
warning.setInformativeText(QString("Failed to read config file from %1").arg(path.toString()));
warning.exec();
open();
}
qDebug() << "no config at" << path;
Expand All @@ -257,7 +258,8 @@ bool DatasetLoadWidget::loadDataset(const boost::optional<bool> loadOverlay, QUr

bool keepAnnotation = silent;
if (!silent && (!Session::singleton().annotationFilename.isEmpty() || Session::singleton().unsavedChanges)) {
QMessageBox question(this);
QMessageBox question(parent);
question.setWindowFlags(Qt::WindowFlags{question.windowFlags() | Qt::WindowStaysOnTopHint});
question.setIcon(QMessageBox::Question);
question.setText(tr("Keep the current annotation for the new dataset?"));
question.setInformativeText(tr("It only makes sense to keep the annotation if the new dataset matches it."));
Expand All @@ -280,11 +282,12 @@ bool DatasetLoadWidget::loadDataset(const boost::optional<bool> loadOverlay, QUr
info.checkMagnifications();
} catch (std::exception &) {
if (!silent) {
QMessageBox box(this);
box.setIcon(QMessageBox::Warning);
box.setText("Dataset will not be loaded.");
box.setInformativeText("No magnifications could be detected. (knossos.conf in mag folder)");
box.exec();
QMessageBox warning(parent);
warning.setWindowFlags(Qt::WindowFlags{warning.windowFlags() | Qt::WindowStaysOnTopHint});
warning.setIcon(QMessageBox::Warning);
warning.setText("Dataset will not be loaded.");
warning.setInformativeText("No magnifications could be detected. (knossos.conf in mag folder)");
warning.exec();
open();
}
qDebug() << "no mags";
Expand Down
2 changes: 1 addition & 1 deletion widgets/datasetloadwidget.h
Expand Up @@ -90,7 +90,7 @@ class DatasetLoadWidget : public DialogVisibilityNotify {

explicit DatasetLoadWidget(QWidget *parent = 0);
void changeDataset(bool isGUI);
bool loadDataset(const boost::optional<bool> loadOverlay = boost::none, QUrl path = {}, const bool silent = false);
bool loadDataset(QWidget * parent, const boost::optional<bool> loadOverlay = boost::none, QUrl path = {}, const bool silent = false);
void saveSettings();
void loadSettings();
void applyGeometrySettings();
Expand Down

0 comments on commit 6b9a9fb

Please sign in to comment.