NorMIT-nav  22.09
An IGT application
cxFilenameWidget.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 #include "cxFilenameWidget.h"
12 #include "cxFileInputWidget.h"
13 #include "cxFilePathProperty.h"
14 #include <QFileInfo>
15 #include <QDir>
16 #include "cxTypeConversions.h"
17 #include <iostream>
18 #include "cxLogger.h"
19 
20 namespace cx
21 {
22 
23 FilenameWidget::FilenameWidget(QWidget* parent, FilePathPropertyPtr dataInterface,
24  QGridLayout* gridLayout, int row) :
25  OptimizedUpdateWidget(parent)
26 {
27  mData = dataInterface;
28  connect(mData.get(), SIGNAL(changed()), this, SLOT(setModified()));
29 
30  QHBoxLayout* topLayout = new QHBoxLayout;
31  topLayout->setMargin(0);
32  this->setLayout(topLayout);
33 
34  mFileInput = new FileInputWidget(this);
35  mFileInput->setUseRelativePath(false);
36  connect(mFileInput, SIGNAL(fileChanged()), this, SLOT(editingFinished()));
37 
38  if (gridLayout) // add to input gridlayout
39  {
40  gridLayout->addWidget(mFileInput, row, 0);
41  }
42  else // add directly to this
43  {
44  topLayout->addWidget(mFileInput);
45  }
46 
47  this->setModified();
48 }
49 
50 
51 void FilenameWidget::editingFinished()
52 {
53  mData->setValue(mFileInput->getFilename());
54 }
55 
56 void FilenameWidget::prePaintEvent()
57 {
58  mFileInput->blockSignals(true);
59 
60  QString path = mData->getEmbeddedPath().getRootPath();
61  if (path.isEmpty())
62  path = QDir::homePath();
63 
64  mFileInput->setDescription(mData->getDisplayName());
65  mFileInput->setBasePath(path);
66  mFileInput->setFilename(mData->getValue());
67  mFileInput->setHelp(mData->getHelp());
68  mFileInput->setBrowseHelp(mData->getHelp());
69 
70  mFileInput->blockSignals(false);
71 }
72 
73 } // namespace cx
cxLogger.h
cxFileInputWidget.h
cx::FileInputWidget::setUseRelativePath
void setUseRelativePath(bool on)
Definition: cxFileInputWidget.cpp:126
cx::OptimizedUpdateWidget::setModified
virtual void setModified()
Definition: cxOptimizedUpdateWidget.cpp:36
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::FileInputWidget::getFilename
QString getFilename() const
Definition: cxFileInputWidget.cpp:114
cxFilePathProperty.h
cx::FilePathPropertyPtr
boost::shared_ptr< class FilePathProperty > FilePathPropertyPtr
Definition: cxPlusConnectWidget.h:28
cx::FileInputWidget::setHelp
void setHelp(QString text)
Definition: cxFileInputWidget.cpp:73
cx::FileInputWidget::setBasePath
void setBasePath(QString path)
Definition: cxFileInputWidget.cpp:92
cx::FileInputWidget::setBrowseHelp
void setBrowseHelp(QString text)
Definition: cxFileInputWidget.cpp:86
cxTypeConversions.h
cx::FilenameWidget::FilenameWidget
FilenameWidget(QWidget *parent, FilePathPropertyPtr, QGridLayout *gridLayout=0, int row=0)
Definition: cxFilenameWidget.cpp:23
cxFilenameWidget.h
cx::OptimizedUpdateWidget
Interface for all classes following the modified/prepaint paradigm.
Definition: cxOptimizedUpdateWidget.h:41
cx::FileInputWidget
Definition: cxFileInputWidget.h:34
cx::FileInputWidget::setFilename
void setFilename(QString text)
Definition: cxFileInputWidget.cpp:58
cx::FileInputWidget::setDescription
void setDescription(QString text)
Definition: cxFileInputWidget.cpp:47