Skip to content

Commit 369915a

Browse files
author
gsherman
committed
Remove need for specifying the web browser. QDesktopServices are used instead.
Drag and drop implementation. git-svn-id: http://svn.osgeo.org/qgis/trunk@8163 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent de8c103 commit 369915a

File tree

5 files changed

+47
-168
lines changed

5 files changed

+47
-168
lines changed

src/app/qgisapp.cpp

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <QClipboard>
3232
#include <QColor>
3333
#include <QCursor>
34+
#include <QDesktopServices>
3435
#include <QDesktopWidget>
3536
#include <QDialog>
3637
#include <QDir>
@@ -401,6 +402,10 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
401402
mSplash->showMessage(tr("QGIS Ready!"), Qt::AlignHCenter | Qt::AlignBottom);
402403

403404
mMapTipsVisible = false;
405+
406+
// setup drag drop
407+
setAcceptDrops(true);
408+
404409
mFullScreenMode = false;
405410
showNormal();
406411
qApp->processEvents();
@@ -439,6 +444,43 @@ QgisApp::~QgisApp()
439444
QgsApplication::exitQgis();
440445
}
441446

447+
void QgisApp::dragEnterEvent(QDragEnterEvent *event)
448+
{
449+
if (event->mimeData()->hasUrls())
450+
{
451+
event->acceptProposedAction();
452+
}
453+
}
454+
455+
void QgisApp::dropEvent(QDropEvent *event)
456+
{
457+
// get the file list
458+
QList<QUrl>::iterator i;
459+
QList<QUrl>urls = event->mimeData()->urls();
460+
for (i = urls.begin(); i != urls.end(); i++)
461+
{
462+
QUrl mUrl = *i;
463+
// seems that some drag and drop operations include an empty url
464+
// so we test for length to make sure we have something
465+
if( mUrl.path().length() > 0)
466+
{
467+
// check to see if we are opening a project file
468+
QFileInfo fi(mUrl.path());
469+
if( fi.completeSuffix() == "qgs" )
470+
{
471+
QgsDebugMsg("Opening project " + mUrl.path());
472+
}
473+
else
474+
{
475+
QgsDebugMsg("Adding " + mUrl.path() + " to the map canvas");
476+
openLayer(mUrl.path());
477+
}
478+
}
479+
}
480+
event->acceptProposedAction();
481+
}
482+
483+
442484
// restore any application settings stored in QSettings
443485
void QgisApp::readSettings()
444486
{
@@ -4259,47 +4301,7 @@ void QgisApp::openURL(QString url, bool useQgisDocDirectory)
42594301
status = 0; //avoid compiler warning
42604302
CFRelease(urlRef);
42614303
#else
4262-
// find a browser
4263-
QSettings settings;
4264-
QString browser = settings.readEntry("/qgis/browser");
4265-
if (browser.length() == 0)
4266-
{
4267-
// ask user for browser and use it
4268-
bool ok;
4269-
QString myHeading = tr("QGIS Browser Selection");
4270-
QString myMessage = tr("Enter the name of a web browser to use (eg. konqueror).\n");
4271-
myMessage += tr("Enter the full path if the browser is not in your PATH.\n");
4272-
myMessage += tr("You can change this option later by selecting Options from the Settings menu (Help Browser tab).");
4273-
QString text = QInputDialog::getText(myHeading,
4274-
myMessage,
4275-
QLineEdit::Normal,
4276-
QString::null, &ok, this);
4277-
if (ok && !text.isEmpty())
4278-
{
4279-
// user entered something and pressed OK
4280-
browser = text;
4281-
// save the setting
4282-
settings.writeEntry("/qgis/browser", browser);
4283-
}
4284-
else
4285-
{
4286-
browser = "";
4287-
}
4288-
4289-
}
4290-
if (browser.length() > 0)
4291-
{
4292-
// find the installed location of the help files
4293-
// open index.html using browser
4294-
//XXX for debug on win32 QMessageBox::information(this,"Help opening...", browser + " - " + url);
4295-
QProcess *helpProcess = new QProcess(this);
4296-
QStringList myArgs;
4297-
myArgs << url;
4298-
helpProcess->start(browser,myArgs);
4299-
}
4300-
/* mHelpViewer = new QgsHelpViewer(this,"helpviewer",false);
4301-
mHelpViewer->showContent(QgsApplication::prefixPath() +"/share/doc","index.html");
4302-
mHelpViewer->show(); */
4304+
QDesktopServices::openUrl(url);
43034305
#endif
43044306
}
43054307

src/app/qgisapp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ class QgisApp : public QMainWindow, public Ui::QgisAppBase
145145
//! Returns a pointer to the internal clipboard
146146
QgsClipboard * clipboard();
147147

148+
void dragEnterEvent(QDragEnterEvent *);
149+
150+
void dropEvent(QDropEvent *);
151+
148152
//private slots:
149153
public slots:
150154
//! About QGis

src/app/qgsoptions.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
5353
qparent = parent;
5454
// read the current browser and set it
5555
QSettings settings;
56-
QString browser = settings.readEntry("/qgis/browser");
57-
cmbBrowser->setCurrentText(browser);
5856
#ifdef QGISDEBUG
5957
std::cout << "Standard Identify radius setting: " << QGis::DEFAULT_IDENTIFY_RADIUS << std::endl;
6058
#endif
@@ -223,7 +221,6 @@ QString QgsOptions::theme()
223221
void QgsOptions::saveOptions()
224222
{
225223
QSettings settings;
226-
settings.writeEntry("/qgis/browser", cmbBrowser->currentText());
227224
settings.writeEntry("/Map/identifyRadius", spinBoxIdentifyValue->value());
228225
settings.writeEntry("/qgis/hideSplash",cbxHideSplash->isChecked());
229226
settings.writeEntry("/qgis/new_layers_visible",chkAddedVisibility->isChecked());
@@ -300,26 +297,6 @@ void QgsOptions::saveOptions()
300297
}
301298

