tuchulcha  0.10.1
Graphical Workflow Configuration Editor
ParamInspectorWindow.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2009 Jens-Malte Gottfried
2 
3  This file is part of Tuchulcha.
4 
5  Tuchulcha is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Tuchulcha is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Tuchulcha. If not, see <http://www.gnu.org/licenses/>.
17 */
24 #include <QDir>
25 #include <QMessageBox>
26 #include <QMenuBar>
27 #include <QDockWidget>
28 #include <QStatusBar>
29 #include <QSettings>
30 #include "ParamInspectorWindow.h"
31 #include "ObjectInspector.h"
32 #include "ParameterFileModel.h"
33 #include "FileManager.h"
34 #include "RecentFileHandler.h"
35 
36 ParamInspectorWindow::ParamInspectorWindow(QWidget *pp, Qt::WindowFlags ff) :
37  QMainWindow(pp, ff)
38 {
39  _fileMenu = menuBar()->addMenu(tr("&File"));
40  _inspector = new ObjectInspector(this);
42  QString(),_inspector, FileManager::instance().classesFile());
43  model->setOnlyParams(false);
44  _inspector->setModel(model);
45  _inspector->setEdit(true);
46 
47  _fileMenu->addAction(tr("&Open"), this,
48  SLOT(openFile()), QKeySequence(tr("Ctrl+O")));
49  _rfHandler = new RecentFileHandler(this);
51  connect(_rfHandler,SIGNAL(openFile(QString)),SLOT(openFile(QString)));
52  connect(model,SIGNAL(fileNameChanged(QString)),
53  _rfHandler,SLOT(setCurrentFile(QString)));
54 
55  _fileMenu->addSeparator();
56  _fileMenu->addAction(tr("Open &Metadata"), _inspector,
57  SLOT(openMetaData()), QKeySequence(tr("Ctrl+M")));
58  _fileMenu->addAction(tr("&Save"), _inspector,
59  SLOT(saveFile()), QKeySequence(tr("Ctrl+S")));
60  _fileMenu->addAction(tr("Save &as..."), _inspector,
61  SLOT(saveFileAs()), QKeySequence(tr("Ctrl+Alt+S")));
62  _fileMenu->addAction(tr("E&xit"), this,
63  SLOT(close()), QKeySequence(tr("Ctrl+Q")));
64 
65  setCentralWidget(_inspector->getViewer());
66  QDockWidget* dock = new QDockWidget(tr("Tools"),this);
67  dock->setObjectName("tools");
68  dock->setWidget(_inspector);
69  addDockWidget(Qt::RightDockWidgetArea, dock);
70 
71  connect(_inspector, SIGNAL(statusMessage(const QString&, int)),
72  statusBar(), SLOT(showMessage(const QString&, int)));
73 
74  setWindowTitle(tr("Object Inspector"));
75 
76  resize(620, 700);
77  QSettings settings;
78  restoreGeometry(settings.value("geometry").toByteArray());
79  restoreState(settings.value("windowState").toByteArray());
80 }
81 
82 ParamInspectorWindow::~ParamInspectorWindow() {
83  setCentralWidget(0);
84  delete _inspector;
85  QDockWidget* dock = findChild<QDockWidget*>("tools");
86  Q_ASSERT(dock);
87  delete dock;
88 }
89 
90 void ParamInspectorWindow::closeEvent(QCloseEvent* cEv) {
91  QSettings settings;
92  settings.setValue("geometry", saveGeometry());
93  settings.setValue("windowState",saveState());
94  QMainWindow::closeEvent(cEv);
95 }
96 
97 void ParamInspectorWindow::openFile(QString fName) {
98  try {
99  _inspector->openFile(fName);
100  } catch (std::string errorMsg) {
101  // empty filenames are harmless, simply do nothing
102  if (errorMsg.find("Empty filename") == std::string::npos)
103  QMessageBox::warning(
104  this, tr("Error opening file"), errorMsg.c_str());
105  }
106  if(_inspector->model()->fileName() != QDir::homePath()) {
107  setWindowTitle(tr("Object Inspector")+QString(" [%1]")
108  .arg(_inspector->model()->fileName()));
109  }
110  else {
111  setWindowTitle(tr("Object Inspector"));
112  }
113 }
void setOnlyParams(bool value)
Set property _onlyparams.
Declaration of class FileManager.
ObjectInspector * _inspector
Inspector widget.
Declaration of class ParameterFileModel.
static const FileManager & instance()
get a reference to the file Manager instance
Definition: FileManager.cpp:70
provide list of recent files
Object inspector widget.
ParamInspectorWindow(QWidget *parent=0, Qt::WindowFlags flags=0)
default constructor
RecentFileHandler * _rfHandler
recent files
This model serves to provide a model frontend to access a ParameterFile instance. ...
RecentFileHandler declaration.
ParameterFileModel * model() const
Get value of property _model.
Test displaying a ParameterFileModel.
void openFile(QString fName=QString())
open file and update window title
QMenu * _fileMenu
File menu.
QString fileName() const
Get property _fileName.
virtual void setEdit(bool on)
Enable/Disable structural editing.
virtual void openFile(QString fName=QString())
Open given file.
void registerRecentFileEntries(QMenu *menu)
add entries to the given menu
QWidget * getViewer()
get inspector viewer widget
Declaration of class ObjectInspector.
virtual void setModel(ParameterFileModel *model)
Change used model.
virtual void closeEvent(QCloseEvent *event)
save geometry etc.