SMILX  1.01
milxQtWindow.cpp
1 /*=========================================================================
2  The Software is copyright (c) Commonwealth Scientific and Industrial Research Organisation (CSIRO)
3  ABN 41 687 119 230.
4  All rights reserved.
5 
6  Licensed under the CSIRO BSD 3-Clause License
7  You may not use this file except in compliance with the License.
8  You may obtain a copy of the License in the file LICENSE.md or at
9 
10  https://stash.csiro.au/projects/SMILI/repos/smili/browse/license.txt
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 =========================================================================*/
18 #include "milxQtWindow.h"
19 
20 #include <QFileDialog>
22 #include <vtkRenderWindow.h>
23 
24 milxQtWindow::milxQtWindow(QWidget *theParent) : QVTKWidget(theParent)
25 {
27  verboseMode = true;
28  deletableOnClose = true;
29  consoleAssigned = false;
30 
32  prefix = "";
33  name = "";
34 
36 }
37 
39 {
40  //dtor
41 }
42 
43 void milxQtWindow::setName(const QString filename)
44 {
45  name = filename;
46  setWindowTitle(strippedNamePrefix());
47 
49 }
50 
52 {
53  bool ok;
54 
55  QString newName = QInputDialog::getText(this, tr("Rename Data"), tr("New Name: "), QLineEdit::Normal, name, &ok);
56 
57  if(ok)
58  setName(newName);
59 }
60 
61 void milxQtWindow::copyToContextMenu(QMenu *copyMenu)
62 {
63  QList<QAction *> actionsInMenu = copyMenu->actions();
64  QMenu *newMenu = new QMenu(this);
65 
66  newMenu->setTitle(copyMenu->title());
67  foreach(QAction *action, actionsInMenu)
68  {
69  QAction *newAction = new QAction(action->parent());
70  newAction->setText(action->text());
71  newAction->setCheckable(action->isCheckable());
72  newAction->setChecked(action->isChecked());
73 
74  newMenu->addAction(newAction);
75  }
76 
77  addToContextMenu(newMenu);
78 }
79 
80 //Internal Members
82 {
83 
84 }
85 
86 void milxQtWindow::closeEvent(QCloseEvent *clEvent)
87 {
88  clEvent->accept();
89  emit closing(this);
90 }
91 
92 void milxQtWindow::printError(QString msg)
93 {
94  if(!verboseMode)
95  return;
96 
97  if(consoleAssigned)
98  console->printError(msg);
99  else
100  cerr << "ERROR: " << msg.toStdString() << endl;
101 }
102 
103 void milxQtWindow::printWarning(QString msg)
104 {
105  if(!verboseMode)
106  return;
107 
108  if(consoleAssigned)
109  console->printWarning(msg);
110  else
111  cerr << "Warning: " << msg.toStdString() << endl;
112 }
113 
114 void milxQtWindow::printDebug(QString msg)
115 {
116  if(!verboseMode)
117  return;
118 
119  if(consoleAssigned)
120  console->printDebug(msg);
121  else
122  cerr << "Debug: " << msg.toStdString() << endl;
123 }
124 
125 void milxQtWindow::printInfo(QString msg)
126 {
127  if(!verboseMode)
128  return;
129 
130  if(consoleAssigned)
131  console->printInfo(msg);
132  else
133  cerr << msg.toStdString() << endl;
134 }
void printWarning(QString msg)
Warning message wrapper for console.
void printError(QString msg)
Error message wrapper for console.
milxQtWindow(QWidget *theParent=0)
The standard constructor.
void setName(const QString filename)
Set the name of the data.
void createConnections()
Create the connections for context menu etc.
virtual ~milxQtWindow()
The standard destructor.
virtual QString strippedNamePrefix()
Returns the stripped (path removed) name of the data with "Generic" prefix.
Definition: milxQtWindow.h:98
void printDebug(QString msg)
Debug message wrapper for console.
void nameChanged(const QString newName)
Send signal that the data has been renamed.
virtual void copyToContextMenu(QMenu *copyMenu)
Copies the menu, by duplicating the entries, to the context menu. Connections are assumed to be made ...
bool consoleAssigned
Console assigned for output?
Definition: milxQtWindow.h:247
QString prefix
Prefix of the data.
Definition: milxQtWindow.h:242
void printDebug(QString msg)
Debug message wrapper for console.
void addToContextMenu(QAction *act)
Adds (prepends) the action to the context menu. Connections are assumed to be made before hand...
Definition: milxQtWindow.h:115
void printError(QString msg)
Error message wrapper for console.
void closing(QWidget *win)
Send signal that the window is closing.
bool deletableOnClose
Delete on close allowed? Allowed by default.
Definition: milxQtWindow.h:246
bool verboseMode
Verbose message output mode.
Definition: milxQtWindow.h:245
void closeEvent(QCloseEvent *clEvent)
When closing, execute this member.
void rename()
Renames the data.
void printWarning(QString msg)
Warning message wrapper for console.
milxQtConsole * console
Console for log outputs.
Definition: milxQtWindow.h:257
void printInfo(QString msg)
Info message wrapper for console.
void printInfo(QString msg)
Info message wrapper for console.
QString name
Name of the data.
Definition: milxQtWindow.h:241