feat: Dbus接口增加传递Image的名称
Description: 增加Dbus接口,可以传递打开Image的名称 Log: no Change-Id: I964a0f28504f953322fd103ba5075e1ed582a2b0
This commit is contained in:
		| @ -94,6 +94,7 @@ int main(int argc, char *argv[]) | ||||
|         qDebug() << __FUNCTION__ << __LINE__; | ||||
|         pOcr->openFile(QString(argv[1])); | ||||
|         //pOcr->openImage(QImage(QSize(500, 145), QImage::Format_RGB32)); | ||||
|         //pOcr->openImageAndName(QImage(QSize(500, 145), QImage::Format_RGB32),"test"); | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|  | ||||
| @ -273,7 +273,7 @@ void MainWidget::openImage(const QString &path) | ||||
|     } | ||||
| } | ||||
|  | ||||
| void MainWidget::openImage(const QImage &img) | ||||
| void MainWidget::openImage(const QImage &img,const QString & name) | ||||
| { | ||||
|     createLoadingUi(); | ||||
|     if (m_imageview) { | ||||
| @ -281,7 +281,7 @@ void MainWidget::openImage(const QImage &img) | ||||
|         QTimer::singleShot(100, [ = ] { | ||||
|             m_imageview->fitWindow(); | ||||
|         }); | ||||
|         m_imgName = ""; | ||||
|         m_imgName = name; | ||||
|     } | ||||
|     if (m_currentImg) { | ||||
|         delete m_currentImg; | ||||
|  | ||||
| @ -42,7 +42,7 @@ public: | ||||
|  | ||||
|  | ||||
|     void openImage(const QString &path ); | ||||
|     void openImage(const QImage &img); | ||||
|     void openImage(const QImage &img,const QString & name=""); | ||||
|  | ||||
|     void loadHtml(const QString &html); | ||||
|     void loadString(const QString &string); | ||||
|  | ||||
| @ -54,8 +54,8 @@ bool MainWindow::openFile(const QString &filePaths) | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| bool MainWindow::openImage(const QImage &image) | ||||
| bool MainWindow::openImage(const QImage &image, const QString &name) | ||||
| { | ||||
|     m_mainWidget->openImage(image); | ||||
|     m_mainWidget->openImage(image,name); | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| @ -38,7 +38,7 @@ public: | ||||
|  | ||||
|     bool openFile(const QString &filePaths); | ||||
|  | ||||
|     bool openImage(const QImage &image); | ||||
|     bool openImage(const QImage &image,const QString & name=""); | ||||
| private: | ||||
|     MainWidget *m_mainWidget{nullptr}; | ||||
| }; | ||||
|  | ||||
| @ -46,3 +46,13 @@ void OcrApplication::openImage(QImage image) | ||||
|     win->resize(800, 600); | ||||
|     win->show(); | ||||
| } | ||||
|  | ||||
| void OcrApplication::openImageAndName(QImage image, QString imageName) | ||||
| { | ||||
|     qDebug() << __FUNCTION__ << __LINE__ << image.size(); | ||||
|     MainWindow *win = new MainWindow(); | ||||
|     win->openImage(image,imageName); | ||||
|     win->resize(800, 600); | ||||
|     win->show(); | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -37,6 +37,8 @@ public: | ||||
|  | ||||
|     Q_INVOKABLE void openImage(QImage image); | ||||
|  | ||||
|     Q_INVOKABLE void openImageAndName( QImage image, QString imageName); | ||||
|  | ||||
|  | ||||
| signals: | ||||
|  | ||||
|  | ||||
| @ -51,6 +51,17 @@ bool DbusOcrAdaptor::openFile(QString filePath) | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| void DbusOcrAdaptor::openImageAndName(QByteArray images,QString imageName) | ||||
| { | ||||
|     qDebug() << __FUNCTION__ << __LINE__; | ||||
|     QByteArray data = images; | ||||
|     QString tmp_data = QString::fromLatin1(data.data(), data.size()); | ||||
|     QByteArray srcData = QByteArray::fromBase64(tmp_data.toLatin1()); | ||||
|     data = qUncompress(srcData); | ||||
|     QImage image; | ||||
|     image.loadFromData(data); | ||||
|     QMetaObject::invokeMethod(parent(), "openImageAndName", Q_ARG(QImage, image), Q_ARG(QString, imageName)); | ||||
| } | ||||
| void DbusOcrAdaptor::openImage(QByteArray images) | ||||
| { | ||||
|     qDebug() << __FUNCTION__ << __LINE__; | ||||
| @ -62,3 +73,4 @@ void DbusOcrAdaptor::openImage(QByteArray images) | ||||
|     image.loadFromData(data); | ||||
|     QMetaObject::invokeMethod(parent(), "openImage", Q_ARG(QImage, image)); | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -46,6 +46,11 @@ class DbusOcrAdaptor: public QDBusAbstractAdaptor | ||||
|                                        "      <arg direction=\"in\" type=\"ay\" name=\"openImage\"/>\n" | ||||
|                                        "    </method>\n" | ||||
|  | ||||
|                                        "    <method name=\"openImageAndName\">\n" | ||||
|                                        "      <arg direction=\"in\" type=\"ay\" name=\"images\"/>\n" | ||||
|                                        "      <arg direction=\"in\" type=\"s\" name=\"imageName\"/>\n" | ||||
|                                        "    </method>\n" | ||||
|  | ||||
|                                        "    <method name=\"openFile\">\n" | ||||
|                                        "      <arg direction=\"in\" type=\"s\" name=\"openFile\"/>\n" | ||||
|                                        "      <arg direction=\"out\" type=\"b\"/>\n" | ||||
| @ -58,6 +63,7 @@ public: | ||||
|  | ||||
| public Q_SLOTS: // METHODS | ||||
|     void openImage(QByteArray images); | ||||
|     void openImageAndName(QByteArray images,QString imageName); | ||||
|  | ||||
|     bool openFile(QString filePath); | ||||
|  | ||||
|  | ||||
| @ -81,6 +81,25 @@ public Q_SLOTS: // METHODS | ||||
|         return call(QStringLiteral("openImage"), QVariant::fromValue(data)); | ||||
|     } | ||||
|  | ||||
|     /* | ||||
|     * @bref:openImages | ||||
|     * @param: image 图片 | ||||
|     * @param: imageName 图片名称 | ||||
|     * @return: QDBusPendingReply | ||||
|     * @note: | ||||
|     */ | ||||
|     inline QDBusPendingReply<> openImageAndName(const QImage &image,const QString &imageName) | ||||
|     { | ||||
|         qDebug() << __FUNCTION__; | ||||
|         QByteArray data; | ||||
|         QBuffer buf(&data); | ||||
|         if (image.save(&buf, "PNG")) { | ||||
|             data = qCompress(data, 9); | ||||
|             data = data.toBase64(); | ||||
|         } | ||||
|         return call(QStringLiteral("openImage"), QVariant::fromValue(data),imageName); | ||||
|     } | ||||
|  | ||||
| Q_SIGNALS: // SIGNALS | ||||
| }; | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user