Skip to content

Commit

Permalink
Fix for ticket #483 (provide regular expressions in delimited text
Browse files Browse the repository at this point in the history
plugin)


git-svn-id: http://svn.osgeo.org/qgis/trunk@7385 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Nov 12, 2007
1 parent 4346694 commit 496b5fb
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 127 deletions.
45 changes: 39 additions & 6 deletions src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,23 @@ QgsDelimitedTextPluginGui::QgsDelimitedTextPluginGui(QgisInterface * _qI, QWidge
QString key = "/Plugin-DelimitedText";
txtDelimiter->setText(settings.readEntry(key + "/delimiter"));

// and how to use the delimiter
QString delimiterType = settings.value(key + "/delimiterType",
"plain").toString();
if (delimiterType == "plain")
{
delimiterPlain->setChecked(true);
delimiterRegexp->setChecked(false);
}
else
{
delimiterPlain->setChecked(false);
delimiterRegexp->setChecked(true);
}

teInstructions->setHtml(tr("<h1>Description</h1>"
"<p>Select a delimited text file containing x and y coordinates that you would like to use as a point layer and this plugin will do the job for you!</p>"
"<p>Use the layer name box to specify the legend name for the new layer. Use the delimiter box to specify what delimeter is used in your file (e.g. space, comma or tab). After choosing a delimiter, press the parse button and select the columns containing the x and y values for the layer.</p>"));
"<p>Use the layer name box to specify the legend name for the new layer. Use the delimiter box to specify what delimeter is used in your file (e.g. space, comma, tab or a regular expression in Perl style). After choosing a delimiter, press the parse button and select the columns containing the x and y values for the layer.</p>"));

}
QgsDelimitedTextPluginGui::~QgsDelimitedTextPluginGui()
Expand All @@ -68,9 +82,14 @@ void QgsDelimitedTextPluginGui::on_buttonBox_accepted()
if(txtLayerName->text().length() > 0)
{
//Build the delimited text URI from the user provided information
QString uri = QString("%1?delimiter=%2&xField=%3&yField=%4")
QString delimiterType = "plain";
if (delimiterRegexp->isChecked())
delimiterType = "regexp";

QString uri = QString("%1?delimiter=%2&delimiterType=%3&xField=%4&yField=%5")
.arg(txtFilePath->text())
.arg(txtDelimiter->text())
.arg(delimiterType)
.arg(cmbXField->currentText())
.arg(cmbYField->currentText());

Expand All @@ -84,6 +103,11 @@ void QgsDelimitedTextPluginGui::on_buttonBox_accepted()
QFileInfo fi(txtFilePath->text());
settings.writeEntry(key + "/text_path", fi.dirPath());

if (delimiterPlain->isChecked())
settings.setValue(key + "/delimiterType", "plain");
else
settings.setValue(key + "/delimiterType", "regexp");

accept();
}
else
Expand Down Expand Up @@ -122,10 +146,19 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
#endif
QString delimiter = txtDelimiter->text();

// convert \t to tabulator
delimiter.replace("\\t", "\t");

QStringList fieldList = QStringList::split(delimiter, line);
QStringList fieldList;

if (delimiterPlain->isChecked())
{
// convert \t to tabulator
delimiter.replace("\\t", "\t");
fieldList = line.split(delimiter);
}
else
{
QRegExp del(delimiter);
fieldList = line.split(QRegExp(delimiter));
}

#ifdef QGISDEBUG
std::cerr << "Split line into " << fieldList.size() << " parts" << std::endl;
Expand Down
Loading

0 comments on commit 496b5fb

Please sign in to comment.