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;
138 QStringList FileSelectWidget::getAllFiles(QString folder,
int depth)
141 QStringList files = dir.entryList(mNameFilters, QDir::Files);
144 for (
int i = 0; i < files.size(); ++i)
146 retval << (dir.absolutePath() +
"/" + files[i]);
148 QStringList folders = dir.entryList(QStringList(), QDir::AllDirs | QDir::NoDotAndDotDot);
152 for (
int i = 0; i < folders.size(); ++i)
154 files = this->getAllFiles(folder +
"/" + folders[i], depth-1);
155 retval.append(files);
164 this->updateComboBox();
167 void FileSelectWidget::updateComboBox()
169 mDataComboBox->blockSignals(
true);
170 mDataComboBox->clear();
173 for (
int i=0; i<mRootPaths.size(); ++i)
174 files << this->getAllFiles(mRootPaths[i], mFolderDepth);
176 for (
int i = 0; i < files.size(); ++i)
178 mDataComboBox->addItem(QFileInfo(files[i]).fileName(), files[i]);
180 mDataComboBox->setCurrentIndex(-1);
181 for (
int i = 0; i < mDataComboBox->count(); ++i)
183 if (mDataComboBox->itemData(i) == mFilename)
184 mDataComboBox->setCurrentIndex(i);
187 if (!mFilename.isEmpty() && mDataComboBox->currentIndex() < 0 && !files.contains(mFilename))
189 mDataComboBox->addItem(QFileInfo(mFilename).fileName(), mFilename);
190 mDataComboBox->setCurrentIndex(mDataComboBox->count() - 1);
193 mDataComboBox->setToolTip(mFilename);
195 mDataComboBox->blockSignals(
false);
198 void FileSelectWidget::currentDataComboIndexChanged(
int index)
203 mFilename = mDataComboBox->itemData(index).toString();