Skip to content

Commit

Permalink
Add New in Menu (#5650)
Browse files Browse the repository at this point in the history
* Add New in Menu
  • Loading branch information
boutinb authored and JorisGoosen committed Sep 30, 2024
1 parent 8e00f8e commit 3f48d69
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 28 deletions.
5 changes: 5 additions & 0 deletions Desktop/data/asyncloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void AsyncLoader::io(FileEvent *event)

switch (event->operation())
{
case FileEvent::FileNew:
emit progress(tr("Loading New Data Set"), 0);
emit beginLoad(event);
break;

case FileEvent::FileOpen:
emit progress(tr("Loading Data Set"), 0);
emit beginLoad(event);
Expand Down
2 changes: 1 addition & 1 deletion Desktop/data/fileevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FileEvent : public QObject
Q_OBJECT

public:
enum FileMode { FileSave, FileOpen, FileExportResults, FileExportData, FileGenerateData, FileSyncData, FileClose };
enum FileMode { FileSave, FileNew, FileOpen, FileExportResults, FileExportData, FileGenerateData, FileSyncData, FileClose };

FileEvent(QObject *parent = nullptr, FileMode fileMode = FileEvent::FileOpen);
virtual ~FileEvent();
Expand Down
17 changes: 7 additions & 10 deletions Desktop/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ bool runJaspEngineJunctionFixer(int argc, char *argv[], bool removeJunctions = f
#endif


void parseArguments(int argc, char *argv[], std::string & filePath, bool & unitTest, bool & dirTest, int & timeOut, bool & save, bool & logToFile, bool & hideJASP, bool & safeGraphics, Json::Value & dbJson, QString & reportingDir)
void parseArguments(int argc, char *argv[], std::string & filePath, bool & newData, bool & unitTest, bool & dirTest, int & timeOut, bool & save, bool & logToFile, bool & hideJASP, bool & safeGraphics, Json::Value & dbJson, QString & reportingDir)
{
filePath = "";
unitTest = false;
Expand All @@ -130,6 +130,7 @@ void parseArguments(int argc, char *argv[], std::string & filePath, bool & unitT
logToFile = false;
hideJASP = false;
safeGraphics = false;
newData = false;
reportingDir = "";
timeOut = 10;
dbJson = Json::nullValue;
Expand All @@ -145,6 +146,7 @@ void parseArguments(int argc, char *argv[], std::string & filePath, bool & unitT
else if(args[arg] == "--logToFile") logToFile = true;
else if(args[arg] == "--hide") hideJASP = true;
else if(args[arg] == "--safeGraphics") safeGraphics = true;
else if(args[arg] == "--newData") newData = true;
#ifdef _WIN32
else if(args[arg] == junctionArg) runJaspEngineJunctionFixer(argc, argv, false); //Run the junctionfixer, it will exit the application btw!
else if(args[arg] == removeJunctionsArg) runJaspEngineJunctionFixer(argc, argv, true); //Remove the junctions
Expand Down Expand Up @@ -408,15 +410,16 @@ int main(int argc, char *argv[])
save,
logToFile,
hideJASP,
safeGraphics;
safeGraphics,
newData;
int timeOut;
Json::Value dbJson;

QCoreApplication::setOrganizationName("JASP");
QCoreApplication::setOrganizationDomain("jasp-stats.org");
QCoreApplication::setApplicationName("JASP");

parseArguments(argc, argv, filePath, unitTest, dirTest, timeOut, save, logToFile, hideJASP, safeGraphics, dbJson, reportingDir);
parseArguments(argc, argv, filePath, newData, unitTest, dirTest, timeOut, save, logToFile, hideJASP, safeGraphics, dbJson, reportingDir);

if(safeGraphics) Settings::setValue(Settings::SAFE_GRAPHICS_MODE, true);
else safeGraphics = Settings::value(Settings::SAFE_GRAPHICS_MODE).toBool();
Expand Down Expand Up @@ -448,12 +451,6 @@ int main(int argc, char *argv[])
args.push_back("minimal");
}

if(hideJASP)
{
args.push_back("-platform");
args.push_back("minimal");
}

PlotSchemeHandler::createUrlScheme(); //Needs to be done *before* creating PlotSchemeHandler instance and also before QApplication is instantiated
ImgSchemeHandler::createUrlScheme();

Expand Down Expand Up @@ -526,7 +523,7 @@ int main(int argc, char *argv[])
msgBox->hide();
}
#endif
a.init(filePathQ, unitTest, timeOut, save, logToFile, dbJson, reportingDir);
a.init(filePathQ, newData, unitTest, timeOut, save, logToFile, dbJson, reportingDir);

try
{
Expand Down
23 changes: 19 additions & 4 deletions Desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ void MainWindow::makeConnections()

connect(_ribbonModel, &RibbonModel::analysisClickedSignal, _analyses, &Analyses::analysisClickedHandler );
connect(_ribbonModel, &RibbonModel::showRCommander, this, &MainWindow::showRCommander );
connect(_ribbonModel, &RibbonModel::generateEmptyData, _package, &DataSetPackage::generateEmptyData );
connect(_ribbonModel, &RibbonModel::dataModeChanged, _package, &DataSetPackage::dataModeChanged );
connect(_ribbonModel, &RibbonModel::setDataSynchronisation, _package, &DataSetPackage::setSynchingExternallyFriendly );

Expand Down Expand Up @@ -728,7 +727,7 @@ void MainWindow::loadQML()
connect(_ribbonModel, &RibbonModel::dataUndo, DataSetView::mainDataViewer(), &DataSetView::undo);
connect(_ribbonModel, &RibbonModel::dataRedo, DataSetView::mainDataViewer(), &DataSetView::redo);
connect(this, &MainWindow::resizeData, DataSetView::mainDataViewer(), &DataSetView::resizeData);

connect(_ribbonModel, &RibbonModel::showNewData, this, &MainWindow::showNewData);

//connect(DataSetView::lastInstancedDataSetView(), &DataSetView::selectionStartChanged, _columnModel, &ColumnModel::changeSelectedColumn);

Expand Down Expand Up @@ -903,6 +902,11 @@ void MainWindow::open(QString filepath)
else _openOnLoadFilename = filepath;
}

void MainWindow::showNewData()
{
_package->generateEmptyData();
_ribbonModel->showData();
}

void MainWindow::open(const Json::Value & dbJson)
{
Expand Down Expand Up @@ -1176,7 +1180,14 @@ void MainWindow::connectFileEventCompleted(FileEvent * event)

void MainWindow::dataSetIORequestHandler(FileEvent *event)
{
if (event->operation() == FileEvent::FileOpen)
if (event->operation() == FileEvent::FileNew)
{
if (_package->isLoaded())
QProcess::startDetached(QCoreApplication::applicationFilePath(), QStringList("--newData"));
else
showNewData();
}
else if (event->operation() == FileEvent::FileOpen)
{
if (_package->isLoaded())
{
Expand Down Expand Up @@ -1302,7 +1313,10 @@ void MainWindow::dataSetIOCompleted(FileEvent *event)
{
hideProgress();

if (event->operation() == FileEvent::FileOpen)
if (event->operation() == FileEvent::FileNew)
{
}
else if (event->operation() == FileEvent::FileOpen)
{
if (event->isSuccessful())
{
Expand Down Expand Up @@ -1468,6 +1482,7 @@ void MainWindow::qmlLoaded()
{
Log::log() << "MainWindow::qmlLoaded()" << std::endl;
_qmlLoaded = true;
emit qmlLoadedChanged();

handleDeferredFileLoad();
}
Expand Down
2 changes: 2 additions & 0 deletions Desktop/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class MainWindow : public QObject

static MainWindow * singleton() { return _singleton; }

void showNewData();
void open(QString filepath);
void open(const Json::Value & dbJson);
void testLoadedJaspFile(int timeOut, bool save);
Expand Down Expand Up @@ -249,6 +250,7 @@ public slots:
void communityVisibleChanged();
void contactTextChanged();
void resizeData(int row, int col);
void qmlLoadedChanged();

private slots:
void resultsPageLoaded();
Expand Down
2 changes: 1 addition & 1 deletion Desktop/modules/ribbonmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void RibbonModel::addSpecialRibbonButtonsEarly()

_analysesButton = new RibbonButton(this, "Analyses", fq(tr("Analyses")), "JASP_logo_green.svg", false, [&](){ emit finishCurrentEdit(); emit showStatistics(); }, fq(tr("Switch JASP to analyses mode")), true);
_dataSwitchButton = new RibbonButton(this, "Data", fq(tr("Edit Data")), "data-button.svg", false, [&](){ emit showData(); }, fq(tr("Switch JASP to data editing mode")), false, false, false);
_dataNewButton = new RibbonButton(this, "Data-New", fq(tr("New Data")), "data-button-new.svg", false, [&](){ emit genShowEmptyData(); }, fq(tr("Open a workspace without data")), true, false, false);
_dataNewButton = new RibbonButton(this, "Data-New", fq(tr("New Data")), "data-button-new.svg", false, [&](){ emit showNewData(); }, fq(tr("Open a workspace without data")), true, false, false);
_dataResizeButton = new RibbonButton(this, "Data-Resize", fq(tr("Resize Data")), "data-button-resize.svg", false, [&](){ emit resizeData(); }, fq(tr("Resize your dataset")), false);
_insertButton = new RibbonButton(this, "Data-Insert", fq(tr("Insert")), "data-button-insert.svg", _entriesInsert, fq(tr("Insert empty columns or rows")));
_removeButton = new RibbonButton(this, "Data-Remove", fq(tr("Remove")), "data-button-erase.svg", _entriesDelete, fq(tr("Remove columns or rows")));
Expand Down
3 changes: 1 addition & 2 deletions Desktop/modules/ribbonmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class RibbonModel : public QAbstractListModel
void setDataMode(bool data);
Q_INVOKABLE void showData() { setCurrentRow(int(RowType::Data)); }
Q_INVOKABLE void showStatistics() { setCurrentRow(int(RowType::Analyses)); }
void genShowEmptyData() { generateEmptyData(); showData(); }

void removeRibbonButtonModel(std::string moduleName);

Expand Down Expand Up @@ -105,7 +104,6 @@ class RibbonModel : public QAbstractListModel
void invalidateFilterModel();
void currentRowChanged();
void dataLoadedChanged(bool loaded);
void generateEmptyData();
void dataModeChanged(bool dataMode);
void startExternalEdit();
void stopExternalEdit();
Expand All @@ -124,6 +122,7 @@ class RibbonModel : public QAbstractListModel
void cellsClear();
void dataUndo();
void dataRedo();
void showNewData();

public slots:
void addRibbonButtonModelFromDynamicModule(Modules::DynamicModule * module);
Expand Down
26 changes: 18 additions & 8 deletions Desktop/utilities/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "utilities/settings.h"
#include <iostream>

void Application::init(QString filePath, bool unitTest, int timeOut, bool save, bool logToFile, const Json::Value & dbJson, QString reportingPath)
void Application::init(QString filePath, bool newData, bool unitTest, int timeOut, bool save, bool logToFile, const Json::Value & dbJson, QString reportingPath)
{
std::cout << "Application init entered" << std::endl;

Expand All @@ -36,14 +36,24 @@ void Application::init(QString filePath, bool unitTest, int timeOut, bool save,

_mainWindow = new MainWindow(this);

if(unitTest)
_mainWindow->testLoadedJaspFile(timeOut, save);
connect(_mainWindow, &MainWindow::qmlLoadedChanged, this, [=]() {
// The QML files are not yet laoded when MainWindow is just created (loadQML is called via a QTmer::singleShot)
// But to correctly work, the following calls need the QML files to be loaded.
if (newData)
_mainWindow->showNewData();
else
{
if(unitTest)
_mainWindow->testLoadedJaspFile(timeOut, save);

if(filePath.size() > 0)
_mainWindow->open(filePath);

if(!dbJson.isNull())
_mainWindow->open(dbJson);
if(filePath.size() > 0)
_mainWindow->open(filePath);

if(!dbJson.isNull())
_mainWindow->open(dbJson);
}

});

if(reportingPath != "")
_mainWindow->reportHere(reportingPath);
Expand Down
2 changes: 1 addition & 1 deletion Desktop/utilities/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Application : public QApplication

virtual bool notify(QObject *receiver, QEvent *event) OVERRIDE;
virtual bool event(QEvent *event) OVERRIDE;
void init(QString filePath, bool unitTest, int timeOut, bool save, bool logToFile, const Json::Value & dbJson, QString reportingPath);
void init(QString filePath, bool newData, bool unitTest, int timeOut, bool save, bool logToFile, const Json::Value & dbJson, QString reportingPath);

signals:

Expand Down
1 change: 1 addition & 0 deletions Desktop/widgets/filemenu/actionbuttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void ActionButtons::loadButtonData()

_data =
{
{FileOperation::New, tr("New"), true, {} },
{FileOperation::Open, tr("Open"), true, {ResourceButtons::Computer, ResourceButtons::OSF, ResourceButtons::Database, ResourceButtons::RecentFiles, ResourceButtons::DataLibrary } },
{FileOperation::Save, tr("Save"), false, {} },
{FileOperation::SaveAs, tr("Save As"), false, {ResourceButtons::Computer, ResourceButtons::OSF } },
Expand Down
2 changes: 1 addition & 1 deletion Desktop/widgets/filemenu/actionbuttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ActionButtons : public QAbstractListModel
Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged )

public:
enum FileOperation {None = 0, Open, Save, SaveAs, ExportResults, ExportData, SyncData, Close, Preferences, Contact, Community, About};
enum FileOperation {None = 0, New, Open, Save, SaveAs, ExportResults, ExportData, SyncData, Close, Preferences, Contact, Community, About};
Q_ENUM(FileOperation)

struct DataRow { FileOperation operation; QString name; bool enabled; std::set<ResourceButtons::ButtonType> resourceButtons; };
Expand Down
13 changes: 13 additions & 0 deletions Desktop/widgets/filemenu/filemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ FileMenu::FileMenu(QObject *parent) : QObject(parent)
connect(_resourceButtons, &ResourceButtons::selectedButtonChanged, this, &FileMenu::resourceButtonClicked );
connect(_currentDataFile, &CurrentDataFile::setCheckAutomaticSync, _mainWindow, &MainWindow::setCheckAutomaticSync );

_actionButtons->setEnabled(ActionButtons::New, true);
_actionButtons->setEnabled(ActionButtons::Open, true);
_actionButtons->setEnabled(ActionButtons::Save, false);
_actionButtons->setEnabled(ActionButtons::SaveAs, false);
Expand Down Expand Up @@ -116,6 +117,15 @@ FileEvent *FileMenu::saveAs()
return _computer->browseSave();
}

FileEvent *FileMenu::newData()
{
FileEvent *event = new FileEvent(this, FileEvent::FileNew);

dataSetIORequestHandler(event);

return event;
}

FileEvent *FileMenu::save()
{
FileEvent *event = nullptr;
Expand Down Expand Up @@ -410,6 +420,9 @@ void FileMenu::actionButtonClicked(const ActionButtons::FileOperation action)
else
setMode(FileEvent::FileSave);
break;
case ActionButtons::FileOperation::New:
newData();
break;

case ActionButtons::FileOperation::About:
setVisible(false);
Expand Down
1 change: 1 addition & 0 deletions Desktop/widgets/filemenu/filemenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class FileMenu : public QObject
void setResourceButtonsVisibleFor(FileOperation fo);

void setOnlineDataManager(OnlineDataManager *odm);
FileEvent * newData();
FileEvent * open(const QString &filepath);
FileEvent * open(const Json::Value & databaseInfo);
FileEvent * save();
Expand Down

0 comments on commit 3f48d69

Please sign in to comment.