25 #include <QHBoxLayout>
33 mNameFilters <<
"*.mhd";
36 QHBoxLayout* dataLayout =
new QHBoxLayout(
this);
37 dataLayout->setMargin(0);
38 mDataComboBox =
new QComboBox(
this);
39 connect(mDataComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(currentDataComboIndexChanged(
int)));
41 mSelectDataAction =
new QAction(QIcon(
":/icons/open.png"), tr(
"&Select data"),
this);
42 connect(mSelectDataAction, SIGNAL(triggered()),
this, SLOT(selectData()));
43 mSelectDataButton =
new QToolButton(
this);
44 mSelectDataButton->setDefaultAction(mSelectDataAction);
46 dataLayout->addWidget(mDataComboBox);
47 dataLayout->addWidget(mSelectDataButton);
64 if (QFileInfo(mFilename).isDir())
67 mRootPaths << QFileInfo(mFilename).dir().absolutePath();
71 if (mRootPaths.isEmpty())
72 mRootPaths << QFileInfo(mFilename).dir().absolutePath();
82 mNameFilters = filter;
87 this->
setPaths(QStringList() << path);
99 void FileSelectWidget::selectData()
101 QString filter = mNameFilters.join(
";;");
103 if (!mRootPaths.isEmpty())
104 folder = mRootPaths.front();
105 QString filename = QFileDialog::getOpenFileName(
this, QString(tr(
"Select file")), folder, filter);
107 if (filename.isEmpty())
110 mFilename = filename;
120 for (
int i=0; i<mRootPaths.size(); ++i)
121 files << this->
getAllFiles(mRootPaths[i], mFolderDepth);
129 QStringList files = dir.entryList(mNameFilters, QDir::Files);
132 for (
int i = 0; i < files.size(); ++i)
134 retval << (dir.absolutePath() +
"/" + files[i]);
136 QStringList folders = dir.entryList(QStringList(), QDir::AllDirs | QDir::NoDotAndDotDot);
140 for (
int i = 0; i < folders.size(); ++i)
142 files = this->
getAllFiles(folder +
"/" + folders[i], depth-1);
143 retval.append(files);
152 this->updateComboBox();
155 void FileSelectWidget::updateComboBox()
157 mDataComboBox->blockSignals(
true);
158 mDataComboBox->clear();
161 for (
int i=0; i<mRootPaths.size(); ++i)
162 files << this->
getAllFiles(mRootPaths[i], mFolderDepth);
164 for (
int i = 0; i < files.size(); ++i)
166 mDataComboBox->addItem(QFileInfo(files[i]).fileName(), files[i]);
168 mDataComboBox->setCurrentIndex(-1);
169 for (
int i = 0; i < mDataComboBox->count(); ++i)
171 if (mDataComboBox->itemData(i) == mFilename)
172 mDataComboBox->setCurrentIndex(i);
175 if (!mFilename.isEmpty() && mDataComboBox->currentIndex() < 0 && !files.contains(mFilename))
177 mDataComboBox->addItem(QFileInfo(mFilename).fileName(), mFilename);
178 mDataComboBox->setCurrentIndex(mDataComboBox->count() - 1);
181 mDataComboBox->setToolTip(mFilename);
183 mDataComboBox->blockSignals(
false);
186 void FileSelectWidget::currentDataComboIndexChanged(
int index)
191 mFilename = mDataComboBox->itemData(index).toString();