2019-07-02 14:57:10 -07:00
|
|
|
#include "tycho.h"
|
|
|
|
|
2019-07-03 16:27:47 -07:00
|
|
|
static
|
|
|
|
ProjectModel *makeModel(Project *proj)
|
2019-07-03 16:23:04 -07:00
|
|
|
{
|
|
|
|
switch(proj->getType()) {
|
|
|
|
case ProjectType::Map: return new MapModel(proj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 16:27:47 -07:00
|
|
|
static
|
|
|
|
ProjectView *makeView(Project *proj)
|
2019-07-03 16:23:04 -07:00
|
|
|
{
|
|
|
|
switch(proj->getType()) {
|
|
|
|
case ProjectType::Map: return new MapView(proj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Project::Project(ProjectType _type) :
|
2019-07-02 18:16:34 -07:00
|
|
|
QMdiSubWindow(),
|
2019-07-03 16:23:04 -07:00
|
|
|
type(_type),
|
|
|
|
model(makeModel(this)),
|
|
|
|
view(makeView(this))
|
2019-07-02 14:57:10 -07:00
|
|
|
{
|
|
|
|
auto widget = new QWidget(this);
|
|
|
|
|
|
|
|
setupUi(widget);
|
|
|
|
|
|
|
|
setWidget(widget);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
2019-07-03 16:23:04 -07:00
|
|
|
listView->setModel(dynamic_cast<QAbstractItemModel *>(model));
|
|
|
|
verticalLayout->insertWidget(0, dynamic_cast<QWidget *>(view));
|
2019-07-02 18:16:34 -07:00
|
|
|
|
2019-07-03 16:23:04 -07:00
|
|
|
connect(listView,
|
|
|
|
SIGNAL(doubleClicked(QModelIndex const &)),
|
|
|
|
dynamic_cast<QObject *>(model),
|
|
|
|
SLOT(select(QModelIndex const &)));
|
2019-07-02 14:57:10 -07:00
|
|
|
|
|
|
|
dbgPrintFunc();
|
|
|
|
}
|
|
|
|
|
|
|
|
Project::~Project()
|
|
|
|
{
|
|
|
|
dbgPrintFunc();
|
|
|
|
}
|
|
|
|
|
2019-07-03 16:23:04 -07:00
|
|
|
ProjectType Project::getType() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectModel *Project::getModel() const
|
2019-07-02 17:22:25 -07:00
|
|
|
{
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
2019-07-03 16:23:04 -07:00
|
|
|
MapModel *Project::getMapModel() const
|
2019-07-02 17:22:25 -07:00
|
|
|
{
|
2019-07-03 16:23:04 -07:00
|
|
|
return dynamic_cast<MapModel *>(model);
|
2019-07-02 17:22:25 -07:00
|
|
|
}
|
|
|
|
|
2019-07-02 14:57:10 -07:00
|
|
|
void Project::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
if(model->isDirty()) {
|
|
|
|
QMessageBox msg;
|
|
|
|
msg.setText(tr("Do you want to save your changes to this project before closing it?"));
|
|
|
|
msg.setInformativeText(tr("Unsaved changes will be lost unless you save."));
|
|
|
|
msg.setStandardButtons(QMessageBox::Save |
|
|
|
|
QMessageBox::Discard |
|
|
|
|
QMessageBox::Cancel);
|
|
|
|
msg.setDefaultButton(QMessageBox::Save);
|
|
|
|
|
|
|
|
switch(msg.exec()) {
|
|
|
|
case QMessageBox::Save:
|
|
|
|
model->save();
|
|
|
|
break;
|
|
|
|
case QMessageBox::Discard:
|
|
|
|
break;
|
|
|
|
case QMessageBox::Cancel:
|
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
// EOF
|