Skip to content

Commit

Permalink
Re #8909. Detached MdiSubWindow from ApplicationWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Apr 1, 2014
1 parent 644e2a4 commit b280846
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 115 deletions.
21 changes: 7 additions & 14 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Expand Up @@ -6005,7 +6005,8 @@ QString ApplicationWindow::windowGeometryInfo(MdiSubWindow *w)
{
QString s = "geometry\t";
if (w->status() == MdiSubWindow::Maximized){
if (w == w->folder()->activeWindow())
//if (w == w->folder()->activeWindow())
if (w == activeWindow())
return s + "maximized\tactive\n";
else
return s + "maximized\n";
Expand Down Expand Up @@ -6037,7 +6038,8 @@ QString ApplicationWindow::windowGeometryInfo(MdiSubWindow *w)
}

bool hide = hidden(w);
if (w == w->folder()->activeWindow() && !hide)
//if (w == w->folder()->activeWindow() && !hide)
if (w == activeWindow() && !hide)
s+="active\n";
else if(hide)
s+="hidden\n";
Expand Down Expand Up @@ -6082,9 +6084,7 @@ void ApplicationWindow::restoreWindowGeometry(ApplicationWindow *app, MdiSubWind
}

if (s.contains ("active")) {
Folder *f = w->folder();
if (f)
f->setActiveWindow(w);
setActiveWindow(w);
}
}

Expand Down Expand Up @@ -8884,11 +8884,6 @@ void ApplicationWindow::activateWindow(MdiSubWindow *w, bool activateOuterWindow
}
}

// update the folder
Folder *f = w->folder();
if (f)
f->setActiveWindow(w);

blockWindowActivation = true;
FloatingWindow* fw = w->getFloatingWindow();
if (fw)
Expand Down Expand Up @@ -9018,15 +9013,12 @@ void ApplicationWindow::closeWindow(MdiSubWindow* window)
}
removeWindowFromLists(window);

Folder *f = window->folder();
f->removeWindow(window);

//update list view in project explorer
Q3ListViewItem *it=lv->findItem (window->objectName(), 0, Q3ListView::ExactMatch|Q3ListView::CaseSensitive);
if (it)
lv->takeItem(it);

if (show_windows_policy == ActiveFolder && !f->windowsList().count()){
if (show_windows_policy == ActiveFolder /*&& !f->windowsList().count()*/){
customMenu(0);
customToolBars(0);
} else if (show_windows_policy == SubFolders && !(current_folder->children()).isEmpty()){
Expand Down Expand Up @@ -17607,6 +17599,7 @@ void ApplicationWindow::addMdiSubWindow(MdiSubWindow *w, bool showNormal)
}

addListViewItem(w);
currentFolder()->addWindow(w);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/ApplicationWindow.h
Expand Up @@ -160,7 +160,7 @@ class ApplicationWindow: public QMainWindow, public Scripted
enum ShowWindowsPolicy{HideAll, ActiveFolder, SubFolders};
enum WindowType{NoWindow, TableWindow, MatrixWindow, MultiLayerWindow, NoteWindow, Plot3DWindow};
enum MatrixToTableConversion{Direct, XYZ, YXZ};
enum EndLineChar{LF, CRLF, CR};
enum EndLineChar{LF=0, CRLF=1, CR=2};
enum Analysis{NoAnalysis, Integrate, Diff, FitLinear, FitGauss, FitLorentz, FitSigmoidal};

FolderListView *lv, *folders;
Expand Down
49 changes: 2 additions & 47 deletions Code/Mantid/MantidPlot/src/FloatingWindow.cpp
Expand Up @@ -70,10 +70,10 @@ bool FloatingWindow::event(QEvent * e)
// If FloatingWindow was activated by clicking on it we need to
// let the application know about it
MdiSubWindow* w = dynamic_cast<MdiSubWindow*>(widget());
if (w && this != w->d_app->getActiveFloating())
if (w && this != d_app->getActiveFloating())
{
// the second argument says that FloatingWindow must not be activated again
w->d_app->activateWindow(w,false);
d_app->activateWindow(w,false);
}
}
else if (e->type() == QEvent::WindowStateChange)
Expand Down Expand Up @@ -193,48 +193,3 @@ void FloatingWindow::setWidget(QWidget* w)
wrapper->setWidget(w);
setCentralWidget(wrapper);
}

