Skip to content

Commit 1b53e28

Browse files
author
telwertowski
committedFeb 4, 2007
Added QgsFileDropEdit class which extends QLineEdit to accept files dropped on the edit field.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6513 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

12 files changed

+292
-45
lines changed

12 files changed

+292
-45
lines changed
 

‎src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ qgisinterface.cpp
55
qgscolorbutton.cpp
66
qgscursors.cpp
77
qgsencodingfiledialog.cpp
8+
qgsfiledropedit.cpp
89
qgslayerprojectionselector.cpp
910
qgsmapcanvas.cpp
1011
qgsmapcanvasitem.cpp

‎src/gui/qgsfiledropedit.cpp

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/***************************************************************************
2+
qgsfiledropedit.cpp - File Dropable LineEdit
3+
--------------------------------------
4+
Date : 31-Jan-2007
5+
Copyright : (C) 2007 by Tom Elwertowski
6+
Email : telwertowski at users dot sourceforge dot net
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
/* $Id$ */
16+
17+
#include "qgsfiledropedit.h"
18+
#include <QDropEvent>
19+
#include <QFileInfo>
20+
#include <QPainter>
21+
#include <QUrl>
22+
23+
/*!
24+
\class QgsFileDropEdit
25+
26+
\brief The QgsDropNameEdit class provides a line edit widget which
27+
accepts file drops.
28+
29+
Dropping can be limited to files only, files with a specific extension
30+
or directories only. By default, dropping is limited to files only.
31+
*/
32+
33+
QgsFileDropEdit::QgsFileDropEdit(QWidget *parent)
34+
: QLineEdit(parent)
35+
{
36+
mDirOnly = false;
37+
mFileOnly = true;
38+
mDragActive = false;
39+
setAcceptDrops(true);
40+
}
41+
42+
QgsFileDropEdit::~QgsFileDropEdit()
43+
{}
44+
45+
/*!
46+
Limit drops to directories.
47+
*/
48+
void QgsFileDropEdit::setDirOnly(bool dirOnly)
49+
{
50+
mDirOnly = dirOnly;
51+
if (mDirOnly)
52+
{
53+
mFileOnly = false;
54+
}
55+
}
56+
57+
/*!
58+
Limit drops to files.
59+
*/
60+
void QgsFileDropEdit::setFileOnly(bool fileOnly)
61+
{
62+
mFileOnly = fileOnly;
63+
if (mFileOnly)
64+
{
65+
mDirOnly = false;
66+
}
67+
}
68+
69+
/*!
70+
Limit drops to files with specified extension.
71+
*/
72+
void QgsFileDropEdit::setSuffixFilter(const QString& suffix)
73+
{
74+
mSuffix = suffix;
75+
}
76+
77+
/*!
78+
Return file name if object meets drop criteria.
79+
*/
80+
QString QgsFileDropEdit::acceptableFilePath(QDropEvent *event) const
81+
{
82+
QString path;
83+
if (event->mimeData()->hasUrls())
84+
{
85+
QFileInfo file(event->mimeData()->urls().first().toLocalFile());
86+
if ( !( mFileOnly && !file.isFile() ||
87+
mDirOnly && !file.isDir() ||
88+
!mSuffix.isEmpty() && mSuffix.compare(file.suffix(), Qt::CaseInsensitive) ) )
89+
path = file.filePath();
90+
}
91+
return path;
92+
}
93+
94+
/*!
95+
Check if dragged object is acceptible. Called when a drag is in progress
96+
and the mouse enters this widget.
97+
*/
98+
void QgsFileDropEdit::dragEnterEvent(QDragEnterEvent *event)
99+
{
100+
QString filePath = acceptableFilePath(event);
101+
if (!filePath.isEmpty())
102+
{
103+
event->acceptProposedAction();
104+
mDragActive = true;
105+
update();
106+
}
107+
else
108+
{
109+
QLineEdit::dragEnterEvent(event);
110+
}
111+
}
112+
113+
/*!
114+
Called when a drag is in progress and the mouse leaves this widget.
115+
*/
116+
void QgsFileDropEdit::dragLeaveEvent(QDragLeaveEvent *event)
117+
{
118+
QLineEdit::dragLeaveEvent(event);
119+
event->accept();
120+
mDragActive = false;
121+
update();
122+
}
123+
124+
/*!
125+
Receive the dragged object. Called when the drag is dropped on this widget.
126+
*/
127+
void QgsFileDropEdit::dropEvent(QDropEvent *event)
128+
{
129+
QString filePath = acceptableFilePath(event);
130+
if (!filePath.isEmpty())
131+
{
132+
setText(filePath);
133+
selectAll();
134+
setFocus(Qt::MouseFocusReason);
135+
event->acceptProposedAction();
136+
mDragActive = false;
137+
update();
138+
}
139+
else
140+
{
141+
QLineEdit::dropEvent(event);
142+
}
143+
}
144+
145+
/*!
146+
Paints line edit with drag highlight in response to a paint event.
147+
*/
148+
void QgsFileDropEdit::paintEvent(QPaintEvent *e)
149+
{
150+
QLineEdit::paintEvent(e);
151+
if (mDragActive)
152+
{
153+
QPainter p(this);
154+
int width = 2; // width of highlight rectangle inside frame
155+
p.setPen(QPen(palette().highlight(), width));
156+
QRect r = rect().adjusted(width, width, -width, -width);
157+
p.drawRect(r);
158+
}
159+
}

