2626 * Workaround with google api, dragging the map doesn't work,
2727 * emulating Chrome, fixes this.
2828 */
29- class myWebPage : public QWebPage
29+ class myWebPage : public QWebEnginePage
3030{
3131protected:
3232
@@ -49,8 +49,12 @@ RGGoogleMap::RGGoogleMap(QWidget *parent)
4949 ui.setupUi (this );
5050
5151 QFile file (" google-maps-template.html" );
52- if (!file.open (QIODevice::ReadOnly | QIODevice::Text))
52+ if (!file.open (QIODevice::ReadOnly | QIODevice::Text)){
53+ QFileInfo fileInfo (file.fileName ());
54+ qDebug () << " I can't open google-maps-template.html !!!" ;
55+ qDebug () << " Path:" << fileInfo.absoluteFilePath ();
5356 return ;
57+ }
5458
5559 QTextStream in (&file);
5660 while (!in.atEnd ()) {
@@ -59,26 +63,59 @@ RGGoogleMap::RGGoogleMap(QWidget *parent)
5963
6064 ui.progressBar ->hide ();
6165 ui.progressBar ->setRange (0 , 100 );
62- ui.spinBoxX ->setValue (RGSettings::getGMXResolution ());
63- ui.spinBoxY ->setValue (RGSettings::getGMYResolution ());
66+ ui.spinBoxX ->setValue (RGSettings::getGMXResolution ());
67+ ui.spinBoxY ->setValue (RGSettings::getGMYResolution ());
6468
65- ui.webView ->setPage (new myWebPage ());
69+ // ui.webView->setPage(new myWebPage());
6670
6771 // Init map resolution
6872 on_fixButton_clicked (true );
6973}
70-
74+ RGGoogleMap::~RGGoogleMap ()
75+ {
76+ qDebug () << " ~RGGoogleMap() destroyed" ;
77+ if (ui.webView ->page () != nullptr ){
78+ qDebug () << " RGGoogleMap destorying webview->page" ;
79+ ui.webView ->page ()->~QWebEnginePage ();
80+ }
81+ if (ui.webView != nullptr ){
82+ qDebug () << " RGGoogleMap destorying webview" ;
83+ ui.webView ->close ();
84+ }
85+ }
7186void RGGoogleMap::accept ()
7287{
7388 m_map = QPixmap (ui.webView ->size ());
7489 ui.webView ->render (&m_map);
7590
76- RGSettings::setGMXResolution (ui.spinBoxX ->value ());
77- RGSettings::setGMYResolution (ui.spinBoxY ->value ());
91+ RGSettings::setGMXResolution (ui.spinBoxX ->value ());
92+ RGSettings::setGMYResolution (ui.spinBoxY ->value ());
93+ qDebug () << " Closing dialog by accepted" ;
94+ if (ui.webView ->page () != nullptr ){
95+ qDebug () << " RGGoogleMap destorying webview->page" ;
96+ ui.webView ->page ()->~QWebEnginePage ();
97+ }
98+ if (ui.webView != nullptr ){
99+ qDebug () << " RGGoogleMap destorying webview" ;
100+ ui.webView ->close ();
101+ }
102+
78103
79104 QDialog::accept ();
80105}
81-
106+ void RGGoogleMap::rejected ()
107+ {
108+ qDebug () << " RGGoogleMap::rejected()" ;
109+ if (ui.webView ->page () != nullptr ){
110+ qDebug () << " RGGoogleMap destorying webview->page" ;
111+ ui.webView ->page ()->~QWebEnginePage ();
112+ }
113+ if (ui.webView != nullptr ){
114+ qDebug () << " RGGoogleMap destorying webview" ;
115+ ui.webView ->close ();
116+ }
117+ QDialog::reject ();
118+ }
82119
83120void RGGoogleMap::on_goButton_clicked (bool )
84121{
@@ -88,13 +125,14 @@ void RGGoogleMap::on_goButton_clicked(bool)
88125 // https://www.google.nl/maps/@52.374716,4.898623,12z
89126
90127 QString manUrl = ui.lineEdit ->text ();
91- QUrl url = manUrl;
128+ QUrl url = manUrl;
92129 QString latlon;
93130 QString zoom;
94131 if (url.hasFragment () || url.host ().contains (" google" ))
95132 {
96- latlon = url.queryItemValue (" ll" );
97- zoom = url.queryItemValue (" z" );
133+ QUrlQuery query (url);
134+ latlon = query.queryItemValue (" ll" );
135+ zoom = query.queryItemValue (" z" );
98136 if (latlon.isEmpty () || zoom.isEmpty ())
99137 {
100138 // Now try the new google maps URL format (the construction is not supported by QUrl, so parse the URL manually
@@ -122,7 +160,11 @@ void RGGoogleMap::on_goButton_clicked(bool)
122160 return ;
123161 }
124162
125-
163+ if (ui.webView ->page () != nullptr ){
164+ qDebug () << " RGGoogleMap destorying webview->page" ;
165+ ui.webView ->page ()->~QWebEnginePage ();
166+ ui.webView ->setPage (new myWebPage ());
167+ }
126168 ui.webView ->setHtml (genHtml (latlon, zoom));
127169 ui.webView ->reload ();
128170}
@@ -165,3 +207,4 @@ QString RGGoogleMap::genHtml(const QString &latlon, const QString &zoom) const
165207
166208 return html;
167209}
210+
0 commit comments