302299

303-
void QgsOptions::on_btnFindBrowser_clicked()
304-
{
305-
QString filter;
306-
#ifdef WIN32
307-
filter = "Applications (*.exe)";
308-
#else
309-
filter = "All Files (*)";
310-
#endif
311-
QString browser = QFileDialog::getOpenFileName(
312-
this,
313-
"Choose a browser",
314-
"./",
315-
filter );
316-
if(browser.length() > 0)
317-
{
318-
cmbBrowser->setCurrentText(browser);
319-
}
320-
}
321-
322-
323300
void QgsOptions::on_pbnSelectProjection_clicked()
324301
{
325302
QSettings settings;

src/app/qgsoptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class QgsOptions :public QDialog, private Ui::QgsOptionsBase
4949
public slots:
5050
//! Slot called when user chooses to change the project wide projection.
5151
void on_pbnSelectProjection_clicked();
52-
void on_btnFindBrowser_clicked();
5352
void on_chkAntiAliasing_stateChanged();
5453
void on_chkUseQPixmap_stateChanged();
5554
void saveOptions();

src/ui/qgsoptionsbase.ui

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,107 +1021,6 @@
10211021
</item>
10221022
</layout>
10231023
</widget>
1024-
<widget class="QWidget" name="tabHelpBrowser" >
1025-
<attribute name="title" >
1026-
<string>Help &amp;Browser</string>
1027-
</attribute>
1028-
<layout class="QGridLayout" >
1029-
<property name="margin" >
1030-
<number>11</number>
1031-
</property>
1032-
<property name="spacing" >
1033-
<number>6</number>
1034-
</property>
1035-
<item row="2" column="0" colspan="2" >
1036-
<spacer>
1037-
<property name="orientation" >
1038-
<enum>Qt::Vertical</enum>
1039-
</property>
1040-
<property name="sizeHint" >
1041-
<size>
1042-
<width>20</width>
1043-
<height>40</height>
1044-
</size>
1045-
</property>
1046-
</spacer>
1047-
</item>
1048-
<item row="1" column="0" colspan="3" >
1049-
<widget class="QLabel" name="textLabel1_2" >
1050-
<property name="text" >
1051-
<string>&lt;b>Note:&lt;/b> The browser must be in your PATH or you can specify the full path above</string>
1052-
</property>
1053-
<property name="wordWrap" >
1054-
<bool>true</bool>
1055-
</property>
1056-
</widget>
1057-
</item>
1058-
<item row="0" column="2" >
1059-
<widget class="QPushButton" name="btnFindBrowser" >
1060-
<property name="maximumSize" >
1061-
<size>
1062-
<width>60</width>
1063-
<height>32767</height>
1064-
</size>
1065-
</property>
1066-
<property name="text" >
1067-
<string>...</string>
1068-
</property>
1069-
</widget>
1070-
</item>
1071-
<item row="0" column="1" >
1072-
<widget class="QComboBox" name="cmbBrowser" >
1073-
<property name="editable" >
1074-
<bool>true</bool>
1075-
</property>
1076-
<item>
1077-
<property name="text" >
1078-
<string>epiphany</string>
1079-
</property>
1080-
</item>
1081-
<item>
1082-
<property name="text" >
1083-
<string>firefox</string>
1084-
</property>
1085-
</item>
1086-
<item>
1087-
<property name="text" >
1088-
<string>mozilla-firefox</string>
1089-
</property>
1090-
</item>
1091-
<item>
1092-
<property name="text" >
1093-
<string>galeon</string>
1094-
</property>
1095-
</item>
1096-
<item>
1097-
<property name="text" >
1098-
<string>konqueror</string>
1099-
</property>
1100-
</item>
1101-
<item>
1102-
<property name="text" >
1103-
<string>mozilla</string>
1104-
</property>
1105-
</item>
1106-
<item>
1107-
<property name="text" >
1108-
<string>opera</string>
1109-
</property>
1110-
</item>
1111-
</widget>
1112-
</item>
1113-
<item row="0" column="0" >
1114-
<widget class="QLabel" name="textLabel1" >
1115-
<property name="text" >
1116-
<string>Open help documents with</string>
1117-
</property>
1118-
<property name="buddy" >
1119-
<cstring>cmbBrowser</cstring>
1120-
</property>
1121-
</widget>
1122-
</item>
1123-
</layout>
1124-
</widget>
11251024
</widget>
11261025
</item>
11271026
</layout>
@@ -1136,7 +1035,6 @@
11361035
</customwidgets>
11371036
<tabstops>
11381037
<tabstop>tabWidget</tabstop>
1139-
<tabstop>btnFindBrowser</tabstop>
11401038
<tabstop>cbxHideSplash</tabstop>
11411039
<tabstop>cmbTheme</tabstop>
11421040
<tabstop>pbnSelectionColour</tabstop>
@@ -1150,7 +1048,6 @@
11501048
<tabstop>radUseGlobalProjection</tabstop>
11511049
<tabstop>txtGlobalWKT</tabstop>
11521050
<tabstop>pbnSelectProjection</tabstop>
1153-
<tabstop>cmbBrowser</tabstop>
11541051
</tabstops>
11551052
<resources/>
11561053
<connections/>

0 commit comments

Comments
 (0)