‎src/gui/qgsfiledropedit.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/***************************************************************************
2+
qgsfiledropedit.h - File Dropable LineEdit
3+
--------------------------------------
4+
Date : 31-Jan-2007
5+
Copyright : (C) 2007 by Tom Elwertowski
6+
Email : telwertowski at users dot sourceforge dot net
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
/* $Id$ */
16+
#ifndef QGSFILEDROPEDIT_H
17+
#define QGSFILEDROPEDIT_H
18+
19+
#include <QLineEdit>
20+
21+
class GUI_EXPORT QgsFileDropEdit: public QLineEdit
22+
{
23+
public:
24+
QgsFileDropEdit(QWidget *parent = 0);
25+
virtual ~QgsFileDropEdit();
26+
27+
bool dirOnly() const { return mDirOnly; }
28+
void setDirOnly(bool dirOnly);
29+
30+
bool fileOnly() const { return mFileOnly; }
31+
void setFileOnly(bool fileOnly);
32+
33+
const QString& suffixFilter() const { return mSuffix; }
34+
void setSuffixFilter( const QString& suffix);
35+
36+
protected:
37+
38+
virtual void dragEnterEvent(QDragEnterEvent *event);
39+
virtual void dragLeaveEvent(QDragLeaveEvent *event);
40+
virtual void dropEvent(QDropEvent *event);
41+
virtual void paintEvent(QPaintEvent *e);
42+
43+
private:
44+
QString acceptableFilePath(QDropEvent *event) const;
45+
46+
QString mSuffix;
47+
bool mDirOnly;
48+
bool mFileOnly;
49+
bool mDragActive;
50+
};
51+
52+
#endif

