-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectableComboBox.cpp
More file actions
41 lines (37 loc) · 1.15 KB
/
Copy pathSelectableComboBox.cpp
File metadata and controls
41 lines (37 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "SelectableComboBox.h"
#include <QFileDialog>
SelectableComboBox::SelectableComboBox(QWidget* parent) : SetTextComboBox(parent)
{
addItem(tr("No file"));
addItem(tr("Select ..."));
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onSetCurrentIndex(int)));
}
void SelectableComboBox::onSetCurrentIndex(int idx)
{
if(currentText() == tr("Select ...")) // select
{
QString fileName = QFileDialog::getOpenFileName
(this, tr("Open File"), ".", fileFilter);
if(!fileName.isEmpty())
{
disconnect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onSetCurrentIndex(int)));
insertItem(idx, QFileInfo(fileName).filePath());
setCurrentIndex(idx);
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onSetCurrentIndex(int)));
}
}
}
QStringList SelectableComboBox::getFiles() const
{
QStringList result;
for(int i=0; i<count(); ++i)
if(itemText(i) != tr("No file") && itemText(i) != tr("Select ..."))
result << itemText(i);
return result;
}
void SelectableComboBox::setFiles(const QStringList& files)
{
int row = 1;
foreach(QString file, files)
insertItem(row++, file);
}