Skip to content

Commit

Permalink
Quantor Results are now transferred to the UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredo Erxleben committed Mar 6, 2015
1 parent c9f41a5 commit eecc5e7
Show file tree
Hide file tree
Showing 18 changed files with 321 additions and 134 deletions.
7 changes: 6 additions & 1 deletion Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ Application::Application(int &argc, char** argv[])
this->m_appSettings = new QSettings();
this->checkSettings();

connect(this, &Application::signal_triggerQuantor,
// Application -> Quantor
connect(this, &Application::signal_quantorTriggered,
&m_quantorInterface, &quantor::QuantorInterface::slot_solveProblem);

// Quantor -> Application
connect(&m_quantorInterface, &quantor::QuantorInterface::signal_hasSolution,
this, &Application::signal_quantorSolutionAvailable);
}

Application::~Application() {
Expand Down
8 changes: 7 additions & 1 deletion Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ class Application : public QApplication {

static Application* instance();
signals:
void signal_triggerQuantor(Document* document, QString targetFunction);

// --- forwarded signals ---
// ApplicationContext -> Quantor
void signal_quantorTriggered(Document* document, QString targetFunction);

// Quantor -> ApplicationContext -> MainWindow
void signal_quantorSolutionAvailable(QString, const QMap<QString, bool>*);

public slots:
void slot_resetSettings();
Expand Down
8 changes: 7 additions & 1 deletion ApplicationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ ApplicationContext::setupSignalsAndSlots() {
connect(this, &ApplicationContext::signal_showDocument,
m_mainWindow, static_cast<void (MainWindow::*)(Document*)>
(&MainWindow::slot_openDocumentTab)); // ship around overloaded function
connect(this, &ApplicationContext::signal_quantorSolutionAvailable,
m_mainWindow, &MainWindow::slot_displayQuantorResult);
// saving signal has to be set up by project

// ApplicationContext -> ComponentFactory
Expand All @@ -90,7 +92,11 @@ ApplicationContext::setupSignalsAndSlots() {

// ApplicationContext -> Application
connect(this, &ApplicationContext::signal_triggerQuantor,
m_application, &Application::signal_triggerQuantor);
m_application, &Application::signal_quantorTriggered);

// Application -> ApplicationContext
connect(m_application, &Application::signal_quantorSolutionAvailable,
this, &ApplicationContext::signal_quantorSolutionAvailable);

}

Expand Down
2 changes: 2 additions & 0 deletions ApplicationContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ class ApplicationContext : public QObject {
void signal_clearComponentTypes();
void signal_triggerQuantor(Document* document, QString targetFunction);


// forwarding signal to MainWindow
void signal_showDocument(Document* document);
void signal_quantorSolutionAvailable(QString, const QMap<QString, bool>*);

public slots:
void slot_newDocument(QString name);
Expand Down
39 changes: 39 additions & 0 deletions MapModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "MapModel.h"

using namespace q2d::util;

MapModel::MapModel(QObject *parent) :
QAbstractTableModel(parent)
{
m_map = nullptr;
}

int MapModel::rowCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
if (m_map)
return m_map->count();
return 0;
}

int MapModel::columnCount(const QModelIndex & parent) const
{
Q_UNUSED(parent);
return 2;
}

QVariant MapModel::data(const QModelIndex& index, int role) const
{
if (m_map == nullptr)
return QVariant();
if (index.row() < 0 ||
index.row() >= m_map->count() ||
role != Qt::DisplayRole) {
return QVariant();
}
if (index.column() == 0)
return m_map->keys().at(index.row());
if (index.column() == 1)
return m_map->values().at(index.row());
return QVariant();
}
40 changes: 40 additions & 0 deletions MapModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef MAPMODEL_H
#define MAPMODEL_H

#include <QAbstractTableModel>
#include <QMap>

/**
* @brief The MapModel class
* @author mhcuervo
*
* COPYRIGHT NOTICE: this class was originally written by mhcuervo as posted on
* http://stackoverflow.com/questions/23484511/how-to-display-a-simple-qmap-in-a-qtableview-in-qt
* Changes were made due to refactoring and adaption to the concrete use case.
*/
namespace q2d {
namespace util {

class MapModel : public QAbstractTableModel
{
Q_OBJECT
private:
const QMap<QString, bool>* m_map;
public:

enum MapRoles {
KeyRole = Qt::UserRole + 1,
ValueRole
};

explicit MapModel(QObject *parent = 0);
int rowCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
inline void setMap(const QMap<QString, bool>* map) { m_map = map; }
};

}
}

#endif // MAPMODEL_H
35 changes: 25 additions & 10 deletions gui/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "MainWindow.h"
#include "ui_MainWindow.h"

#include "Application.h"
#include "Document.h"
#include "metamodel/Category.h"
#include "ComponentFactory.h"
#include "Constants.h"
#include "gui/SchematicsTab.h"
#include "../Application.h"
#include "../Document.h"
#include "../metamodel/Category.h"
#include "../ComponentFactory.h"
#include "../Constants.h"
#include "SchematicsTab.h"

#include <QFileDialog>
#include <QInputDialog>
Expand All @@ -23,11 +23,10 @@ MainWindow::MainWindow(ApplicationContext* parent) :
QMainWindow(), m_ui(new Ui::MainWindow) {

Q_CHECK_PTR(parent);
this->m_context = parent;

m_context = parent;
m_ui->setupUi(this);

this->m_application = qobject_cast<Application*>(Application::instance());
m_application = qobject_cast<Application*>(Application::instance());
m_resultDialog = nullptr;
}

MainWindow::~MainWindow() {}
Expand Down Expand Up @@ -317,3 +316,19 @@ MainWindow::on_btn_addCategory_clicked() {
// add a new category
emit this->signal_createCategory(name, parent);
}

void
MainWindow::slot_displayQuantorResult(QString textualRepresentation, const QMap<QString, bool>* resultMapping){

qDebug() << "Show Quantor result dialog";
// TODO extend the result dialog so the instance can be reused,
// instead of been created anew every time
if(m_resultDialog != nullptr){
delete m_resultDialog;
m_resultDialog = nullptr;
}
m_resultDialog = new QuantorResultDialog(this, textualRepresentation, resultMapping);
m_resultDialog->show();
m_resultDialog->raise();
m_resultDialog->activateWindow();
}
5 changes: 4 additions & 1 deletion gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define MAINWINDOW_H

#include "ui_MainWindow.h"

#include "QuantorResultDialog.h"
#include "metamodel/Category.h"

#include <QDir>
Expand All @@ -31,6 +31,8 @@ class MainWindow : public QMainWindow {
q2d::Application* m_application;
q2d::ApplicationContext* m_context;

QuantorResultDialog* m_resultDialog;


void addNewSchematicsTab(Document* relatedDocument);
public:
Expand Down Expand Up @@ -65,6 +67,7 @@ public slots:
void slot_openDocumentTab(const QModelIndex index);
void slot_openDocumentTab(Document* document);
void slot_setComponentModel(QStandardItemModel* model);
void slot_displayQuantorResult(QString textualRepresentation, const QMap<QString, bool>* resultMapping);

private slots:
// created by the Qt Designer
Expand Down
85 changes: 0 additions & 85 deletions gui/QuantorResult.ui

This file was deleted.

23 changes: 23 additions & 0 deletions gui/QuantorResultDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "QuantorResultDialog.h"
#include "ui_QuantorResultDialog.h"

#include "../MapModel.h"

#include <QAbstractTableModel>

QuantorResultDialog::QuantorResultDialog(QWidget *parent, QString resultText, const QMap<QString, bool>* resultMapping) :
QDialog(parent),
m_ui(new Ui::QuantorResultDialog)
{
m_ui->setupUi(this);
m_ui->lbl_resultText->setText(resultText);
q2d::util::MapModel* model = new q2d::util::MapModel(this);
model->setMap(resultMapping);
m_ui->table_Assignments->setModel(model);
}

QuantorResultDialog::~QuantorResultDialog()
{
m_ui->table_Assignments->model()->deleteLater();
delete m_ui;
}
20 changes: 20 additions & 0 deletions gui/QuantorResultDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef QUANTORRESULTDIALOG_H
#define QUANTORRESULTDIALOG_H

#include <QDialog>

namespace Ui {
class QuantorResultDialog;
}

class QuantorResultDialog : public QDialog
{
Q_OBJECT
private:
Ui::QuantorResultDialog *m_ui;
public:
explicit QuantorResultDialog(QWidget *parent, QString resultText, const QMap<QString, bool>* resultMapping);
~QuantorResultDialog();
};

#endif // QUANTORRESULTDIALOG_H
42 changes: 42 additions & 0 deletions gui/QuantorResultDialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QuantorResultDialog</class>
<widget class="QDialog" name="QuantorResultDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="lbl_result">
<property name="text">
<string>Result:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbl_resultText">
<property name="text">
<string>(NONE)</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableView" name="table_Assignments"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Loading

0 comments on commit eecc5e7

Please sign in to comment.