-
Notifications
You must be signed in to change notification settings - Fork 1
/
qgsvctsourceselect.cpp
51 lines (41 loc) · 1.41 KB
/
qgsvctsourceselect.cpp
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
42
43
44
45
46
47
48
49
50
51
#include "qgsvctsourceselect.h"
#include "qgsgui.h"
#include "qgsvctprovider.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QFileInfo>
#include "qgsmessagelog.h"
QgsVctSourceSelect::QgsVctSourceSelect(QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode theWidgetMode)
: QgsAbstractDataSourceWidget( parent, fl, theWidgetMode )
{
setupUi(this);
QgsGui::instance()->enableAutoGeometryRestore(this);
setupButtons(buttonBox);
connect(toolButtonFilePath, &QAbstractButton::clicked, this, &QgsVctSourceSelect::openFileDialog);
connect(lineEditFilePath, &QLineEdit::textChanged, this, &QgsVctSourceSelect::onFileChanged);
}
void QgsVctSourceSelect::addButtonClicked()
{
emit addVectorLayer(lineEditFilePath->text(), lineEditLayerName->text());
}
void QgsVctSourceSelect::openFileDialog()
{
QString path = QFileDialog::getOpenFileName(this, tr("Choose a VCT File to Open"), "", tr("VCT files (*.vct *.VCT)"));
lineEditFilePath->setText(path);
}
void QgsVctSourceSelect::onFileChanged()
{
QFileInfo finfo(lineEditFilePath->text());
lineEditLayerName->setText(finfo.baseName());
bool addButtonEnabled = false;
emit enableButtons(addButtonEnabled);
//Check input
if (lineEditFilePath->text().isEmpty())
return;
if (!finfo.exists())
return;
if (!finfo.isFile())
return;
addButtonEnabled = true;
emit enableButtons(addButtonEnabled);
}