mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
DocPage Organizer: Insert/replace document in selection
This commit is contained in:
@@ -77,7 +77,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
ui->actionSeparate_to_Multiple_Documents_Grouped->setData(int(Operation::SeparateGrouped));
|
ui->actionSeparate_to_Multiple_Documents_Grouped->setData(int(Operation::SeparateGrouped));
|
||||||
ui->actionInsert_Image->setData(int(Operation::InsertImage));
|
ui->actionInsert_Image->setData(int(Operation::InsertImage));
|
||||||
ui->actionInsert_Empty_Page->setData(int(Operation::InsertEmptyPage));
|
ui->actionInsert_Empty_Page->setData(int(Operation::InsertEmptyPage));
|
||||||
ui->actionInsert_Page_from_PDF->setData(int(Operation::InsertPDF));
|
ui->actionInsert_PDF->setData(int(Operation::InsertPDF));
|
||||||
ui->actionGet_Source->setData(int(Operation::GetSource));
|
ui->actionGet_Source->setData(int(Operation::GetSource));
|
||||||
ui->actionAbout->setData(int(Operation::About));
|
ui->actionAbout->setData(int(Operation::About));
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
mainToolbar->addActions({ ui->actionGroup, ui->actionUngroup });
|
mainToolbar->addActions({ ui->actionGroup, ui->actionUngroup });
|
||||||
QToolBar* insertToolbar = addToolBar(tr("Insert"));
|
QToolBar* insertToolbar = addToolBar(tr("Insert"));
|
||||||
insertToolbar->setObjectName("insert_toolbar");
|
insertToolbar->setObjectName("insert_toolbar");
|
||||||
insertToolbar->addActions({ ui->actionInsert_Page_from_PDF, ui->actionInsert_Image, ui->actionInsert_Empty_Page });
|
insertToolbar->addActions({ ui->actionInsert_PDF, ui->actionInsert_Image, ui->actionInsert_Empty_Page });
|
||||||
QToolBar* selectToolbar = addToolBar(tr("Select"));
|
QToolBar* selectToolbar = addToolBar(tr("Select"));
|
||||||
selectToolbar->setObjectName("select_toolbar");
|
selectToolbar->setObjectName("select_toolbar");
|
||||||
selectToolbar->addActions({ ui->actionSelect_None, ui->actionSelect_All, ui->actionSelect_Even, ui->actionSelect_Odd, ui->actionSelect_Portrait, ui->actionSelect_Landscape });
|
selectToolbar->addActions({ ui->actionSelect_None, ui->actionSelect_All, ui->actionSelect_Even, ui->actionSelect_Odd, ui->actionSelect_Portrait, ui->actionSelect_Landscape });
|
||||||
@@ -160,7 +160,7 @@ void MainWindow::on_actionAddDocument_triggered()
|
|||||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_settings.directory, tr("PDF document (*.pdf)"));
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_settings.directory, tr("PDF document (*.pdf)"));
|
||||||
if (!fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
{
|
{
|
||||||
addDocument(fileName);
|
insertDocument(fileName, QModelIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ void MainWindow::saveSettings()
|
|||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addDocument(const QString& fileName)
|
void MainWindow::insertDocument(const QString& fileName, const QModelIndex& insertIndex)
|
||||||
{
|
{
|
||||||
auto queryPassword = [this](bool* ok)
|
auto queryPassword = [this](bool* ok)
|
||||||
{
|
{
|
||||||
@@ -248,7 +248,7 @@ void MainWindow::addDocument(const QString& fileName)
|
|||||||
if (securityHandler->isAllowed(pdf::PDFSecurityHandler::Permission::Assemble) ||
|
if (securityHandler->isAllowed(pdf::PDFSecurityHandler::Permission::Assemble) ||
|
||||||
securityHandler->isAllowed(pdf::PDFSecurityHandler::Permission::Modify))
|
securityHandler->isAllowed(pdf::PDFSecurityHandler::Permission::Modify))
|
||||||
{
|
{
|
||||||
m_model->addDocument(fileName, qMove(document));
|
m_model->insertDocument(fileName, qMove(document), insertIndex);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -654,9 +654,34 @@ void MainWindow::performOperation(Operation operation)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Operation::InsertPDF:
|
case Operation::InsertPDF:
|
||||||
case Operation::ReplaceSelection:
|
{
|
||||||
Q_ASSERT(false);
|
QModelIndexList indexes = ui->documentItemsView->selectionModel()->selection().indexes();
|
||||||
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_settings.directory, tr("PDF document (*.pdf)"));
|
||||||
|
if (!fileName.isEmpty())
|
||||||
|
{
|
||||||
|
insertDocument(fileName, !indexes.isEmpty() ? indexes.back() : QModelIndex());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Operation::ReplaceSelection:
|
||||||
|
{
|
||||||
|
QModelIndexList indexes = ui->documentItemsView->selectionModel()->selection().indexes();
|
||||||
|
|
||||||
|
if (indexes.isEmpty())
|
||||||
|
{
|
||||||
|
// Jakub Melka: we have nothing to do, selection is empty
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_settings.directory, tr("PDF document (*.pdf)"));
|
||||||
|
if (!fileName.isEmpty())
|
||||||
|
{
|
||||||
|
insertDocument(fileName, indexes.back());
|
||||||
|
m_model->removeSelection(indexes);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
|
@@ -94,7 +94,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
void addDocument(const QString& fileName);
|
void insertDocument(const QString& fileName, const QModelIndex& insertIndex);
|
||||||
|
|
||||||
bool canPerformOperation(Operation operation) const;
|
bool canPerformOperation(Operation operation) const;
|
||||||
void performOperation(Operation operation);
|
void performOperation(Operation operation);
|
||||||
|
@@ -82,7 +82,7 @@
|
|||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Insert</string>
|
<string>Insert</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionInsert_Page_from_PDF"/>
|
<addaction name="actionInsert_PDF"/>
|
||||||
<addaction name="actionInsert_Image"/>
|
<addaction name="actionInsert_Image"/>
|
||||||
<addaction name="actionInsert_Empty_Page"/>
|
<addaction name="actionInsert_Empty_Page"/>
|
||||||
</widget>
|
</widget>
|
||||||
@@ -189,13 +189,16 @@
|
|||||||
<string>Ctrl+Shift+R</string>
|
<string>Ctrl+Shift+R</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionInsert_Page_from_PDF">
|
<action name="actionInsert_PDF">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="resources.qrc">
|
<iconset resource="resources.qrc">
|
||||||
<normaloff>:/pdfdocpage/resources/insert-page-from-pdf.svg</normaloff>:/pdfdocpage/resources/insert-page-from-pdf.svg</iconset>
|
<normaloff>:/pdfdocpage/resources/insert-page-from-pdf.svg</normaloff>:/pdfdocpage/resources/insert-page-from-pdf.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Insert Page from PDF</string>
|
<string>Insert PDF</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Insert PDF</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+I</string>
|
<string>Ctrl+I</string>
|
||||||
|
@@ -95,7 +95,7 @@ QVariant PageItemModel::data(const QModelIndex& index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
int PageItemModel::addDocument(QString fileName, pdf::PDFDocument document)
|
int PageItemModel::insertDocument(QString fileName, pdf::PDFDocument document, const QModelIndex& index)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(m_documents.cbegin(), m_documents.cend(), [&](const auto& item) { return item.second.fileName == fileName; });
|
auto it = std::find_if(m_documents.cbegin(), m_documents.cend(), [&](const auto& item) { return item.second.fileName == fileName; });
|
||||||
if (it != m_documents.cend())
|
if (it != m_documents.cend())
|
||||||
@@ -111,7 +111,7 @@ int PageItemModel::addDocument(QString fileName, pdf::PDFDocument document)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_documents[newIndex] = { qMove(fileName), qMove(document) };
|
m_documents[newIndex] = { qMove(fileName), qMove(document) };
|
||||||
createDocumentGroup(newIndex);
|
createDocumentGroup(newIndex, index);
|
||||||
return newIndex;
|
return newIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,7 +518,7 @@ QItemSelection PageItemModel::getSelectionImpl(std::function<bool (const PageGro
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageItemModel::createDocumentGroup(int index)
|
void PageItemModel::createDocumentGroup(int index, const QModelIndex& insertIndex)
|
||||||
{
|
{
|
||||||
const DocumentItem& item = m_documents.at(index);
|
const DocumentItem& item = m_documents.at(index);
|
||||||
const pdf::PDFInteger pageCount = item.document.getCatalog()->getPageCount();
|
const pdf::PDFInteger pageCount = item.document.getCatalog()->getPageCount();
|
||||||
@@ -544,8 +544,14 @@ void PageItemModel::createDocumentGroup(int index)
|
|||||||
newItem.groups.push_back(qMove(groupItem));
|
newItem.groups.push_back(qMove(groupItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), rowCount(QModelIndex()), rowCount(QModelIndex()));
|
int insertRow = rowCount(QModelIndex());
|
||||||
m_pageGroupItems.push_back(qMove(newItem));
|
if (insertIndex.isValid())
|
||||||
|
{
|
||||||
|
insertRow = insertIndex.row() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
beginInsertRows(QModelIndex(), insertRow, insertRow);
|
||||||
|
m_pageGroupItems.insert(std::next(m_pageGroupItems.begin(), insertRow), qMove(newItem));
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -118,8 +118,9 @@ public:
|
|||||||
/// cannot be added (for example, it already exists), -1 is returned.
|
/// cannot be added (for example, it already exists), -1 is returned.
|
||||||
/// \param fileName File name
|
/// \param fileName File name
|
||||||
/// \param document Document
|
/// \param document Document
|
||||||
|
/// \param index Index, where image is inserted
|
||||||
/// \returns Identifier of the document (internal index)
|
/// \returns Identifier of the document (internal index)
|
||||||
int addDocument(QString fileName, pdf::PDFDocument document);
|
int insertDocument(QString fileName, pdf::PDFDocument document, const QModelIndex& index);
|
||||||
|
|
||||||
/// Adds image to the model, inserts one single page containing
|
/// Adds image to the model, inserts one single page containing
|
||||||
/// the image. Returns index of a newly added image. If image
|
/// the image. Returns index of a newly added image. If image
|
||||||
@@ -167,7 +168,7 @@ public:
|
|||||||
const std::map<int, ImageItem>& getImages() const { return m_images; }
|
const std::map<int, ImageItem>& getImages() const { return m_images; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createDocumentGroup(int index);
|
void createDocumentGroup(int index, const QModelIndex& insertIndex);
|
||||||
QString getGroupNameFromDocument(int index) const;
|
QString getGroupNameFromDocument(int index) const;
|
||||||
void updateItemCaptionAndTags(PageGroupItem& item) const;
|
void updateItemCaptionAndTags(PageGroupItem& item) const;
|
||||||
void insertEmptyPage(const QModelIndex& index);
|
void insertEmptyPage(const QModelIndex& index);
|
||||||
|
Reference in New Issue
Block a user