@@ -97,21 +97,25 @@ namespace hal
9797 void DotViewer::handleOpenInputFileDialog ()
9898 {
9999 QString filename = QFileDialog::getOpenFileName (this , " Open dot file" , " ." , " Dot files (*.dot);;All files (*)" );
100- if (!filename.isEmpty ()) handleOpenInputFileByName (filename);
100+ if (!filename.isEmpty ()) loadDotFile (filename);
101101 }
102102
103103 void DotViewer::handleOpenInputFileByName (const QString& fileName, const QString &creator)
104+ {
105+ loadDotFile (fileName,creator);
106+ }
107+
108+ bool DotViewer::loadDotFile (const QString& fileName, const QString &creator)
104109 {
105110 if (dynamic_cast <PythonThread*>(QThread::currentThread ()))
106111 {
107112 // call from differnt thread, we cannot create GUI objects directly
108113 DotViewerCallFromTread* dvcft = new DotViewerCallFromTread;
109- dvcft->emitOpenInputFileByName (this , fileName, creator);
114+ bool retval = dvcft->openInputFileByName (this , fileName, creator);
110115 delete dvcft;
111- return ;
116+ return retval ;
112117 }
113118
114- mFilename = fileName;
115119 mCreatorPlugin = creator;
116120
117121 const char * halComment = " \" created by HAL plugin " ;
@@ -121,9 +125,17 @@ namespace hal
121125 mDotGraphicsView ->setScene (mDotScene );
122126 toDispose->deleteLater ();
123127
124- if (fileName.isEmpty ()) return ;
128+ if (fileName.isEmpty ()) {
129+ log_warning (" dot_viewer" , " Cannot load dot file, no file name provided" );
130+ return false ;
131+ }
125132 QFile ff (fileName);
126- if (!ff.open (QIODevice::ReadOnly)) return ;
133+ if (!ff.open (QIODevice::ReadOnly)) {
134+ log_warning (" dot_viewer" , " An error occurred loading dot file '{}'" , fileName.toStdString ());
135+ return false ;
136+ }
137+
138+ mFilename = fileName;
127139 QByteArray dotfileContent = ff.readAll ();
128140
129141 // Determine plugin name to construct correct interaction class
@@ -163,6 +175,7 @@ namespace hal
163175
164176 // interact might be nullptr but that is OK (no interactions in this case)
165177 mDotScene ->loadLayout (dotfileContent, interact);
178+ return true ;
166179 }
167180
168181 void DotViewer::handleColorSelect ()
@@ -195,11 +208,12 @@ namespace hal
195208 }
196209 }
197210
198- void DotViewerCallFromTread::emitOpenInputFileByName (DotViewer* callee, QString filename, QString plugin)
211+ bool DotViewerCallFromTread::openInputFileByName (DotViewer* callee, QString filename, QString plugin)
199212 {
200- if (!callee) return ;
213+ if (!callee) return false ;
201214 connect (this , &DotViewerCallFromTread::callOpenInputFileByName, callee, &DotViewer::handleOpenInputFileByName, Qt::BlockingQueuedConnection);
202215 Q_EMIT callOpenInputFileByName (filename, plugin);
203216 disconnect (this , &DotViewerCallFromTread::callOpenInputFileByName, callee, &DotViewer::handleOpenInputFileByName);
217+ return (callee->filename () == filename); // callee will not store filename upon load error
204218 }
205219} // namespace hal
0 commit comments