Added common base class for Typ, Dfn, and From dialogs: GeorgesDockWidget.

This commit is contained in:
dfighter1985 2014-08-31 21:25:12 +02:00
parent a0df8bf7c7
commit 9031443df8
8 changed files with 128 additions and 58 deletions

View file

@ -3,7 +3,7 @@
#include <QMessageBox> #include <QMessageBox>
GeorgesDFNDialog::GeorgesDFNDialog( QWidget *parent ) : GeorgesDFNDialog::GeorgesDFNDialog( QWidget *parent ) :
QDockWidget( parent ) GeorgesDockWidget( parent )
{ {
m_ui.setupUi( this ); m_ui.setupUi( this );
setupConnections(); setupConnections();

View file

@ -1,15 +1,18 @@
#ifndef GEORGES_DFN_DIALOG #ifndef GEORGES_DFN_DIALOG
#define GEORGES_DFN_DIALOG #define GEORGES_DFN_DIALOG
#include "georges_dock_widget.h"
#include "ui_georges_dfn_dialog.h" #include "ui_georges_dfn_dialog.h"
class GeorgesDFNDialog : public QDockWidget class GeorgesDFNDialog : public GeorgesDockWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
GeorgesDFNDialog( QWidget *parent = NULL ); GeorgesDFNDialog( QWidget *parent = NULL );
~GeorgesDFNDialog(); ~GeorgesDFNDialog();
void write(){}
private Q_SLOTS: private Q_SLOTS:
void onAddClicked(); void onAddClicked();
void onRemoveClicked(); void onRemoveClicked();

View file

@ -0,0 +1,14 @@
#include "georges_dock_widget.h"
GeorgesDockWidget::GeorgesDockWidget( QWidget *parent ) :
QDockWidget( parent )
{
m_modified = false;
m_undoStack = NULL;
}
GeorgesDockWidget::~GeorgesDockWidget()
{
}

View file

@ -0,0 +1,29 @@
#ifndef GEORGES_DOCK_WIDGET
#define GEORGES_DOCK_WIDGET
#include <QDockWidget>
class QUndoStack;
class GeorgesDockWidget : public QDockWidget
{
public:
GeorgesDockWidget( QWidget *parent = NULL );
~GeorgesDockWidget();
void setUndoStack( QUndoStack *stack ){ m_undoStack = stack; }
bool isModified() const{ return m_modified; }
void setModified( bool b ){ m_modified = b; }
QString fileName() const{ return m_fileName; }
virtual void write() = 0;
protected:
QString m_fileName;
bool m_modified;
QUndoStack *m_undoStack;
};
#endif

View file

@ -207,9 +207,9 @@ namespace GeorgesQt
// Check to see if the form is already loaded, if it is just raise it. // Check to see if the form is already loaded, if it is just raise it.
if (m_dockedWidgets.size()) if (m_dockedWidgets.size())
{ {
Q_FOREACH(CGeorgesTreeViewDialog *wgt, m_dockedWidgets) Q_FOREACH(GeorgesDockWidget *wgt, m_dockedWidgets)
{ {
if (info.fileName() == wgt->loadedForm) if (info.fileName() == wgt->fileName())
{ {
wgt->raise(); wgt->raise();
return; return;
@ -217,16 +217,33 @@ namespace GeorgesQt
} }
} }
GeorgesDockWidget *w = NULL;
if( info.suffix() == "dfn" ) if( info.suffix() == "dfn" )
{ {
loadDfnDialog( fileName ); w = loadDfnDialog( fileName );
}
else
if( info.suffix() == "typ" )
{
w = loadTypDialog( fileName );
}
else
{
w = loadFormDialog( fileName, loadFromDfn );
}
if( w == NULL )
{
QMessageBox::information( this,
tr( "Failed to load file..." ),
tr( "Failed to load file '%1'" ).arg( info.fileName() ) );
return; return;
} }
CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock); w->setUndoStack(UndoStack);
dock->setUndoStack(UndoStack); m_lastActiveDock = w;
m_lastActiveDock = dock; m_dockedWidgets.append(w);
m_dockedWidgets.append(dock);
connect(m_dockedWidgets.last(), SIGNAL(closing()), this, SLOT(closingTreeView())); connect(m_dockedWidgets.last(), SIGNAL(closing()), this, SLOT(closingTreeView()));
connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)), m_dockedWidgets.last(), SLOT(checkVisibility(bool))); connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)), m_dockedWidgets.last(), SLOT(checkVisibility(bool)));
@ -241,38 +258,6 @@ namespace GeorgesQt
m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last());
} }
// Retrieve the form and load the form.
NLGEORGES::CForm *form;
if(loadFromDfn)
{
// Get the form by DFN name.
form = m_dockedWidgets.last()->getFormByDfnName(info.fileName());
}
else
{
form = m_dockedWidgets.last()->getFormByName(info.fileName());
}
if (form)
{
m_dockedWidgets.last()->setForm(form);
m_dockedWidgets.last()->loadFormIntoDialog(form);
QApplication::processEvents();
connect(m_dockedWidgets.last(), SIGNAL(modified()),
this, SLOT(setModified()));
m_dockedWidgets.last()->raise();
connect(m_dockedWidgets.last(), SIGNAL(changeFile(QString)),
m_georgesDirTreeDialog, SLOT(changeFile(QString)));
}
else
{
nlwarning("Failed to load form: %s", info.fileName().toUtf8().constData());
m_dockedWidgets.last()->close();
QMessageBox::information( this,
tr( "Failed to load form..." ),
tr( "Failed to load form '%1'" ).arg( info.fileName() ) );
}
} }
void GeorgesEditorForm::closingTreeView() void GeorgesEditorForm::closingTreeView()
@ -327,11 +312,55 @@ namespace GeorgesQt
} }
} }
GeorgesDockWidget* GeorgesEditorForm::loadTypDialog( const QString &fileName )
{
return NULL;
}
void GeorgesEditorForm::loadDfnDialog( const QString &fileName ) GeorgesDockWidget* GeorgesEditorForm::loadDfnDialog( const QString &fileName )
{ {
GeorgesDFNDialog *d = new GeorgesDFNDialog(); GeorgesDFNDialog *d = new GeorgesDFNDialog();
m_mainDock->addDockWidget( Qt::RightDockWidgetArea, d ); m_mainDock->addDockWidget( Qt::RightDockWidgetArea, d );
return d;
}
GeorgesDockWidget* GeorgesEditorForm::loadFormDialog( const QString &fileName, bool loadFromDFN )
{
QFileInfo info( fileName );
CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(m_mainDock);
// Retrieve the form and load the form.
NLGEORGES::CForm *form;
if(loadFromDFN)
{
// Get the form by DFN name.
form = d->getFormByDfnName(info.fileName());
}
else
{
form = d->getFormByName(info.fileName());
}
if (form)
{
d->setForm(form);
d->loadFormIntoDialog(form);
QApplication::processEvents();
connect(d, SIGNAL(modified()),
this, SLOT(setModified()));
d->raise();
connect(d, SIGNAL(changeFile(QString)),
m_georgesDirTreeDialog, SLOT(changeFile(QString)));
}
else
{
delete d;
d = NULL;
}
return d;
} }
} /* namespace GeorgesQt */ } /* namespace GeorgesQt */

