From 849b12c5df97ec268c5efce27ea96daa7676e525 Mon Sep 17 00:00:00 2001 From: Tomi Korpipaa Date: Tue, 16 Jan 2018 13:55:14 +0200 Subject: Fix incorrect renaming when editing sub-presentations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also unify the dialog functionality with data input dialog, so that double-clicking triggers editing of values. Task-number: QT3DS-812 Change-Id: I19548f3daeeb9ad11ef6a1868f7403bf76790362 Reviewed-by: Antti Määttä Reviewed-by: Miikka Heikkinen --- .../Studio/_Win/Application/SubPresentationListDlg.cpp | 18 ++++++++++++++---- .../Studio/_Win/Application/SubPresentationListDlg.h | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Authoring/Studio/_Win/Application/SubPresentationListDlg.cpp b/src/Authoring/Studio/_Win/Application/SubPresentationListDlg.cpp index 2722fe2d..b104cde2 100644 --- a/src/Authoring/Studio/_Win/Application/SubPresentationListDlg.cpp +++ b/src/Authoring/Studio/_Win/Application/SubPresentationListDlg.cpp @@ -101,6 +101,10 @@ void CSubPresentationListDlg::initDialog() // When clicking an item, select the whole row connect(m_ui->tableView, &QTableView::clicked, this, &CSubPresentationListDlg::onSelected); + + // Double-click opens the item in edit mode + connect(m_ui->tableView, &QTableView::doubleClicked, + this, &CSubPresentationListDlg::onEditSubPresentation); } void CSubPresentationListDlg::updateButtons() @@ -191,14 +195,17 @@ void CSubPresentationListDlg::onEditSubPresentation() if (subpresdialog.exec() == QDialog::Accepted) { m_records[m_currentIndex] = subpresdialog.subpresentation(); + // We need to update the table to be able to accurately find out if the id is unique + updateContents(); // Make sure that id is still unique - m_records[m_currentIndex].m_id = getUniqueId(m_records[m_currentIndex].m_id); + m_records[m_currentIndex].m_id = getUniqueId(m_records[m_currentIndex].m_id, true); + // Update again, as the id might have been updated + updateContents(); } m_currentIndex = -1; updateButtons(); - updateContents(); } void CSubPresentationListDlg::onSelected(const QModelIndex &index) @@ -209,11 +216,14 @@ void CSubPresentationListDlg::onSelected(const QModelIndex &index) updateButtons(); } -QString CSubPresentationListDlg::getUniqueId(const QString &id) +QString CSubPresentationListDlg::getUniqueId(const QString &id, bool editing) { QString retval = QStringLiteral("%1").arg(id); int idx = 1; - while (m_tableContents->findItems(retval, Qt::MatchExactly, 0).size() && idx < 1000) { + int limit = (editing == true) ? 1 : 0; + // When editing, ignore our own id (i.e. there is supposed to be one entry already) + while (m_tableContents->findItems(retval, Qt::MatchExactly, 0).size() > limit + && idx < 1000) { retval = QStringLiteral("%1_%2").arg(id).arg(idx, 3, 10, QLatin1Char('0')); ++idx; } diff --git a/src/Authoring/Studio/_Win/Application/SubPresentationListDlg.h b/src/Authoring/Studio/_Win/Application/SubPresentationListDlg.h index d877f625..0cfdd7c0 100644 --- a/src/Authoring/Studio/_Win/Application/SubPresentationListDlg.h +++ b/src/Authoring/Studio/_Win/Application/SubPresentationListDlg.h @@ -59,7 +59,7 @@ protected: void initDialog(); void updateButtons(); void updateContents(); - QString getUniqueId(const QString &id); + QString getUniqueId(const QString &id, bool editing = false); private Q_SLOTS: void on_buttonBox_accepted(); -- cgit v1.2.3