src/mainwindow.cpp

changeset 8
44679e468ba9
parent 7
68443f5be176
child 9
8b9780700b5e
equal deleted inserted replaced
7:68443f5be176 8:44679e468ba9
5 #include <QMessageBox> 5 #include <QMessageBox>
6 #include "mainwindow.h" 6 #include "mainwindow.h"
7 #include "ui_mainwindow.h" 7 #include "ui_mainwindow.h"
8 #include "settingseditor/settingseditor.h" 8 #include "settingseditor/settingseditor.h"
9 #include "version.h" 9 #include "version.h"
10 #include "document.h"
10 11
11 MainWindow::MainWindow(QWidget *parent) : 12 MainWindow::MainWindow(QWidget *parent) :
12 QMainWindow{parent}, 13 QMainWindow{parent},
13 ui{std::make_unique<Ui_MainWindow>()}, 14 ui{std::make_unique<Ui_MainWindow>()},
14 documents{this}, 15 documents{this},
41 tr("Open model"), 42 tr("Open model"),
42 "", 43 "",
43 tr("LDraw models (*.ldr *.dat)")); 44 tr("LDraw models (*.ldr *.dat)"));
44 if (not path.isEmpty()) 45 if (not path.isEmpty())
45 { 46 {
46 QFile file{path}; 47 QString errorString;
47 const bool open_result = file.open(QIODevice::ReadOnly); 48 QTextStream errorStream{&errorString};
48 if (open_result) 49 QString modelName = this->documents.openModel(path, errorStream);
49 { 50 if (not modelName.isEmpty())
50 QMessageBox::critical(this, "Not implemented", "This functionality is not done yet"); 51 {
52 Document* document = new Document{this->documents.findModelByName(modelName)};
53 this->ui->tabs->addTab(document, modelName);
51 } 54 }
52 else 55 else
53 { 56 {
54 const QString errorString = format( 57 const QString errorMessage = utility::format(
55 tr("Could not open %1: %2"), 58 tr("Could not open %1: %2"),
56 path, 59 path,
57 file.errorString()); 60 errorString);
58 QMessageBox::critical(this, tr("Problem opening file"), errorString); 61 QMessageBox::critical(this, tr("Problem opening file"), errorMessage);
59 } 62 }
60 } 63 }
61 } 64 }
62 65
63 /** 66 /**

mercurial