View file

@ -23,6 +23,8 @@
// Qt includes // Qt includes
#include <QtGui/QUndoStack> #include <QtGui/QUndoStack>
class GeorgesDockWidget;
namespace GeorgesQt namespace GeorgesQt
{ {
@ -56,7 +58,9 @@ private:
void readSettings(); void readSettings();
void writeSettings(); void writeSettings();
void loadDfnDialog(const QString &fileName); GeorgesDockWidget* loadTypDialog(const QString &fileName);
GeorgesDockWidget* loadDfnDialog(const QString &fileName);
GeorgesDockWidget* loadFormDialog(const QString &fileName, bool loadFromDFN );
Ui::GeorgesEditorForm m_ui; Ui::GeorgesEditorForm m_ui;
@ -71,10 +75,10 @@ private:
QMainWindow *m_mainDock; QMainWindow *m_mainDock;
/// Contains a list of all of the open forms. /// Contains a list of all of the open forms.
QList<CGeorgesTreeViewDialog*> m_dockedWidgets; QList<GeorgesDockWidget*> m_dockedWidgets;
/// Contains a pointer to the last known focal change for active documents. /// Contains a pointer to the last known focal change for active documents.
CGeorgesTreeViewDialog *m_lastActiveDock; GeorgesDockWidget *m_lastActiveDock;
/// Contains a record of the last directory a sheet file dialog was opened for. /// Contains a record of the last directory a sheet file dialog was opened for.
QString m_lastSheetDir; QString m_lastSheetDir;

View file

@ -52,7 +52,7 @@ namespace GeorgesQt
{ {
CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/) CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/)
: QDockWidget(parent), : GeorgesDockWidget(parent),
m_header(0), m_header(0),
m_modified(false) m_modified(false)
{ {
@ -263,6 +263,7 @@ namespace GeorgesQt
if (root) if (root)
{ {
loadedForm = m_form->getFilename().c_str(); loadedForm = m_form->getFilename().c_str();
m_fileName = m_form->getFilename().c_str();
CGeorgesFormModel *model = new CGeorgesFormModel(m_form,deps,comments,parents,m_header->expanded()); CGeorgesFormModel *model = new CGeorgesFormModel(m_form,deps,comments,parents,m_header->expanded());
m_ui.treeView->setModel(model); m_ui.treeView->setModel(model);

View file

@ -18,6 +18,7 @@
#define GEORGES_TREEVIEWER_DIALOG_H #define GEORGES_TREEVIEWER_DIALOG_H
#include "ui_georges_treeview_form.h" #include "ui_georges_treeview_form.h"
#include "georges_dock_widget.h"
#include "expandable_headerview.h" #include "expandable_headerview.h"
// Qt includes // Qt includes
@ -49,7 +50,7 @@ namespace GeorgesQt
class CGeorges; class CGeorges;
class CGeorgesFormModel; class CGeorgesFormModel;
class CGeorgesTreeViewDialog: public QDockWidget class CGeorgesTreeViewDialog: public GeorgesDockWidget
{ {
Q_OBJECT Q_OBJECT
@ -57,9 +58,6 @@ namespace GeorgesQt
CGeorgesTreeViewDialog(QWidget *parent = 0); CGeorgesTreeViewDialog(QWidget *parent = 0);
~CGeorgesTreeViewDialog(); ~CGeorgesTreeViewDialog();
bool isModified() {return m_modified;}
void setModified(bool m) {m_modified = m;}
NLGEORGES::CForm* getFormByName(const QString formName); NLGEORGES::CForm* getFormByName(const QString formName);
NLGEORGES::CForm* getFormByDfnName(const QString dfnName); NLGEORGES::CForm* getFormByDfnName(const QString dfnName);
@ -75,12 +73,6 @@ namespace GeorgesQt
QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; } QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; }
void setUndoStack(QUndoStack *stack) {
m_undoStack = stack;
}
QString loadedForm; QString loadedForm;
protected: protected:
@ -117,8 +109,6 @@ namespace GeorgesQt
UForm *m_form; UForm *m_form;
CGeorges *m_georges; CGeorges *m_georges;
QUndoStack *m_undoStack;
/// Contains a record of the last directory a sheet file dialog was opened for. /// Contains a record of the last directory a sheet file dialog was opened for.
QString m_lastSheetDir; QString m_lastSheetDir;