Fraxinus
2023.01.05-dev+develop.0da12
An IGT application
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
cxFileWatcherWidget.cpp
Go to the documentation of this file.
1
/*=========================================================================
2
This file is part of CustusX, an Image Guided Therapy Application.
3
4
Copyright (c) SINTEF Department of Medical Technology.
5
All rights reserved.
6
7
CustusX is released under a BSD 3-Clause license.
8
9
See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10
=========================================================================*/
11
12
#include "
cxFileWatcherWidget.h
"
13
#include "
cxLogger.h
"
14
#include <QFileSystemWatcher>
15
#include <QFileInfo>
16
17
18
namespace
cx
19
{
20
FileWatcherWidget::FileWatcherWidget
(QWidget* parent, QString objectName, QString windowTitle) :
21
BaseWidget
(parent, objectName, windowTitle),
22
mFileSystemWatcher(new QFileSystemWatcher())
23
{
24
connect(
mFileSystemWatcher
, SIGNAL(fileChanged(
const
QString&)),
this
, SLOT(
previewFileSlot
(
const
QString&)));
25
}
26
27
FileWatcherWidget::~FileWatcherWidget
()
28
{}
29
30
bool
FileWatcherWidget::internalOpenNewFile
(
const
QString absoluteFilePath)
31
{
32
if
(
mCurrentFile
)
33
{
34
if
(
mCurrentFile
->isOpen())
35
{
36
this->
watchFile
(
false
);
37
mCurrentFile
->close();
38
}
39
}
40
41
mCurrentFile
.reset(
new
QFile(absoluteFilePath));
42
this->
watchFile
(
true
);
43
44
if
(!
mCurrentFile
->exists())
45
{
46
return
false
;
47
}
48
49
if
(!
mCurrentFile
->open(QIODevice::ReadOnly))
50
{
51
reportWarning
(
"Could not open file "
+absoluteFilePath);
52
//return false; Is this missing???
53
}
54
return
true
;
55
}
56
57
void
FileWatcherWidget::watchFile
(
bool
on)
58
{
59
if
(!
mCurrentFile
)
60
return
;
61
62
QFileInfo info(*
mCurrentFile
);
63
64
if
(on)
65
{
66
if
(!
mFileSystemWatcher
->files().contains(info.absoluteFilePath()))
67
mFileSystemWatcher
->addPath(info.absoluteFilePath());
68
}
69
else
70
{
71
mFileSystemWatcher
->removePath(info.absoluteFilePath());
72
}
73
}
74
}
/* namespace cx */
cxFileWatcherWidget.h
cx::FileWatcherWidget::internalOpenNewFile
bool internalOpenNewFile(const QString absoluteFilePath)
Definition:
cxFileWatcherWidget.cpp:30
cx::FileWatcherWidget::mFileSystemWatcher
QFileSystemWatcher * mFileSystemWatcher
Definition:
cxFileWatcherWidget.h:50
cx::FileWatcherWidget::watchFile
void watchFile(bool on)
Definition:
cxFileWatcherWidget.cpp:57
cxLogger.h
cx::FileWatcherWidget::previewFileSlot
virtual void previewFileSlot(const QString &absoluteFilePath)=0
cx::FileWatcherWidget::FileWatcherWidget
FileWatcherWidget(QWidget *parent, QString objectName, QString windowTitle)
Definition:
cxFileWatcherWidget.cpp:20
cx::FileWatcherWidget::mCurrentFile
boost::shared_ptr< QFile > mCurrentFile
Definition:
cxFileWatcherWidget.h:51
cx::reportWarning
void reportWarning(QString msg)
Definition:
cxLogger.cpp:70
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition:
cxBaseWidget.h:88
cx::FileWatcherWidget::~FileWatcherWidget
virtual ~FileWatcherWidget()
Definition:
cxFileWatcherWidget.cpp:27
cx
Namespace for all CustusX production code.
Definition:
cx_dev_group_definitions.h:13
CX
source
resource
widgets
cxFileWatcherWidget.cpp
Generated on Thu Jan 5 2023 02:05:42 for Fraxinus by
1.8.11