Коммит 0d8e58a3 создал по автору OMP Education's avatar OMP Education Зафиксировано автором Alexey Andreyev
Просмотр файлов

[Annotations] Implement the note editing feature

Contributes to:

https://gitlab.com/omprussia/libraries/amberpdf-qml-plugin/-/issues/16
владелец 67d28f22
...@@ -91,6 +91,9 @@ Rectangle { ...@@ -91,6 +91,9 @@ Rectangle {
function removeNote(pageIndex, noteIndex) { function removeNote(pageIndex, noteIndex) {
pdfView.removeNote(pageIndex, noteIndex) pdfView.removeNote(pageIndex, noteIndex)
} }
function editNote(pageIndex, noteIndex, newColor, newContent) {
pdfView.editNote(pageIndex, noteIndex, newContent, newColor)
}
color: "transparent" color: "transparent"
data: [ data: [
......
...@@ -66,12 +66,14 @@ public: ...@@ -66,12 +66,14 @@ public:
virtual void addAnnotation(const QRectF &rect, const QColor &color, virtual void addAnnotation(const QRectF &rect, const QColor &color,
const QString &author, const QString &content) = 0; const QString &author, const QString &content) = 0;
virtual void removeAnnotation(int annotationId) = 0; virtual void removeAnnotation(int annotationId) = 0;
virtual void editNote(int noteId, const QString &newContent, const QColor &newColor) = 0;
signals: signals:
void annotationsLoaded(); void annotationsLoaded();
void originalSizeLoaded(); void originalSizeLoaded();
void annotationAdded(bool); void annotationAdded(bool);
void annotationDelete(int, bool); void annotationDelete(int, bool);
void annotationEdited(int, bool);
}; };
#endif // BASEPAGE_H #endif // BASEPAGE_H
...@@ -219,3 +219,40 @@ void PdfPageItem::removeAnnotation(int annotationId) ...@@ -219,3 +219,40 @@ void PdfPageItem::removeAnnotation(int annotationId)
watcher->setFuture(m_amberPage->removeAnnotation(annotationId)); watcher->setFuture(m_amberPage->removeAnnotation(annotationId));
} }
void PdfPageItem::editNote(int noteId, const QString &newContent, const QColor &newColor)
{
BaseAnnotation *annotationToEdit = nullptr;
for (const auto annotation : m_annotations) {
if (annotation == nullptr)
continue;
if (annotation->annotationId == noteId) {
annotationToEdit = annotation;
break;
}
}
if (annotationToEdit == nullptr)
return;
auto *watcher = new QFutureWatcher<bool>();
connect(watcher, &QFutureWatcher<bool>::finished, this, [this, watcher, noteId]() {
if (watcher == nullptr)
return;
if (watcher->isFinished() && !watcher->isCanceled())
removeAnnotation(noteId);
watcher->deleteLater();
});
auto future = m_amberPage->addAnnotation(annotationToEdit->rect, newColor, annotationToEdit->author, newContent);
watcher->setFuture(future);
connect(this, &PdfPageItem::annotationDelete, this, [this, noteId](int annotationId, bool result) {
if (noteId != annotationId)
return;
emit annotationEdited(noteId, result);
});
}
...@@ -66,6 +66,7 @@ public: ...@@ -66,6 +66,7 @@ public:
void addAnnotation(const QRectF &rect, const QColor &color, void addAnnotation(const QRectF &rect, const QColor &color,
const QString &author, const QString &content) override; const QString &author, const QString &content) override;
void removeAnnotation(int annotationId) override; void removeAnnotation(int annotationId) override;
void editNote(int noteId, const QString &newContent, const QColor &newColor) override;
private: private:
QSharedPointer<PdfPage> m_amberPage; QSharedPointer<PdfPage> m_amberPage;
......
...@@ -173,6 +173,16 @@ void PdfPageContainer::setPageSource(QSharedPointer<BasePage> pageSource) ...@@ -173,6 +173,16 @@ void PdfPageContainer::setPageSource(QSharedPointer<BasePage> pageSource)
emit noteRemoved(noteId, removeResult); emit noteRemoved(noteId, removeResult);
}); });
connect(m_pageSource.data(), &BasePage::annotationEdited, this, [this](int noteId, bool edited) {
Q_UNUSED(noteId)
if (m_pageSource && edited) {
m_pageSource->loadAnnotations();
emit pageChanged();
}
emit noteEdited(noteId, edited);
});
if (m_pageSource->annotations().isEmpty()) if (m_pageSource->annotations().isEmpty())
m_pageSource->loadAnnotations(); m_pageSource->loadAnnotations();
...@@ -263,6 +273,14 @@ void PdfPageContainer::removeNote(int noteId) ...@@ -263,6 +273,14 @@ void PdfPageContainer::removeNote(int noteId)
m_pageSource->removeAnnotation(noteId); m_pageSource->removeAnnotation(noteId);
} }
void PdfPageContainer::editNote(int noteId, const QString &newContent, const QColor &newColor)
{
if (!m_pageSource)
return;
m_pageSource->editNote(noteId, newContent, newColor);
}
void PdfPageContainer::setRequestedSize(QSizeF requestedSize) void PdfPageContainer::setRequestedSize(QSizeF requestedSize)
{ {
if (m_requestedSize == requestedSize) if (m_requestedSize == requestedSize)
......
...@@ -84,6 +84,7 @@ public: ...@@ -84,6 +84,7 @@ public:
void addAnnotation(const QRectF &rect, const QColor &color, void addAnnotation(const QRectF &rect, const QColor &color,
const QString &author, const QString &content); const QString &author, const QString &content);
void removeNote(int noteId); void removeNote(int noteId);
void editNote(int noteId, const QString &newContent, const QColor &newColor);
public slots: public slots:
void setRequestedSize(QSizeF requestedSize); void setRequestedSize(QSizeF requestedSize);
...@@ -104,6 +105,7 @@ signals: ...@@ -104,6 +105,7 @@ signals:
void notesPaintChanged(bool notesPaint); void notesPaintChanged(bool notesPaint);
void noteActivate(QString, QString); void noteActivate(QString, QString);
void noteRemoved(int, bool); void noteRemoved(int, bool);
void noteEdited(int, bool);
private slots: private slots:
void _correctSize(); void _correctSize();
......
...@@ -319,6 +319,15 @@ void PdfView::removeNote(int pageId, int noteId) ...@@ -319,6 +319,15 @@ void PdfView::removeNote(int pageId, int noteId)
page->removeNote(noteId); page->removeNote(noteId);
} }
void PdfView::editNote(int pageId, int noteId, const QString &newContent, const QColor &newColor)
{
if (!m_paintedPages.contains(pageId))
return;
auto page = qobject_cast<PdfPageContainer *>(m_pages.value(pageId));
page->editNote(noteId, newContent, newColor);
}
bool PdfView::documentEdited() const bool PdfView::documentEdited() const
{ {
return m_documentEdited; return m_documentEdited;
...@@ -886,6 +895,9 @@ void PdfView::_preparePages() ...@@ -886,6 +895,9 @@ void PdfView::_preparePages()
connect(page, &PdfPageContainer::noteRemoved, this, [pageIndex, this](int noteId, bool result) { connect(page, &PdfPageContainer::noteRemoved, this, [pageIndex, this](int noteId, bool result) {
emit noteRemoved(pageIndex, noteId, result); emit noteRemoved(pageIndex, noteId, result);
}); });
connect(page, &PdfPageContainer::noteEdited, this, [pageIndex, this](int noteId, bool result) {
emit noteEdited(pageIndex, noteId, result);
});
page->setVisible(false); page->setVisible(false);
page->setPageGeometry(m_mapper->originalPageGeometry(pageIndex)); page->setPageGeometry(m_mapper->originalPageGeometry(pageIndex));
......
...@@ -106,6 +106,7 @@ public: ...@@ -106,6 +106,7 @@ public:
const QString &author, const QString &author,
const QString &content); const QString &content);
Q_INVOKABLE void removeNote(int pageId, int noteId); Q_INVOKABLE void removeNote(int pageId, int noteId);
Q_INVOKABLE void editNote(int pageId, int noteId, const QString &newContent, const QColor &newColor);
PagesWithNotesModel* pagesWithNotesModel() const; PagesWithNotesModel* pagesWithNotesModel() const;
public slots: public slots:
...@@ -149,6 +150,7 @@ signals: ...@@ -149,6 +150,7 @@ signals:
void documentSaved(bool saveStatus); void documentSaved(bool saveStatus);
void documentEditedChanged(bool documentEdited); void documentEditedChanged(bool documentEdited);
void noteRemoved(int pageIndex, int noteId, bool result); void noteRemoved(int pageIndex, int noteId, bool result);
void noteEdited(int pageIndex, int noteId, bool result);
void pagesWithNotesModelChanged(PagesWithNotesModel* pagesWithNotesModel); void pagesWithNotesModelChanged(PagesWithNotesModel* pagesWithNotesModel);
private slots: private slots:
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать