Skip to content
Permalink
Browse files

BUG: Change ctkDirectoryButton into ctkPathLineEdit

*DO NOT INTEGRATE*

Know issue: When updating the Cache directory in setting panel, each
key stroke leads to the creation of path.

Fixes #1672

From: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>

git-svn-id: http://svn.slicer.org/Slicer4/trunk@22301 3bd1e089-480b-0410-8dfb-8563597acbee
  • Loading branch information...
jcfr committed Aug 20, 2013
1 parent 528c2e7 commit d508928514813067d230460c4e49e2714816d722
@@ -19,7 +19,6 @@
#include <QToolButton>

// CTK includes
#include <ctkDirectoryButton.h>
#include <ctkFlowLayout.h>
#include <ctkPathLineEdit.h>
#include <ctkSliderWidget.h>
@@ -100,7 +99,7 @@ WIDGET_VALUE_WRAPPER(Image, qMRMLNodeComboBox, currentNodeID, setCurrentNodeID,
WIDGET_VALUE_WRAPPER(Geometry, qMRMLNodeComboBox, currentNodeID, setCurrentNodeID, String, currentNodeIDChanged(QString));
WIDGET_VALUE_WRAPPER(Table, qMRMLNodeComboBox, currentNodeID, setCurrentNodeID, String, currentNodeIDChanged(QString));
WIDGET_VALUE_WRAPPER(Transform, qMRMLNodeComboBox, currentNodeID, setCurrentNodeID, String, currentNodeIDChanged(QString));
WIDGET_VALUE_WRAPPER(Directory, ctkDirectoryButton, directory, setDirectory, String, directoryChanged(QString));
WIDGET_VALUE_WRAPPER(Directory, ctkPathLineEdit, currentPath, setCurrentPath, String, currentPathChanged(QString));
WIDGET_VALUE_WRAPPER(File, ctkPathLineEdit, currentPath, setCurrentPath, String, currentPathChanged(QString));
WIDGET_VALUE_WRAPPER(Enumeration, ButtonGroupWidgetWrapper, checkedValue, setCheckedValue, String, valueChanged());
WIDGET_VALUE_WRAPPER(Measurement, qMRMLNodeComboBox, currentNodeID, setCurrentNodeID, String, currentNodeIDChanged(QString));
@@ -783,13 +782,18 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createDirectoryTagWidget(const ModuleP
{
QString _label = QString::fromStdString(moduleParameter.GetLabel());
QString _name = QString::fromStdString(moduleParameter.GetName());

ctkDirectoryButton* widget = new ctkDirectoryButton();
widget->setCaption(QString("Select %1 ...").arg(_name));

INSTANCIATE_WIDGET_VALUE_WRAPPER(Directory, _name, _label, widget);
ctkPathLineEdit* pathLineEdit =
new ctkPathLineEdit(_name, QStringList() << QString("*.*"), ctkPathLineEdit::Dirs);
pathLineEdit->setShowHistoryButton(false);
pathLineEdit->setOptions(ctkPathLineEdit::ShowDirsOnly);
pathLineEdit->setFilters(ctkPathLineEdit::Dirs | ctkPathLineEdit::Drives
| ctkPathLineEdit::NoDotAndDotDot | ctkPathLineEdit::Readable
| ctkPathLineEdit::Writable);

INSTANCIATE_WIDGET_VALUE_WRAPPER(Directory, _name, _label, pathLineEdit);

return widget;
return pathLineEdit;
}

//-----------------------------------------------------------------------------
@@ -798,22 +802,13 @@ QWidget* qSlicerCLIModuleUIHelperPrivate::createFileTagWidget(const ModuleParame
QString label = QString::fromStdString(moduleParameter.GetLabel());
QString name = QString::fromStdString(moduleParameter.GetName());

QWidget* widget = new QWidget;
ctkPathLineEdit* pathLineEdit =
new ctkPathLineEdit(name, QStringList() << QString("*.*"), ctkPathLineEdit::Files, widget);
QToolButton* browseButton = new QToolButton(widget);
browseButton->setText("...");
QObject::connect(browseButton, SIGNAL(clicked()),
pathLineEdit, SLOT(browse()));
new ctkPathLineEdit(name, QStringList() << QString("*.*"), ctkPathLineEdit::Files);
pathLineEdit->setShowHistoryButton(false);

INSTANCIATE_WIDGET_VALUE_WRAPPER(File, name, label, pathLineEdit);

QHBoxLayout* hBoxLayout = new QHBoxLayout;
hBoxLayout->setContentsMargins(0,0,0,0);
hBoxLayout->addWidget(pathLineEdit);
hBoxLayout->addWidget(browseButton);
widget->setLayout(hBoxLayout);
return widget;
return pathLineEdit;
}

//-----------------------------------------------------------------------------
@@ -97,12 +97,18 @@
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="ctkDirectoryButton" name="DirectoryButton">
<property name="text">
<string>Change directory for selected files</string>
<widget class="ctkPathLineEdit" name="DirectoryButton">
<property name="filters">
<set>ctkPathLineEdit::Dirs|ctkPathLineEdit::Drives|ctkPathLineEdit::NoDotAndDotDot|ctkPathLineEdit::Readable</set>
</property>
<property name="options">
<set>ctkDirectoryButton::DontUseNativeDialog</set>
<set>ctkPathLineEdit::DontUseNativeDialog|ctkPathLineEdit::ShowDirsOnly</set>
</property>
<property name="showHistoryButton">
<bool>false</bool>
</property>
<property name="text" stdset="0">
<string>Change directory for selected files</string>
</property>
</widget>
</item>
@@ -157,9 +163,9 @@
</widget>
<customwidgets>
<customwidget>
<class>ctkDirectoryButton</class>
<class>ctkPathLineEdit</class>
<extends>QWidget</extends>
<header>ctkDirectoryButton.h</header>
<header>ctkPathLineEdit.h</header>
</customwidget>
</customwidgets>
<resources>
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>329</width>
<height>267</height>
<height>302</height>
</rect>
</property>
<property name="windowTitle">
@@ -148,22 +148,32 @@
</widget>
</item>
<item row="1" column="1">
<widget class="ctkDirectoryButton" name="CachePathButton"/>
<widget class="ctkPathLineEdit" name="CachePathLineEdit">
<property name="filters">
<set>ctkPathLineEdit::Dirs|ctkPathLineEdit::Drives|ctkPathLineEdit::NoDotAndDotDot|ctkPathLineEdit::Readable|ctkPathLineEdit::Writable</set>
</property>
<property name="options">
<set>ctkPathLineEdit::ShowDirsOnly</set>
</property>
<property name="showHistoryButton">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ctkDirectoryButton</class>
<extends>QWidget</extends>
<header>ctkDirectoryButton.h</header>
</customwidget>
<customwidget>
<class>ctkSettingsPanel</class>
<extends>QWidget</extends>
<header>ctkSettingsPanel.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ctkPathLineEdit</class>
<extends>QWidget</extends>
<header>ctkPathLineEdit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
@@ -57,7 +57,17 @@
</widget>
</item>
<item row="2" column="1">
<widget class="ctkDirectoryButton" name="ExtensionsInstallPathButton"/>
<widget class="ctkPathLineEdit" name="ExtensionsInstallPathLineEdit">
<property name="filters">
<set>ctkPathLineEdit::Dirs|ctkPathLineEdit::Drives|ctkPathLineEdit::NoDotAndDotDot|ctkPathLineEdit::Readable|ctkPathLineEdit::Writable</set>
</property>
<property name="options">
<set>ctkPathLineEdit::ShowDirsOnly</set>
</property>
<property name="showHistoryButton">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
@@ -91,17 +101,17 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ctkDirectoryButton</class>
<extends>QWidget</extends>
<header>ctkDirectoryButton.h</header>
</customwidget>
<customwidget>
<class>ctkSettingsPanel</class>
<extends>QWidget</extends>
<header>ctkSettingsPanel.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ctkPathLineEdit</class>
<extends>QWidget</extends>
<header>ctkPathLineEdit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../qSlicerBaseQTGUI.qrc"/>
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>531</width>
<height>538</height>
<width>718</width>
<height>618</height>
</rect>
</property>
<property name="windowTitle">
@@ -46,7 +46,17 @@
</widget>
</item>
<item row="3" column="1">
<widget class="ctkDirectoryButton" name="TemporaryDirectoryButton"/>
<widget class="ctkPathLineEdit" name="TemporaryPathLineEdit">
<property name="filters">
<set>ctkPathLineEdit::Dirs|ctkPathLineEdit::Drives|ctkPathLineEdit::NoDotAndDotDot|ctkPathLineEdit::Readable|ctkPathLineEdit::Writable</set>
</property>
<property name="options">
<set>ctkPathLineEdit::ShowDirsOnly</set>
</property>
<property name="showHistoryButton">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="AdditionalModulePathsLabel">
@@ -577,37 +587,42 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ctkSettingsPanel</class>
<extends>QWidget</extends>
<header>ctkSettingsPanel.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>qSlicerModulesListView</class>
<extends>QListView</extends>
<extends></extends>
<header>qSlicerModulesListView.h</header>
</customwidget>
<customwidget>
<class>ctkCheckablePushButton</class>
<extends>QPushButton</extends>
<extends>ctkPushButton</extends>
<header>ctkCheckablePushButton.h</header>
</customwidget>
<customwidget>
<class>ctkDirectoryButton</class>
<extends>QWidget</extends>
<header>ctkDirectoryButton.h</header>
</customwidget>
<customwidget>
<class>ctkExpandButton</class>
<extends>QToolButton</extends>
<header>ctkExpandButton.h</header>
</customwidget>
<customwidget>
<class>ctkPathLineEdit</class>
<extends>QWidget</extends>
<header>ctkPathLineEdit.h</header>
</customwidget>
<customwidget>
<class>ctkPushButton</class>
<extends>QPushButton</extends>
<header>ctkPushButton.h</header>
</customwidget>
<customwidget>
<class>ctkSearchBox</class>
<extends>QLineEdit</extends>
<header>ctkSearchBox.h</header>
</customwidget>
<customwidget>
<class>ctkSettingsPanel</class>
<extends>QWidget</extends>
<header>ctkSettingsPanel.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>qSlicerDirectoryListView</class>
<extends>QWidget</extends>
@@ -160,7 +160,7 @@ qSlicerSaveDataDialogPrivate::qSlicerSaveDataDialogPrivate(QWidget* parentWidget
this->FileWidget->setHorizontalHeader(headerView);

// Connect push buttons to associated actions
connect(this->DirectoryButton, SIGNAL(directorySelected(QString)),
connect(this->DirectoryButton, SIGNAL(currentPathChanged(QString)),
this, SLOT(setDirectory(QString)));
connect(this->SelectSceneDataButton, SIGNAL(clicked()),
this, SLOT(selectModifiedSceneData()));
@@ -206,10 +206,10 @@ void qSlicerSaveDataDialogPrivate::setDirectory(const QString& newDirectory)
{
continue;
}
ctkDirectoryButton* directoryItemButton = qobject_cast<ctkDirectoryButton*>(
ctkPathLineEdit* directoryItemPathLineEdit = qobject_cast<ctkPathLineEdit*>(
this->FileWidget->cellWidget(row, FileDirectoryColumn));
Q_ASSERT(directoryItemButton);
directoryItemButton->setDirectory(newDir.path());
Q_ASSERT(directoryItemPathLineEdit);
directoryItemPathLineEdit->setCurrentPath(newDir.path());
}
}

@@ -233,7 +233,7 @@ void qSlicerSaveDataDialogPrivate::populateItems()
// Moreover, we want to have the MRML scene to be the first item.
this->FileWidget->setSortingEnabled(false);

this->DirectoryButton->setDirectory(this->MRMLScene->GetRootDirectory());
this->DirectoryButton->setCurrentPath(this->MRMLScene->GetRootDirectory());

this->populateScene();

@@ -342,9 +342,14 @@ void qSlicerSaveDataDialogPrivate::populateScene()
this->FileWidget->setItem( row, FileNameColumn, fileNameItem);

// Scene Directory
ctkDirectoryButton* sceneDirectoryButton =
new ctkDirectoryButton(this->MRMLScene->GetRootDirectory(), this->FileWidget);
this->FileWidget->setCellWidget(row, FileDirectoryColumn, sceneDirectoryButton);
ctkPathLineEdit* scenePathLineEdit = new ctkPathLineEdit(this->FileWidget);
scenePathLineEdit->setShowHistoryButton(false);
scenePathLineEdit->setCurrentPath(this->MRMLScene->GetRootDirectory());
scenePathLineEdit->setOptions(ctkPathLineEdit::ShowDirsOnly);
scenePathLineEdit->setFilters(ctkPathLineEdit::Dirs | ctkPathLineEdit::Drives
| ctkPathLineEdit::NoDotAndDotDot | ctkPathLineEdit::Readable
| ctkPathLineEdit::Writable);
this->FileWidget->setCellWidget(row, FileDirectoryColumn, scenePathLineEdit);

// Scene Selected
QTableWidgetItem* selectItem = this->FileWidget->item(row, SelectColumn);
@@ -479,14 +484,14 @@ QFileInfo qSlicerSaveDataDialogPrivate::nodeFileInfo(vtkMRMLStorableNode* node)
}
}
}
if (snode->GetFileName() == 0 && !this->DirectoryButton->directory().isEmpty())
if (snode->GetFileName() == 0 && !this->DirectoryButton->currentPath().isEmpty())
{
QString fileExtension = snode->GetDefaultWriteFileExtension();
if (!fileExtension.isEmpty())
{
fileExtension = QString(".") + fileExtension;
}
QFileInfo fileName(QDir(this->DirectoryButton->directory()),
QFileInfo fileName(QDir(this->DirectoryButton->currentPath()),
QString(node->GetName()) + fileExtension);
snode->SetFileName(fileName.absoluteFilePath().toLatin1());
}
@@ -644,7 +649,14 @@ ::createFileNameItem(const QFileInfo& fileInfo, const QString& extension)
QWidget* qSlicerSaveDataDialogPrivate::createFileDirectoryWidget(const QFileInfo& fileInfo)
{
// TODO: use QSignalMapper
return new ctkDirectoryButton(fileInfo.absolutePath(),this->FileWidget);
ctkPathLineEdit * fileDirectoryWidget = new ctkPathLineEdit(this->FileWidget);
fileDirectoryWidget->setShowHistoryButton(false);
fileDirectoryWidget->setCurrentPath(fileInfo.absolutePath());
fileDirectoryWidget->setOptions(ctkPathLineEdit::ShowDirsOnly);
fileDirectoryWidget->setFilters(ctkPathLineEdit::Dirs | ctkPathLineEdit::Drives
| ctkPathLineEdit::NoDotAndDotDot | ctkPathLineEdit::Readable
| ctkPathLineEdit::Writable);
return fileDirectoryWidget;
}

//-----------------------------------------------------------------------------
@@ -805,11 +817,11 @@ QFileInfo qSlicerSaveDataDialogPrivate::file(int row)const
QTableWidgetItem* fileNameItem = this->FileWidget->item(row, FileNameColumn);
Q_ASSERT(fileNameItem);

ctkDirectoryButton* fileDirectoryButton = qobject_cast<ctkDirectoryButton*>(
ctkPathLineEdit* filePathLineEdit = qobject_cast<ctkPathLineEdit*>(
this->FileWidget->cellWidget(row, FileDirectoryColumn));
Q_ASSERT(fileDirectoryButton);
Q_ASSERT(filePathLineEdit);

QDir directory = fileDirectoryButton->directory();
QDir directory = filePathLineEdit->currentPath();
return QFileInfo(directory, fileNameItem->text());
}

@@ -924,10 +936,10 @@ QFileInfo qSlicerSaveDataDialogPrivate::sceneFile()const
int sceneRow = this->findSceneRow();

QTableWidgetItem* fileNameItem = this->FileWidget->item(sceneRow, FileNameColumn);
ctkDirectoryButton* fileDirectoryButton = qobject_cast<ctkDirectoryButton*>(
ctkPathLineEdit* filePathLineEdit = qobject_cast<ctkPathLineEdit*>(
this->FileWidget->cellWidget(sceneRow, FileDirectoryColumn));

QDir directory = fileDirectoryButton->directory();
QDir directory = filePathLineEdit->currentPath();
QFileInfo file = QFileInfo(directory, fileNameItem->text());
if (file.fileName().isEmpty())
{
Oops, something went wrong.

0 comments on commit d508928

Please sign in to comment.
You can’t perform that action at this time.