‎src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ QgsDelimitedTextPluginGui::QgsDelimitedTextPluginGui(QgisInterface * _qI, QWidge
3434
pbnOK = buttonBox->button(QDialogButtonBox::Ok);
3535
pbnParse = buttonBox->addButton(tr("Parse"), QDialogButtonBox::ActionRole);
3636
connect(pbnParse, SIGNAL(clicked()), this, SLOT(on_pbnParse_clicked()));
37+
connect(txtFilePath, SIGNAL(textChanged(const QString&)), this, SLOT(on_pbnParse_clicked()));
3738
enableButtons();
3839
// at startup, fetch the last used delimiter and directory from
3940
// settings

‎src/plugins/delimited_text/qgsdelimitedtextpluginguibase.ui

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
</widget>
217217
</item>
218218
<item>
219-
<widget class="QLineEdit" name="txtFilePath" >
219+
<widget class="QgsFileDropEdit" name="txtFilePath" >
220220
<property name="toolTip" >
221221
<string>Full path to the delimited text file</string>
222222
</property>
@@ -332,6 +332,11 @@
332332
<header>Qt3Support/Q3GroupBox</header>
333333
<container>1</container>
334334
</customwidget>
335+
<customwidget>
336+
<class>QgsFileDropEdit</class>
337+
<extends>QLineEdit</extends>
338+
<header>qgsfiledropedit.h</header>
339+
</customwidget>
335340
<customwidget>
336341
<class>Q3TextEdit</class>
337342
<extends>Q3Frame</extends>

‎src/plugins/georeferencer/pluginguibase.ui

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<ui version="4.0" >
2-
<author></author>
3-
<comment></comment>
4-
<exportmacro></exportmacro>
52
<class>QgsGeorefPluginGuiBase</class>
63
<widget class="QDialog" name="QgsGeorefPluginGuiBase" >
74
<property name="geometry" >
@@ -125,12 +122,12 @@
125122
</sizepolicy>
126123
</property>
127124
<property name="text" >
128-
<string>...</string>
125+
<string>Browse...</string>
129126
</property>
130127
</widget>
131128
</item>
132129
<item row="1" column="3" >
133-
<widget class="QLineEdit" name="leSelectRaster" >
130+
<widget class="QgsFileDropEdit" name="leSelectRaster" >
134131
<property name="sizePolicy" >
135132
<sizepolicy>
136133
<hsizetype>7</hsizetype>
@@ -144,7 +141,13 @@
144141
</layout>
145142
</widget>
146143
<layoutdefault spacing="6" margin="11" />
147-
<pixmapfunction></pixmapfunction>
144+
<customwidgets>
145+
<customwidget>
146+
<class>QgsFileDropEdit</class>
147+
<extends>QLineEdit</extends>
148+
<header>qgsfiledropedit.h</header>
149+
</customwidget>
150+
</customwidgets>
148151
<resources>
149152
<include location="georeferencer.qrc" />
150153
</resources>

‎src/plugins/georeferencer/qgspointdialogbase.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,14 @@
228228
<item row="2" column="7" >
229229
<widget class="QPushButton" name="pbnSelectModifiedRaster" >
230230
<property name="text" >
231-
<string>...</string>
231+
<string>Save As...</string>
232232
</property>
233233
</widget>
234234
</item>
235235
<item row="3" column="7" >
236236
<widget class="QPushButton" name="pbnSelectWorldFile" >
237237
<property name="text" >
238-
<string>...</string>
238+
<string>Save As...</string>
239239
</property>
240240
</widget>
241241
</item>

‎src/plugins/gps_importer/qgsgpsplugingui.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ QgsGPSPluginGui::QgsGPSPluginGui(const BabelMap& importers,
6161
this, SLOT(enableRelevantControls()));
6262
connect(tabWidget, SIGNAL(currentChanged(int)),
6363
this, SLOT(enableRelevantControls()));
64-
}
64+
65+
// drag and drop filter
66+
leGPXFile->setSuffixFilter("gpx");
67+
}
68+
6569
QgsGPSPluginGui::~QgsGPSPluginGui()
6670
{
6771
}
@@ -139,7 +143,8 @@ void QgsGPSPluginGui::on_pbnDLOutput_clicked()
139143
tr("Choose a filename to save under"),
140144
"." , //initial dir
141145
tr("GPS eXchange format (*.gpx)"));
142-
leDLOutput->setText(myFileNameQString);
146+
if (!myFileNameQString.isEmpty())
147+
leDLOutput->setText(myFileNameQString);
143148
}
144149

145150

@@ -220,7 +225,8 @@ void QgsGPSPluginGui::on_pbnGPXSelectFile_clicked()
220225
myFilterString, //filters to select
221226
&myFileTypeQString); //the pointer to store selected filter
222227
QgsLogger::debug("Selected filetype filter is : " + myFileTypeQString);
223-
leGPXFile->setText(myFileNameQString);
228+
if (!myFileNameQString.isEmpty())
229+
leGPXFile->setText(myFileNameQString);
224230
}
225231

226232