//
///**
// * Handle the close event.
// * @param e :: A QCloseEvent event.
// */
//void FloatingWindow::closeEvent( QCloseEvent *e )
//{
// // Default result = do close.
// int result = 0;
//
//// // If you need to confirm the close, ask the user
//// if (d_confirm_close)
//// {
//// result = QMessageBox::information(this, tr("MantidPlot"),
//// tr("Do you want to hide or delete") + "<p><b>'" + objectName() + "'</b> ?",
//// tr("Delete"), tr("Hide"), tr("Cancel"), 0, 2);
//// }
//
// switch(result)
// {
// case 0:
// if (widget()->close())
// {
// e->accept();
// // Continue; the mdi window should close (?)
// }
// else
// {
// QMessageBox::critical(parentWidget(),"MantidPlot - Error", "Window cannot be closed");
// e->ignore();
// }
// break;
//
//// case 1:
//// e->ignore();
//// emit hiddenWindow(this);
//// break;
////
//// case 2:
//// e->ignore();
//// break;
// }
//
//}
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/Folder.cpp
Expand Up @@ -182,7 +182,7 @@ void Folder::addWindow( MdiSubWindow *w )
{
if (w) {
lstWindows.append( w );
w->setFolder(this);
connect(w,SIGNAL(closedWindow(MdiSubWindow *)),this,SLOT(removeWindow(MdiSubWindow *)));
}
}

Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/MantidPlot/src/Folder.h
Expand Up @@ -59,7 +59,6 @@ class Folder : public QObject
QList<MdiSubWindow *> windowsList(){return lstWindows;};

void addWindow( MdiSubWindow *w );
void removeWindow( MdiSubWindow *w );
bool hasWindow(MdiSubWindow *w) const;

//! The list of subfolder names, including first generation children only
Expand Down Expand Up @@ -124,6 +123,8 @@ class Folder : public QObject
public slots:
///Mantid: made this a slot for use with script messages when there is no script window
void appendLogInfo(const QString& text){d_log_info += text;};
void removeWindow( MdiSubWindow *w );


protected:
QString birthdate, modifDate;
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/MantidPlot/src/Graph3D.cpp
Expand Up @@ -32,6 +32,7 @@
#include "MyParser.h"
#include "MatrixModel.h"
#include "UserFunction.h"//Mantid
//#include "ApplicationWindow.h"


#include <QApplication>
Expand Down Expand Up @@ -113,7 +114,7 @@ Triple UserParametricSurface::operator()(double u, double v)
return Triple(x, y, z);
}

