Skip to content

Commit

Permalink
added basic view and presenter implementations, re #12610
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeMPouzols committed Aug 3, 2015
1 parent 175fb8d commit 316a290
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "MantidAPI/MatrixWorkspace.h"
// #include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionModel.h"
#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h"
#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h"

#include <boost/lexical_cast.hpp>

using namespace Mantid::API;
using namespace MantidQt::CustomInterfaces;

namespace MantidQt {
namespace CustomInterfaces {

EnggDiffractionPresenter::EnggDiffractionPresenter(IEnggDiffractionView *view)
: m_view(view) /*, m_model(new EnggDiffractionModel()), */ {
if (!m_view) {
throw std::runtime_error(
"Severe inconsistency found. Presenter created "
"with an empty/null view (engineeering diffraction interface). "
"Cannot continue.");
}
}

EnggDiffractionPresenter::~EnggDiffractionPresenter() { cleanup(); }

/**
* Close open sessions, kill threads etc., save settings, etc. for a
* graceful window close/destruction
*/
void EnggDiffractionPresenter::cleanup() {
// m_model->cleanup();
}

void EnggDiffractionPresenter::notify(
IEnggDiffractionPresenter::Notification notif) {

switch (notif) {

case IEnggDiffractionPresenter::Start:
processStart();
break;

case IEnggDiffractionPresenter::LoadExistingCalib:
processLoadExistingCalib();
break;

case IEnggDiffractionPresenter::CalcCalib:
processCalcCalib();
break;

case IEnggDiffractionPresenter::LogMsg:
processLogMsg();
break;

case IEnggDiffractionPresenter::ShutDown:
processShutDown();
break;
}
}

void EnggDiffractionPresenter::processStart() {
std::vector<std::string> msgs = m_view->logMsgs();
for (size_t i = 0; i < msgs.size(); i++) {
//m_model->logMsg(msgs[i]);
}
}

void EnggDiffractionPresenter::processLoadExistingCalib() {}

void EnggDiffractionPresenter::processCalcCalib() {}

void EnggDiffractionPresenter::processLogMsg() {}

void EnggDiffractionPresenter::processShutDown() {
m_view->saveSettings();
cleanup();
}

} // namespace CustomInterfaces
} // namespace MantidQt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include "MantidQtAPI/AlgorithmRunner.h"
#include "MantidQtAPI/HelpWindow.h"
#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h"
#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h"

using namespace Mantid::API;
using namespace MantidQt::CustomInterfaces;

#include <boost/lexical_cast.hpp>

#include <QCheckBox>
#include <QCloseEvent>
#include <QMessageBox>
#include <QSettings>

namespace MantidQt {
namespace CustomInterfaces {

// Add this class to the list of specialised dialogs in this namespace
DECLARE_SUBWINDOW(EnggDiffractionViewQtGUI)

/**
* Default constructor.
*
* @param parent Parent window (most likely the Mantid main app window).
*/
EnggDiffractionViewQtGUI::EnggDiffractionViewQtGUI(QWidget *parent)
: UserSubWindow(parent), IEnggDiffractionView(), m_presenter(NULL) {}

EnggDiffractionViewQtGUI::~EnggDiffractionViewQtGUI() {}

void EnggDiffractionViewQtGUI::initLayout() {
// setup container ui
m_ui.setupUi(this);
// add tab contents and set up their ui's
QWidget *wCalib = new QWidget(m_ui.tabMain);
m_uiTabCalib.setupUi(wCalib);
m_ui.tabMain->addTab(wCalib, QString("Calibration"));
QWidget *wSettings = new QWidget(m_ui.tabMain);
m_uiTabSettings.setupUi(wSettings);
m_ui.tabMain->addTab(wSettings, QString("Setup"));

readSettings();

// basic UI setup
doSetupTabCalib();
doSetupTabSettings();

// presenter that knows how to handle a IEnggDiffractionView should take care
// of all the logic
// note that the view needs to know the concrete presenter
m_presenter.reset(new EnggDiffractionPresenter(this));

// it will know what compute resources and tools we have available:
// This view doesn't even know the names of compute resources, etc.
m_presenter->notify(IEnggDiffractionPresenter::Start);
}

void EnggDiffractionViewQtGUI::doSetupTabCalib() {}

void EnggDiffractionViewQtGUI::doSetupTabSettings() {}

void EnggDiffractionViewQtGUI::readSettings() {}

void EnggDiffractionViewQtGUI::saveSettings() const {}

void EnggDiffractionViewQtGUI::userWarning(const std::string &err,
const std::string &description) {
QMessageBox::warning(this, QString::fromStdString(err),
QString::fromStdString(description), QMessageBox::Ok,
QMessageBox::Ok);
}

void EnggDiffractionViewQtGUI::userError(const std::string &err,
const std::string &description) {
QMessageBox::critical(this, QString::fromStdString(err),
QString::fromStdString(description), QMessageBox::Ok,
QMessageBox::Ok);
}

std::string EnggDiffractionViewQtGUI::getRBNumber() const {
return "not available";
}

void EnggDiffractionViewQtGUI::loadCalibrationClicked() {}

void EnggDiffractionViewQtGUI::closeEvent(QCloseEvent *event) {
int answer = QMessageBox::AcceptRole;

QMessageBox msgBox;
msgBox.setWindowTitle("Close the engineering diffraction interface");
// with something like this, we'd have layout issues:
// msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
// msgBox.setDefaultButton(QMessageBox::Yes);
msgBox.setIconPixmap(QPixmap(":/win/unknown.png"));
QCheckBox confirmCheckBox("Always ask for confirmation", &msgBox);
confirmCheckBox.setCheckState(Qt::Checked);
msgBox.layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
msgBox.layout()->addWidget(&confirmCheckBox);
QPushButton *bYes = msgBox.addButton("Yes", QMessageBox::YesRole);
bYes->setIcon(style()->standardIcon(QStyle::SP_DialogYesButton));
QPushButton *bNo = msgBox.addButton("No", QMessageBox::NoRole);
bNo->setIcon(style()->standardIcon(QStyle::SP_DialogNoButton));
msgBox.setDefaultButton(bNo);
msgBox.setText("You are about to close this interface");
msgBox.setInformativeText("Are you sure?");
answer = msgBox.exec();

if (answer == QMessageBox::AcceptRole) {
m_presenter->notify(IEnggDiffractionPresenter::ShutDown);
event->accept();
} else {
event->ignore();
}
}

void EnggDiffractionViewQtGUI::openHelpWin() {
MantidQt::API::HelpWindow::showCustomInterface(
NULL, QString("Engineering_Diffraction"));
}

} // namespace CustomInterfaces
} // namespace MantidQt

0 comments on commit 316a290

Please sign in to comment.