@@ -232,23 +238,26 @@ void QgsGPSPluginGui::on_pbnIMPInput_clicked() {
232238
".", //initial dir
233239
mBabelFilter,
234240
&myFileType); //the pointer to store selected filter
235-
mImpFormat = myFileType.left(myFileType.length() - 6);
236-
std::map<QString, QgsBabelFormat*>::const_iterator iter;
237-
iter = mImporters.find(mImpFormat);
238-
if (iter == mImporters.end()) {
239-
QgsLogger::warning("Unknown file format selected: " +
240-
myFileType.left(myFileType.length() - 6));
241-
}
242-
else {
243-
QgsLogger::debug(iter->first + " selected");
244-
leIMPInput->setText(myFileName);
245-
cmbIMPFeature->clear();
246-
if (iter->second->supportsWaypoints())
247-
cmbIMPFeature->insertItem("Waypoints");
248-
if (iter->second->supportsRoutes())
249-
cmbIMPFeature->insertItem("Routes");
250-
if (iter->second->supportsTracks())
251-
cmbIMPFeature->insertItem("Tracks");
241+
if (!myFileName.isEmpty())
242+
{
243+
mImpFormat = myFileType.left(myFileType.length() - 6);
244+
std::map<QString, QgsBabelFormat*>::const_iterator iter;
245+
iter = mImporters.find(mImpFormat);
246+
if (iter == mImporters.end()) {
247+
QgsLogger::warning("Unknown file format selected: " +
248+
myFileType.left(myFileType.length() - 6));
249+
}
250+
else {
251+
QgsLogger::debug(iter->first + " selected");
252+
leIMPInput->setText(myFileName);
253+
cmbIMPFeature->clear();
254+
if (iter->second->supportsWaypoints())
255+
cmbIMPFeature->insertItem("Waypoints");
256+
if (iter->second->supportsRoutes())
257+
cmbIMPFeature->insertItem("Routes");
258+
if (iter->second->supportsTracks())
259+
cmbIMPFeature->insertItem("Tracks");
260+
}
252261
}
253262
}
254263

@@ -259,7 +268,8 @@ void QgsGPSPluginGui::on_pbnIMPOutput_clicked() {
259268
tr("Choose a filename to save under"),
260269
".", //initial dir
261270
tr("GPS eXchange format (*.gpx)"));
262-
leIMPOutput->setText(myFileNameQString);
271+
if (!myFileNameQString.isEmpty())
272+
leIMPOutput->setText(myFileNameQString);
263273
}
264274

265275

‎src/plugins/gps_importer/qgsgpspluginguibase.ui

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ p, li { white-space: pre-wrap; }
104104
</widget>
105105
</item>
106106
<item row="2" column="0" >
107-
<widget class="QLineEdit" name="leGPXFile" />
107+
<widget class="QgsFileDropEdit" name="leGPXFile" />
108108
</item>
109109
<item row="3" column="0" >
110110
<widget class="QLabel" name="lblGPXFeatureTypes" >
@@ -192,7 +192,7 @@ p, li { white-space: pre-wrap; }
192192
<item row="3" column="3" >
193193
<widget class="QPushButton" name="pbnIMPOutput" >
194194
<property name="text" >
195-
<string>Browse...</string>
195+
<string>Save As...</string>
196196
</property>
197197
</widget>
198198
</item>
@@ -388,7 +388,7 @@ p, li { white-space: pre-wrap; }
388388
<item row="3" column="4" >
389389
<widget class="QPushButton" name="pbnDLOutput" >
390390
<property name="text" >
391-
<string>Browse...</string>
391+
<string>Save As...</string>
392392
</property>
393393
</widget>
394394
</item>
@@ -489,6 +489,13 @@ p, li { white-space: pre-wrap; }
489489
</layout>
490490
</widget>
491491
<layoutdefault spacing="6" margin="11" />
492+
<customwidgets>
493+
<customwidget>
494+
<class>QgsFileDropEdit</class>
495+
<extends>QLineEdit</extends>
496+
<header>qgsfiledropedit.h</header>
497+
</customwidget>
498+
</customwidgets>
492499
<resources>
493500
<include location="qgsgps_plugin.qrc" />
494501
</resources>

‎tools/mapserver_export/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ SET (MSEXPORT_UIS qgsmapserverexportbase.ui)
1818

1919
QT4_WRAP_UI (MSEXPORT_UIS_H ${MSEXPORT_UIS})
2020

21-
QT4_WRAP_CPP (MSEXPORT_MOC_SRCS ${MSEXPORT_MOC_HDRS} ${MSEXPORT_UIS_H})
21+
QT4_WRAP_CPP (MSEXPORT_MOC_SRCS ${MSEXPORT_MOC_HDRS})
2222

2323
INCLUDE_DIRECTORIES (
2424
${CMAKE_CURRENT_BINARY_DIR}
2525
${PYTHON_INCLUDE_PATH}
2626
${CMAKE_SOURCE_DIR}/src/core
27+
${CMAKE_SOURCE_DIR}/src/gui
2728
)
2829