Graph3D::Graph3D(const QString& label, ApplicationWindow* parent, const char* name, Qt::WFlags f)
Graph3D::Graph3D(const QString& label, QWidget* parent, const char* name, Qt::WFlags f)
: MdiSubWindow(parent, label, name, f)
{
initPlot();
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/Graph3D.h
Expand Up @@ -63,7 +63,7 @@ class Graph3D: public MdiSubWindow
Q_OBJECT

public:
Graph3D (const QString& label, ApplicationWindow* parent, const char* name=0, Qt::WFlags f=0);
Graph3D (const QString& label, QWidget* parent, const char* name=0, Qt::WFlags f=0);
~Graph3D();

enum PlotType{Scatter = 0, Trajectory = 1, Bars = 2, Ribbon = 3};
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidMatrix.cpp
Expand Up @@ -51,7 +51,7 @@ using namespace MantidQt::API;
using namespace Mantid::Geometry;

MantidMatrix::MantidMatrix(Mantid::API::MatrixWorkspace_const_sptr ws, ApplicationWindow* parent, const QString& label, const QString& name, int start, int end)
: MdiSubWindow(parent, label, name, 0),
: AppMdiSubWindow(parent, label, name, 0),
WorkspaceObserver(),
m_appWindow(parent),
m_workspace(ws),
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidMatrix.h
Expand Up @@ -77,7 +77,7 @@ File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MantidMatrix : public MdiSubWindow, MantidQt::API::WorkspaceObserver
class MantidMatrix : public AppMdiSubWindow, MantidQt::API::WorkspaceObserver
{
Q_OBJECT

Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/MantidPlot/src/Matrix.cpp
Expand Up @@ -65,7 +65,7 @@
#include <gsl/gsl_linalg.h>

Matrix::Matrix(ScriptingEnv *env, const QString& label, ApplicationWindow* parent, const QString& name, Qt::WFlags f)
: MdiSubWindow(parent, label, name, f), Scripted(env),
: AppMdiSubWindow(parent, label, name, f), Scripted(env),
d_matrix_model(NULL),m_bk_color(),d_stack(NULL),
d_table_view(NULL),imageLabel(NULL),formula_str(),
txt_format(),num_precision(0),x_start(0.0),
Expand All @@ -80,7 +80,7 @@ Matrix::Matrix(ScriptingEnv *env, const QString& label, ApplicationWindow* paren
}

Matrix::Matrix(ScriptingEnv *env, int r, int c, const QString& label, ApplicationWindow* parent, const QString& name, Qt::WFlags f)
: MdiSubWindow(parent, label, name, f), Scripted(env),
: AppMdiSubWindow(parent, label, name, f), Scripted(env),
d_matrix_model(NULL),m_bk_color(),d_stack(NULL),
d_table_view(NULL),imageLabel(NULL),formula_str(),
txt_format(),num_precision(0),x_start(0.0),
Expand All @@ -96,7 +96,7 @@ Matrix::Matrix(ScriptingEnv *env, int r, int c, const QString& label, Applicatio
}

Matrix::Matrix(ScriptingEnv *env, const QImage& image, const QString& label, ApplicationWindow* parent, const QString& name, Qt::WFlags f)
: MdiSubWindow(parent, label, name, f), Scripted(env),
: AppMdiSubWindow(parent, label, name, f), Scripted(env),
d_matrix_model(NULL),m_bk_color(),d_stack(NULL),
d_table_view(NULL),imageLabel(NULL),formula_str(),
txt_format(QChar()),num_precision(0),x_start(0.0),
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/Matrix.h
Expand Up @@ -59,7 +59,7 @@ class QShortcut;
class QUndoStack;

//! Matrix worksheet class
class Matrix: public MdiSubWindow, public Scripted
class Matrix: public AppMdiSubWindow, public Scripted
{
Q_OBJECT

Expand Down
55 changes: 36 additions & 19 deletions Code/Mantid/MantidPlot/src/MdiSubWindow.cpp
Expand Up @@ -28,9 +28,13 @@
***************************************************************************/
#include "MdiSubWindow.h"
#include "FloatingWindow.h"


#include "Folder.h"
#include "ApplicationWindow.h"



#include <QApplication>
#include <QMessageBox>
#include <QEvent>
Expand All @@ -48,10 +52,10 @@
using std::ifstream;
using std::string;

MdiSubWindow::MdiSubWindow(ApplicationWindow *app, const QString& label, const QString& name, Qt::WFlags f):
MdiSubWindowParent_t (app, f),
d_app(app),
d_folder(app->currentFolder()),
MdiSubWindow::MdiSubWindow(QWidget *parent, const QString& label, const QString& name, Qt::WFlags f):
MdiSubWindowParent_t (parent, f),
//d_app(app),
//d_folder(app->currentFolder()),
d_label(label),
d_status(Normal),
d_caption_policy(Both),
Expand All @@ -61,10 +65,10 @@ MdiSubWindow::MdiSubWindow(ApplicationWindow *app, const QString& label, const Q
{
setObjectName(name);
setAttribute(Qt::WA_DeleteOnClose);
setLocale(app->locale());
setLocale(parent->locale());
confirmClose(false);
if (d_folder)
d_folder->addWindow(this);
//if (d_folder)
// d_folder->addWindow(this);
}

void MdiSubWindow::updateCaption()
Expand Down Expand Up @@ -95,7 +99,8 @@ switch (d_caption_policy)
{
wrapper->setWindowTitle(windowTitle());
}
d_app->setListViewLabel(objectName(), d_label);
//d_app->setListViewLabel(objectName(), d_label);
emit captionChanged(objectName(), d_label);
};

void MdiSubWindow::resizeEvent( QResizeEvent* e )
Expand Down Expand Up @@ -276,15 +281,15 @@ bool MdiSubWindow::eventFilter(QObject *object, QEvent *e)
return true;
}

if (e->type() == QEvent::Move && object == widget()){
QObjectList lst = children();
foreach(QObject *o, lst){
if (o->isA("QMenu") && d_app){
d_app->customWindowTitleBarMenu(this, dynamic_cast<QMenu *>(o));
break;
}
}
}
//if (e->type() == QEvent::Move && object == widget()){
// QObjectList lst = children();
// foreach(QObject *o, lst){
// if (o->isA("QMenu") && d_app){
// d_app->customWindowTitleBarMenu(this, dynamic_cast<QMenu *>(o));
// break;
// }
// }
//}
return MdiSubWindowParent_t::eventFilter(object, e);
}

Expand Down Expand Up @@ -332,7 +337,7 @@ void MdiSubWindow::setMinimized()
if (wrapper)
{
wrapper->showMinimized();
d_app->activateNewWindow();
//d_app->activateNewWindow();
}
else
{
Expand All @@ -357,7 +362,8 @@ void MdiSubWindow::setMaximized()
QString MdiSubWindow::parseAsciiFile(const QString& fname, const QString &commentString,
int endLine, int ignoreFirstLines, int maxRows, int& rows)
{
if (endLine == ApplicationWindow::CR)
//if (endLine == ApplicationWindow::CR)
if (endLine == 2)
return parseMacAsciiFile(fname, commentString, ignoreFirstLines, maxRows, rows);

//QTextStream replaces '\r\n' with '\n', therefore we don't need a special treatement in this case!
Expand Down Expand Up @@ -495,3 +501,14 @@ QWidget* MdiSubWindow::getWrapperWindow() const
}
return wrapper;
}

//======================================================================================//

AppMdiSubWindow::AppMdiSubWindow(QWidget *parent, const QString& label, const QString& name, Qt::WFlags f)
:MdiSubWindow(parent, label, name, f),
m_app( static_cast<ApplicationWindow*>(parent) )
{
}



0 comments on commit b280846

Please sign in to comment.