Skip to content

Commit

Permalink
Unify file loading (new window): drag/drop / raw files
Browse files Browse the repository at this point in the history
  • Loading branch information
codeling committed Feb 24, 2023
1 parent 528bfa7 commit 58b4291
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion libs/base/iADataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class iAbase_API iADataCollection : public iADataSet
iADataCollection(iADataCollection const& other) = delete;
iADataCollection& operator=(iADataCollection const& other) = delete;
std::vector<std::shared_ptr<iADataSet>> m_dataSets;
std::shared_ptr<QSettings> m_settings; //< TODO NEWIO: maybe replace with QVariantMap? re-use metadata? move somewhere else?
std::shared_ptr<QSettings> m_settings;
};

iAbase_API QString boundsStr(double const* bds);
23 changes: 9 additions & 14 deletions libs/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace
{
return iASystemThemeWatcher::isBrightTheme() ? BrightThemeQss : DarkThemeQss;
}
const QString ProjectFileExtension("iaproj"); // TODO: reuse in iAProjectFileIO
}

template <typename T>
Expand Down Expand Up @@ -313,7 +314,7 @@ void MainWindow::dropEvent(QDropEvent *e)
{
for(const QUrl &url: e->mimeData()->urls())
{
loadFileAskNewWindow(url.toLocalFile());
loadFileNew(url.toLocalFile(), nullptr);
}
}

Expand Down Expand Up @@ -347,8 +348,7 @@ void MainWindow::openRaw()
m_path,
"Raw File (*)"
);
// TODO NEWIO: ask for whether to load in new window here?
loadFileNew(fileName, nullptr, std::make_shared<iARawFileIO>());
loadFileNew(fileName, askWhichChild(), std::make_shared<iARawFileIO>());
}

void MainWindow::openRecentFile()
Expand All @@ -359,26 +359,21 @@ void MainWindow::openRecentFile()
return;
}
QString fileName = action->data().toString();
loadFileAskNewWindow(fileName);
loadFileNew(fileName, askWhichChild());
}

void MainWindow::loadFileAskNewWindow(QString const & fileName)
iAMdiChild* MainWindow::askWhichChild()
{
auto child = activeMdiChild();
if (child)
{
auto result = QMessageBox::question(
this, "", "Load data into the active window?", QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (result == QMessageBox::Cancel)
{
return;
}
auto result = QMessageBox::question(this, "", "Load data into the active window?", QMessageBox::Yes | QMessageBox::No);
if (result == QMessageBox::No)
{
child = nullptr;
}
}
loadFileNew(fileName, child);
return child;
}

void MainWindow::loadFileNew(QString const& fileName, iAMdiChild* child, std::shared_ptr<iAFileIO> io)
Expand Down Expand Up @@ -2329,7 +2324,7 @@ void MainWindow::openWithDataTypeConversion()
mapReadableDataTypeToVTKType(outDataType),
m_owdtcmin, m_owdtcmax, m_owdtcoutmin, m_owdtcoutmax, roi);
}
loadFileAskNewWindow(finalfilename);
loadFileNew(finalfilename, askWhichChild());
}
catch (std::exception & e)
{
Expand Down Expand Up @@ -2442,7 +2437,7 @@ int MainWindow::runGUI(int argc, char * argv[], QString const & appName, QString
iAFileTypeRegistry::addDefaultExtension(iADataSetType::Volume, "mhd");
iAFileTypeRegistry::addDefaultExtension(iADataSetType::Mesh, "stl");
//iAFileTypeRegistry::addDefaultExtension(iADataSetType::Graph, ".txt"); -> graph storing not yet implemented!
iAFileTypeRegistry::addDefaultExtension(iADataSetType::Collection, "iaproj");
iAFileTypeRegistry::addDefaultExtension(iADataSetType::Collection, ProjectFileExtension);
#if defined(__APPLE__) && defined(__MACH__)
QSurfaceFormat::setDefaultFormat(iAVtkWidget::defaultFormat());
#endif
Expand Down
2 changes: 1 addition & 1 deletion libs/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private slots:
// TDOO NEWIO: currently unused, but functionality should be available for any filter (general runner options - re-use transfer function, result in new/existing window, copy non-TF functions
void copyFunctions(MdiChild* oldChild, MdiChild* newChild);
void loadTLGICTData(QString const & baseDirectory);
void loadFileAskNewWindow(QString const& fileName);
iAMdiChild* askWhichChild();
bool keepOpen();
void loadArguments(int argc, char** argv);

Expand Down
17 changes: 17 additions & 0 deletions libs/gui/mdichild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ MdiChild::MdiChild(MainWindow* mainWnd, iAPreferences const& prefs, bool unsaved
m_interactionMode(imCamera),
m_nextDataSetID(0)
{
setAcceptDrops(true);
std::fill(m_slicerVisibility, m_slicerVisibility + 3, false);
setAttribute(Qt::WA_DeleteOnClose);
setDockOptions(dockOptions() | QMainWindow::GroupedDragging);
Expand Down Expand Up @@ -1318,6 +1319,22 @@ void MdiChild::closeEvent(QCloseEvent* event)
event->accept();
}

void MdiChild::dragEnterEvent(QDragEnterEvent* e)
{
if (e->mimeData()->hasUrls())
{
e->acceptProposedAction();
}
}

void MdiChild::dropEvent(QDropEvent* e)
{
for (const QUrl& url : e->mimeData()->urls())
{
m_mainWnd->loadFileNew(url.toLocalFile(), this);
}
}

void MdiChild::setWindowTitleAndFile(const QString& f)
{
QString title = f;
Expand Down
3 changes: 3 additions & 0 deletions libs/gui/mdichild.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ private slots:

private:
void closeEvent(QCloseEvent *event) override;
void dragEnterEvent(QDragEnterEvent* e) override;
void dropEvent(QDropEvent* e) override;

bool saveDataSet(std::shared_ptr<iADataSet> dataSet);
bool saveDataSet(std::shared_ptr<iADataSet> dataSet, QString const & fileName);
void set3DSlicePlanePos(int mode, int slice);
Expand Down

0 comments on commit 58b4291

Please sign in to comment.