46 #include <QHBoxLayout>
54 mNameFilters <<
"*.mhd";
57 QHBoxLayout* dataLayout =
new QHBoxLayout(
this);
58 dataLayout->setMargin(0);
59 mDataComboBox =
new QComboBox(
this);
60 connect(mDataComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(currentDataComboIndexChanged(
int)));
62 mSelectDataAction =
new QAction(QIcon(
":/icons/open.png"), tr(
"&Select data"),
this);
63 connect(mSelectDataAction, SIGNAL(triggered()),
this, SLOT(selectData()));
64 mSelectDataButton =
new QToolButton(
this);
65 mSelectDataButton->setDefaultAction(mSelectDataAction);
67 dataLayout->addWidget(mDataComboBox);
68 dataLayout->addWidget(mSelectDataButton);
85 if (QFileInfo(mFilename).isDir())
88 mRootPaths << QFileInfo(mFilename).dir().absolutePath();
92 if (mRootPaths.isEmpty())
93 mRootPaths << QFileInfo(mFilename).dir().absolutePath();
103 mNameFilters = filter;
108 this->
setPaths(QStringList() << path);
120 void FileSelectWidget::selectData()
122 QString filter = mNameFilters.join(
";;");
124 if (!mRootPaths.isEmpty())
125 folder = mRootPaths.front();
126 QString filename = QFileDialog::getOpenFileName(
this, QString(tr(
"Select file")), folder, filter);
128 if (filename.isEmpty())
131 mFilename = filename;
141 for (
int i=0; i<mRootPaths.size(); ++i)
142 files << this->
getAllFiles(mRootPaths[i], mFolderDepth);
150 QStringList files = dir.entryList(mNameFilters, QDir::Files);
153 for (
int i = 0; i < files.size(); ++i)
155 retval << (dir.absolutePath() +
"/" + files[i]);
157 QStringList folders = dir.entryList(QStringList(), QDir::AllDirs | QDir::NoDotAndDotDot);
161 for (
int i = 0; i < folders.size(); ++i)
163 files = this->
getAllFiles(folder +
"/" + folders[i], depth-1);
164 retval.append(files);
173 this->updateComboBox();
176 void FileSelectWidget::updateComboBox()
178 mDataComboBox->blockSignals(
true);
179 mDataComboBox->clear();
182 for (
int i=0; i<mRootPaths.size(); ++i)
183 files << this->
getAllFiles(mRootPaths[i], mFolderDepth);
185 for (
int i = 0; i < files.size(); ++i)
187 mDataComboBox->addItem(QFileInfo(files[i]).fileName(), files[i]);
189 mDataComboBox->setCurrentIndex(-1);
190 for (
int i = 0; i < mDataComboBox->count(); ++i)
192 if (mDataComboBox->itemData(i) == mFilename)
193 mDataComboBox->setCurrentIndex(i);
196 if (!mFilename.isEmpty() && mDataComboBox->currentIndex() < 0 && !files.contains(mFilename))
198 mDataComboBox->addItem(QFileInfo(mFilename).fileName(), mFilename);
199 mDataComboBox->setCurrentIndex(mDataComboBox->count() - 1);
202 mDataComboBox->setToolTip(mFilename);
204 mDataComboBox->blockSignals(
false);
207 void FileSelectWidget::currentDataComboIndexChanged(
int index)
212 mFilename = mDataComboBox->itemData(index).toString();