Skip to content

Commit

Permalink
Make followup documents use uuid properly
Browse files Browse the repository at this point in the history
  • Loading branch information
dragotin committed Aug 24, 2024
1 parent bddb951 commit b2ed9d5
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/documentman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ DocGuardedPtr DocumentMan::createDocument( const QString& docType, const QString
}
}

doc->setPredecessor(sourceDoc->ident());
doc->setPredecessor(sourceDoc->uuid());

// Take the default pre- and posttext for the new docType, or, if that is empty, the texts of the old doc
QString newText = DefaultProvider::self()->defaultText( docType, KraftDoc::Part::Header );
Expand Down
2 changes: 1 addition & 1 deletion src/documentsaverdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool DocumentSaverDB::loadByIdent( const QString& ident, KraftDoc *doc )
q1.exec();
if( q1.next() ) {
const QString pIdent = q1.value(0).toString();
doc->setPredecessorDbId(pIdent);
doc->setPredecessor(pIdent);
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/kraftdoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,15 @@ void KraftDoc::setTimeOfSupply(QDateTime start, QDateTime end)

QString KraftDoc::docIdentifier() const
{
const QString id = ident();
if( id.isEmpty() ) {
return docType();
}
return i18nc("First argument is the doctype, like Invoice, followed by the ID",
"%1 (Id %2)", docType(), id );
QString re;
if (isDraftState()) {
re = i18nc("First document type, second date", "%1 from %2 (Draft)", docType(), dateStr());
} else {
// both components are already translated.
re = QString("%1 %2").arg(docType()).arg(ident());
// re = i18nc("First argument is the doctype, like Invoice, followed by the ID", "%1 %2", docType(), ident());
}
return re;
}

void KraftDoc::deleteItems()
Expand Down
2 changes: 0 additions & 2 deletions src/kraftdoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ class KraftDoc : public QObject, public KraftObj

QString predecessor() const { return mPredecessor; }
void setPredecessor( const QString& w );
QString predecessorDbId() const { return mPredecessorDbId; }
void setPredecessorDbId( const QString& pId ) { mPredecessorDbId = pId; }

void setTimeOfSupply(QDateTime start, QDateTime end = QDateTime());
QDateTime timeOfSupplyStart() { return _toSStart; }
Expand Down
31 changes: 18 additions & 13 deletions src/kraftview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,16 @@ void KraftView::setupDocHeaderView()
m_headerEdit->m_cbType->insertItems(-1, DocType::allLocalised() );
m_headerEdit->mButtLang->hide();

const QString predecessorDbId = m_doc->predecessorDbId();
const QString predecessorUuid = m_doc->predecessor();
bool predecIsVisible = false;
if( !predecessorDbId.isEmpty() ) {
DocGuardedPtr predecDoc = DocumentMan::self()->openDocumentByIdent(predecessorDbId);
if( !predecessorUuid.isEmpty() ) {
DocGuardedPtr predecDoc = DocumentMan::self()->openDocumentByUuid(predecessorUuid);
if( predecDoc ) {
const QString id = predecDoc->docIdentifier();
const QString link = QString("<a href=\"doc://show?id=%1\">%2</a>").arg(predecessorDbId).arg(id);
m_headerEdit->_labFollowup->setText( i18n("Successor of %1", link));
QString id{predecDoc->docIdentifier()};
const QString link{QString("<a href=\"doc://show?id=%1\">%2</a>").arg(predecessorUuid).arg(id)};
m_headerEdit->_labFollowup->setText(i18nc("this is a document successor for followup documents", "Successor of %1", link));
predecIsVisible = true;
connect( m_headerEdit->_labFollowup, SIGNAL(linkActivated(QString)),
this, SLOT(slotLinkClicked(QString)));
connect( m_headerEdit->_labFollowup, &QLabel::linkActivated, this, &KraftView::slotLinkClicked);
delete predecDoc;
}
}
Expand All @@ -277,11 +276,16 @@ void KraftView::setupDocHeaderView()
void KraftView::slotLinkClicked(const QString& link)
{
QUrl u(link);
if( u.scheme() == "doc" && u.host() == "show" ) {
QUrlQuery uq(link);
const QString ident = uq.queryItemValue("id");
qDebug() << "Link clicked to open document " << ident;
emit openROView( ident );
if( u.scheme() == QStringLiteral("doc") && u.host() == QStringLiteral("show")) {
const QString query = u.query();
QString uuid;
if (query.length() > 0 && query.startsWith("id=")) {
uuid = query.mid(3);
}
qDebug() << "Link clicked to open document " << uuid;
if (!uuid.isEmpty()) {
emit openROView(uuid);
}
}
}

Expand All @@ -303,6 +307,7 @@ void KraftView::redrawDocument( )
KraftDoc *doc = getDocument();
if( !doc ) {
// qDebug () << "ERR: No document available in view, return!";
return;
} else {
// qDebug () << "** Starting redraw of document " << doc;
}
Expand Down
2 changes: 1 addition & 1 deletion src/kraftview.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected slots:
virtual void slotLinkClicked(const QString& link) = 0;
signals:
void viewClosed(bool, DocGuardedPtr, bool);
void openROView(const QString& docId);
void openROView(const QString& uuid);

private:

Expand Down
24 changes: 17 additions & 7 deletions src/newdocassistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,30 +231,40 @@ QString KraftWizard::whiteboard() const

void KraftWizard::setDocToFollow(DocGuardedPtr sourceDoc)
{
if( !sourceDoc ) {
return;
}
DocGuardedPtr dPtr = sourceDoc;
Q_ASSERT(sourceDoc);
DocGuardedPtr dPtr{sourceDoc};

QString sourceId = sourceDoc->ident();
QString uuid = sourceDoc->uuid();

if (sourceId.isEmpty()) {
sourceId = i18n("%1 from %2 (draft)").arg(sourceDoc->docType()).arg(sourceDoc->dateStr());
}

while( ! sourceId.isEmpty() ) {
// store the id of the follower and clear id
const QString idT = dPtr->docIdentifier();
mDetailsPage->mSourceDocIdentsCombo->addItem(idT, sourceId);
mDetailsPage->mSourceDocIdentsCombo->addItem(sourceId, uuid);

// remember the current dptr to be able to delete it soon
DocGuardedPtr oldDptr = dPtr;
dPtr = DocumentMan::self()->openDocumentByIdent( dPtr->predecessor() );
dPtr = DocumentMan::self()->openDocumentByUuid(dPtr->predecessor());
if( dPtr ) {
sourceId = dPtr->ident();
if (sourceId.isEmpty())
sourceId = i18n("%1 from %2 (draft)").arg(sourceDoc->docType()).arg(sourceDoc->dateStr());
uuid = dPtr->uuid();
} else {
sourceId.clear();
uuid.clear();
}
if( oldDptr != sourceDoc ) {
delete oldDptr;
}

delete dPtr;
}

if( mDetailsPage->mSourceDocIdentsCombo->count() > 0 ) {
mDetailsPage->mKeepItemsCB->setVisible(true);
mDetailsPage->mSourceDocIdentsCombo->setVisible(true);
Expand All @@ -274,7 +284,7 @@ QString KraftWizard::copyItemsFromPredecessor()
{
QString re;
if( mDetailsPage->mKeepItemsCB->checkState() == Qt::Checked ) {
re = mDetailsPage->mSourceDocIdentsCombo->currentText(); // use the ident
re = mDetailsPage->mSourceDocIdentsCombo->currentData().toString(); // use the ident
}
return re;
}
Expand Down
10 changes: 4 additions & 6 deletions src/portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,19 +631,17 @@ void Portal::slotFollowUpDocument()
DocPositionList posToCopy;
delete sourceDoc;

QString uuidToCopyFrom;
if ( wiz.exec() ) {
// it is ok to open by ident because the user selects from ident, and there are only
// follow up documents from released docs that have an ident already.
const QString selectedIdent = wiz.copyItemsFromPredecessor();
if(!selectedIdent.isEmpty()) {
DocGuardedPtr copyDoc = DocumentMan::self()->openDocumentByIdent( selectedIdent );
const QString selectedUuid = wiz.copyItemsFromPredecessor();
if(!selectedUuid.isEmpty()) {
DocGuardedPtr copyDoc = DocumentMan::self()->openDocumentByIdent(selectedUuid);
posToCopy = copyDoc->positions();
uuidToCopyFrom = copyDoc->uuid();
delete copyDoc;
}

DocGuardedPtr doc = DocumentMan::self()->createDocument(wiz.docType(), uuidToCopyFrom, posToCopy);
DocGuardedPtr doc = DocumentMan::self()->createDocument(wiz.docType(), selectedUuid, posToCopy);
doc->setDate( wiz.date() );
doc->setWhiteboard( wiz.whiteboard() );
createView( doc );
Expand Down

0 comments on commit b2ed9d5

Please sign in to comment.