29-
ADD_EXECUTABLE (msexport MACOSX_BUNDLE ${MSEXPORT_SRCS} ${MSEXPORT_MOC_SRCS})
30+
ADD_EXECUTABLE (msexport MACOSX_BUNDLE ${MSEXPORT_SRCS} ${MSEXPORT_MOC_SRCS} ${MSEXPORT_UIS_H})
3031

3132
TARGET_LINK_LIBRARIES (msexport
3233
${QT_LIBRARIES}
3334
${PYTHON_LIBRARIES}
3435
qgis_core
36+
qgis_gui
3537
)
3638

3739

‎tools/mapserver_export/qgsmapserverexport.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ QgsMapserverExport::QgsMapserverExport(QWidget * parent, Qt::WFlags fl)
3939
{
4040
setupUi(this);
4141
connect(this, SIGNAL(accepted()), this, SLOT(apply()));
42-
// initialize python
42+
// drag and drop filter
43+
txtQgisFilePath->setSuffixFilter("qgs");
44+
// initialize python
4345
initPy();
4446
qDebug("Reading setttings");
4547
QSettings mySettings;

‎tools/mapserver_export/qgsmapserverexportbase.ui

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
</widget>
6464
</item>
6565
<item>
66-
<widget class="QLineEdit" name="txtWebTemplate" >
66+
<widget class="QgsFileDropEdit" name="txtWebTemplate" >
6767
<property name="toolTip" >
6868
<string>Path to the MapServer template file</string>
6969
</property>
@@ -72,7 +72,7 @@
7272
<item>
7373
<widget class="QPushButton" name="btnChooseTemplateFile" >
7474
<property name="text" >
75-
<string>Other...</string>
75+
<string>Browse...</string>
7676
</property>
7777
</widget>
7878
</item>
@@ -103,12 +103,12 @@
103103
</widget>
104104
</item>
105105
<item>
106-
<widget class="QLineEdit" name="txtWebHeader" />
106+
<widget class="QgsFileDropEdit" name="txtWebHeader" />
107107
</item>
108108
<item>
109109
<widget class="QPushButton" name="btnChooseHeaderFile" >
110110
<property name="text" >
111-
<string>Other...</string>
111+
<string>Browse...</string>
112112
</property>
113113
</widget>
114114
</item>
@@ -139,12 +139,12 @@
139139
</widget>
140140
</item>
141141
<item>
142-
<widget class="QLineEdit" name="txtWebFooter" />
142+
<widget class="QgsFileDropEdit" name="txtWebFooter" />
143143
</item>
144144
<item>
145145
<widget class="QPushButton" name="btnChooseFooterFile" >
146146
<property name="text" >
147-
<string>Other...</string>
147+
<string>Browse...</string>
148148
</property>
149149
</widget>
150150
</item>
@@ -366,12 +366,12 @@
366366
<item row="1" column="2" >
367367
<widget class="QPushButton" name="btnChooseProjectFile" >
368368
<property name="text" >
369-
<string>Other...</string>
369+
<string>Browse...</string>
370370
</property>
371371
</widget>
372372
</item>
373373
<item row="1" column="1" >
374-
<widget class="QLineEdit" name="txtQgisFilePath" >
374+
<widget class="QgsFileDropEdit" name="txtQgisFilePath" >
375375
<property name="toolTip" >
376376
<string>Full path to the QGIS project file to export to MapServer map format</string>
377377
</property>
@@ -390,7 +390,7 @@
390390
<item row="0" column="2" >
391391
<widget class="QPushButton" name="btnChooseFile" >
392392
<property name="text" >
393-
<string>Other...</string>
393+
<string>Save As...</string>
394394
</property>
395395
</widget>
396396
</item>
@@ -425,6 +425,11 @@
425425
<header>Qt3Support/Q3GroupBox</header>
426426
<container>1</container>
427427
</customwidget>
428+
<customwidget>
429+
<class>QgsFileDropEdit</class>
430+
<extends>QLineEdit</extends>
431+
<header>qgsfiledropedit.h</header>
432+
</customwidget>
428433
</customwidgets>
429434
<tabstops>
430435
<tabstop>txtMapFilePath</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.