Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Signals | Public Member Functions | List of all members
LoadImageFromUrl Class Reference

Load QImage from url. This is trivial for a file, but requires an asynchronous download step for http urls. More...

#include <LoadImageFromUrl.h>

Inheritance diagram for LoadImageFromUrl:
Inheritance graph
Collaboration diagram for LoadImageFromUrl:
Collaboration graph

Signals

void signalImportImage (QString, QImage)
 Send the imported image to MainWindow. This completes the asynchronous loading of the image. More...
 

Public Member Functions

 LoadImageFromUrl (MainWindow &mainWindow)
 Single constructor. More...
 
 ~LoadImageFromUrl ()
 
void startLoadImage (const QUrl &url)
 Start the asynchronous loading of an image from the specified url. More...
 

Detailed Description

Load QImage from url. This is trivial for a file, but requires an asynchronous download step for http urls.

Definition at line 22 of file LoadImageFromUrl.h.

Constructor & Destructor Documentation

LoadImageFromUrl::LoadImageFromUrl ( MainWindow mainWindow)

Single constructor.

Definition at line 19 of file LoadImageFromUrl.cpp.

19  :
20  m_mainWindow (mainWindow),
21 #ifdef NETWORKING
22  m_http (this),
23  m_reply (nullptr),
24 #endif
25  m_buffer (nullptr)
26 {
27  connect (this, SIGNAL (signalImportImage (QString, QImage)), &m_mainWindow, SLOT (slotFileImportImage (QString, QImage)));
28 }
void signalImportImage(QString, QImage)
Send the imported image to MainWindow. This completes the asynchronous loading of the image...
LoadImageFromUrl::~LoadImageFromUrl ( )

Definition at line 30 of file LoadImageFromUrl.cpp.

31 {
32  deallocate ();
33 }

Member Function Documentation

void LoadImageFromUrl::signalImportImage ( QString  ,
QImage   
)
signal

Send the imported image to MainWindow. This completes the asynchronous loading of the image.

void LoadImageFromUrl::startLoadImage ( const QUrl &  url)

Start the asynchronous loading of an image from the specified url.

Definition at line 75 of file LoadImageFromUrl.cpp.

76 {
77  LOG4CPP_INFO_S ((*mainCat)) << "LoadImageFromUrl::startLoadImage url=" << url.toString ().toLatin1 ().data ();
78 
79  m_url = url;
80  if (url.isLocalFile ()) {
81 
82  QFileInfo fileInfo (url.toLocalFile ());
83 
84  // Load local file. This is done synchronously
85  QImage image;
86  if (image.load (url.toLocalFile ())) {
87 
88  emit signalImportImage (fileInfo.fileName (),
89  image);
90 
91  } else {
92 
93  // Probably a bad file type
94 
95  QString message;
96  QTextStream str (&message);
97 
98  str << tr ("Unable to load image from") << " " << url.toLocalFile ();
99 
100  QMessageBox::critical (&m_mainWindow,
102  message,
103  QMessageBox::Ok);
104  }
105 
106  } else {
107 
108  // Drop on the floor if networking is not enabled
109 #ifdef NETWORKING
110  // Asynchronous read from url
111  deallocate ();
112  m_buffer = new QByteArray;
113  QNetworkRequest request (url);
114  m_reply = m_http.get (request);
115 
116  connect (m_reply, SIGNAL (readyRead()), this, SLOT (slotReadData()));
117  connect (m_reply, SIGNAL (finished ()), this, SLOT (slotFinished ()));
118 #endif
119  }
120 }
QString engaugeWindowTitle()
Text for title bars of dialogs.
Definition: Version.cpp:14
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
void signalImportImage(QString, QImage)
Send the imported image to MainWindow. This completes the asynchronous loading of the image...
log4cpp::Category * mainCat
Definition: Logger.cpp:14

The documentation for this class was generated from the following files: