Skip to content
Open
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
53 changes: 43 additions & 10 deletions Desktop/components/JASP/Widgets/MainWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,58 @@ Window
return (a + n) % n;
}

DropArea
{
id: drop
enabled: true
anchors.fill: parent
onDropped: (drop) => mainWindow.openURLFile(drop.text)
}

Item
{
anchors.fill: parent

Rectangle
{
id: warningRect
z: 1
visible: mainWindow.hadFatalError
color: jaspTheme.red
color: mainWindow.hadFatalError ? jaspTheme.red : "transparent"
opacity: 0.75
anchors.fill: parent

DropArea
{
enabled: true
anchors.fill: parent
onDropped: (drop) =>
{
if (mainWindow.openURLFile(drop.text))
drop.accepted = true
parent.state = ""
}

onExited: parent.state = ""
onEntered: (drag) =>
{
if (drag.hasText)
parent.state = "active"
}
}

states: [
State {
name: "active"
PropertyChanges {
warningRect {
color: jaspTheme.blueLighter
}
}
}
]

transitions: [
Transition {
from: ""
to: "active"
reversible: true
ColorAnimation { properties: "color"; duration: 150; easing.type: Easing.InOutQuad }
}
]


}

Shortcut { onActivated: mainWindow.showEnginesWindow(); sequences: ["Ctrl+Alt+Shift+E"]; context: Qt.ApplicationShortcut; }
Expand Down
2 changes: 1 addition & 1 deletion Desktop/data/datasetpackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2523,7 +2523,7 @@ bool DataSetPackage::filePathIsNonSaveable(const QString & path) const
{
QFileInfo fileDir(path);

return fileDir.dir() == QDir(AppDirs::examples()) || fileDir.dir() == QDir(AppDirs::autoSaveDir());
return path.startsWith(AppDirs::examples()) || fileDir.dir() == QDir(AppDirs::autoSaveDir());
}

void DataSetPackage::setAnalysesData(const Json::Value &analysesData)
Expand Down
56 changes: 50 additions & 6 deletions Desktop/data/fileevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
#include "exporters/dataexporter.h"
#include "exporters/jaspexporter.h"
#include "exporters/resultexporter.h"
#include "widgets/filemenu/filemenu.h"
#include "log.h"


FileEvent::FileEvent(QObject *parent, FileEvent::FileMode fileMode)
FileEvent::FileEvent(FileMenu *parent, FileEvent::FileMode fileMode)
: QObject(parent), _operation(fileMode)
{
switch (_operation)
Expand All @@ -36,6 +37,9 @@ FileEvent::FileEvent(QObject *parent, FileEvent::FileMode fileMode)
case FileEvent::FileSave: _exporter = new JASPExporter(); break;
default: _exporter = nullptr; break;
}

// The FileMenu handles the started signal
connect(this, &FileEvent::started, parent, &FileMenu::fileEventRequestDispatcher);
}

FileEvent::~FileEvent()
Expand Down Expand Up @@ -93,19 +97,59 @@ bool FileEvent::setPath(const QString & path)

}

void FileEvent::setStarted()
{
if (isStarted())
{
Log::log() << "Try to start event '" << getProgressMsg().toStdString() << "', but it was already started!" << std::endl;
return;
}

_status = EventStatus::EventStarted;

emit started();
}

void FileEvent::setComplete(bool success, const QString & message)
{
_completed = true;
if (isCompleted())
{
Log::log() << "Try to set complete event '" << getProgressMsg().toStdString() << "', but it was already completed!" << std::endl;
return;
}

_status = EventStatus::EventCompleted;
_success = success;
_message = message;

emit completed(this);
emit completed();
}

void FileEvent::setFinalized()
{
if (isFinalized())
{
Log::log() << "Try to set finalize event '" << getProgressMsg().toStdString() << "', but it was already finalized!" << std::endl;
return;
}

_status = EventStatus::EventFinalized;
emit finalized();
deleteLater();
}


void FileEvent::chain(FileEvent *event)
{
_chainedTo = event;
connect(event, &FileEvent::completed, this, &FileEvent::chainedComplete);
if (isStarted())
{
if (isCompleted())
Log::log() << "Event " << getProgressMsg().toStdString() << " is completed before Event " << event->getProgressMsg().toStdString() << " was completed" << std::endl;
else // The `this` event is already started, but it should be set complete (and start the finalize process) only when `event` is finalized
connect(event, &FileEvent::finalized, this, [this, event]() { setComplete(event->isSuccessful(), event->message()); });
}
else
connect(event, &FileEvent::finalized, this, [this, event]() { if (event->isSuccessful()) emit started(); } );
}

bool FileEvent::isExample() const
Expand Down
24 changes: 15 additions & 9 deletions Desktop/data/fileevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "exporters/exporter.h"
#include "utilenums.h"

class FileMenu;

///
/// This class is used to handle the communication to and from the asynchronous loading/synching/saving file processes.
/// These can be chained to have a Close come after a save once the latter is done.
Expand All @@ -34,8 +36,10 @@ class FileEvent : public QObject

public:
enum FileMode { FileSave, FileNew, FileOpen, FileExportResults, FileExportData, FileGenerateData, FileSyncData, FileClose };
enum EventStatus { EventInitialized, EventStarted, EventCompleted, EventFinalized };


FileEvent(QObject *parent = nullptr, FileMode fileMode = FileEvent::FileOpen);
FileEvent(FileMenu *parent, FileMode fileMode = FileEvent::FileOpen);
virtual ~FileEvent();

bool setPath( const QString & path);
Expand All @@ -45,14 +49,18 @@ class FileEvent : public QObject
void setFileType( Utils::FileType type) { _type = type; }
void setTmp( bool saveTmp) { _tmp = saveTmp; }

void setStarted();
void setComplete(bool success = true, const QString &message = "");
void setFinalized();
void chain(FileEvent *event);

bool isDatabase() const { return _database != Json::nullValue; }
bool isOnlineNode() const { return _path.startsWith("http"); }
bool isExample() const;
bool isReadOnly() const { return isExample() || isDatabase(); }
bool isCompleted() const { return _completed; }
bool isStarted() const { return _status != EventStatus::EventInitialized; }
bool isCompleted() const { return _status == EventStatus::EventCompleted || _status == EventStatus::EventFinalized; }
bool isFinalized() const { return _status == EventStatus::EventFinalized; }
bool isSuccessful() const { return _success; }
bool isTmp() const { return _tmp; }
static bool autoSaveExists();
Expand All @@ -74,10 +82,9 @@ class FileEvent : public QObject
QString getProgressMsg() const;

signals:
void completed(FileEvent *event);

private slots:
void chainedComplete(FileEvent *event) { setComplete(event->isSuccessful(), event->message()); }
void started();
void completed();
void finalized();

private:
FileMode _operation;
Expand All @@ -87,10 +94,9 @@ private slots:
_dataFilePath,
_last_error = "Unknown error",
_message;
bool _completed = false,
_success = false,
EventStatus _status = EventStatus::EventInitialized;
bool _success = false,
_tmp = false;
FileEvent * _chainedTo = nullptr;
Exporter * _exporter = nullptr;
Json::Value _database = Json::nullValue;
};
Expand Down
Loading
Loading