Ejemplo n.º 1
0
void MainWindow::on_openProject_triggered()
{
    int msg;

    if(project != nullptr && !project->getSaved())
    {
        msg = NotSavedMessage();

        if(msg == QMessageBox::Cancel)
        {
            return;
        }
        else if(msg == QMessageBox::Save)
        {
            on_saveProject_triggered();

            if(!project->getSaved())
            {
                return;
            }
        }
    }

    QString filename = QFileDialog::getOpenFileName(this,tr("Load Project"), ".", tr(".json Files (*.json)"));

    if(filename != "")
    {
        std::cout << "Open project:" << filename.toStdString() << std::endl;

        if(!searchForRecentProjects(filename))
        {
            recentProjects.push_back(filename);
        }

        QFile file(filename);
        file.open(QFile::OpenModeFlag::ReadOnly);

        QJsonDocument doc = QJsonDocument::fromJson(file.readAll());

        QVariantMap map = doc.toVariant().toMap();

        Room* temp = new Room();
        temp->fromVariantMap(ui->OpenGLWIndow , map);

        file.close();

        editProject(temp);
    }

}
Ejemplo n.º 2
0
void MainWindow::OpenRecentProjects()
{
    QObject * sender = QObject::sender();

    for(int i = 0; i < recentProjectsQActions.size(); i++)
    {
        if(recentProjectsQActions.at(i) == sender)
        {
            int msg;

            if(project != nullptr && !project->getSaved())
            {
                msg = NotSavedMessage();

                if(msg == QMessageBox::Cancel)
                {
                    return;
                }
                else if(msg == QMessageBox::Save)
                {
                    on_saveProject_triggered();

                    if(!project->getSaved())
                    {
                        return;
                    }
                }
            }

            QFile file(recentProjects[i]);
            file.open(QFile::OpenModeFlag::ReadOnly);

            QJsonDocument doc = QJsonDocument::fromJson(file.readAll());

            QVariantMap map = doc.toVariant().toMap();

            Room * temp = new Room();
            temp->fromVariantMap(ui->OpenGLWIndow , map);

            file.close();

            editProject(temp);
        }
    }
}