CustusX  22.04-rc3
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
FilenameWidget(QWidget *parent, FilePathPropertyPtr, QGridLayout *gridLayout=0, int row=0)
void setDescription(QString text)
void setBasePath(QString path)
void setFilename(QString text)
void setUseRelativePath(bool on)
void setHelp(QString text)
void setBrowseHelp(QString text)
Interface for all classes following the modified/prepaint paradigm.
boost::shared_ptr< class FilePathProperty > FilePathPropertyPtr
QString getFilename() const
Namespace for all CustusX production code.