From 42b7107e179b4fb20401da84aae15bb5a2285b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com> Date: Thu, 29 Jan 2009 10:14:56 +0100 Subject: [PATCH] Fixed undo/redo and tooltip in the resource editor The undo/redo was broken due to connections between can{Undo,Redo}Changed() and updateCurrent(). This also caused the weird cursor behaviour. The resource tooltip had the string "Qt::ToolTipRole" prepended to it due to a leftover debug line. --- src/shared/qrceditor/qrceditor.cpp | 9 --------- src/shared/qrceditor/resourcefile.cpp | 23 +++++++++++------------ src/shared/qrceditor/resourcefile_p.h | 4 ++-- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/shared/qrceditor/qrceditor.cpp b/src/shared/qrceditor/qrceditor.cpp index bd25a42d742..a25a4ecce7c 100644 --- a/src/shared/qrceditor/qrceditor.cpp +++ b/src/shared/qrceditor/qrceditor.cpp @@ -96,8 +96,6 @@ QrcEditor::QrcEditor(QWidget *parent) connect(&m_history, SIGNAL(canRedoChanged(bool)), this, SLOT(updateHistoryControls())); connect(&m_history, SIGNAL(canUndoChanged(bool)), this, SLOT(updateHistoryControls())); - connect(&m_history, SIGNAL(canRedoChanged(bool)), this, SLOT(updateCurrent())); - connect(&m_history, SIGNAL(canUndoChanged(bool)), this, SLOT(updateCurrent())); updateHistoryControls(); updateCurrent(); } @@ -151,28 +149,21 @@ void QrcEditor::updateCurrent() const bool isValid = m_treeview->currentIndex().isValid(); const bool isPrefix = m_treeview->isPrefix(m_treeview->currentIndex()) && isValid; const bool isFile = !isPrefix && isValid; - int cursorPosition; m_ui.aliasLabel->setEnabled(isFile); m_ui.aliasText->setEnabled(isFile); m_currentAlias = m_treeview->currentAlias(); - cursorPosition = m_ui.aliasText->cursorPosition(); m_ui.aliasText->setText(m_currentAlias); - m_ui.aliasText->setCursorPosition(cursorPosition); m_ui.prefixLabel->setEnabled(isPrefix); m_ui.prefixText->setEnabled(isPrefix); m_currentPrefix = m_treeview->currentPrefix(); - cursorPosition = m_ui.prefixText->cursorPosition(); m_ui.prefixText->setText(m_currentPrefix); - m_ui.prefixText->setCursorPosition(cursorPosition); m_ui.languageLabel->setEnabled(isPrefix); m_ui.languageText->setEnabled(isPrefix); m_currentLanguage = m_treeview->currentLanguage(); - cursorPosition = m_ui.languageText->cursorPosition(); m_ui.languageText->setText(m_currentLanguage); - m_ui.languageText->setCursorPosition(cursorPosition); m_ui.addButton->setEnabled(true); m_addFileAction->setEnabled(isValid); diff --git a/src/shared/qrceditor/resourcefile.cpp b/src/shared/qrceditor/resourcefile.cpp index 19a5f25e991..55141ba0364 100644 --- a/src/shared/qrceditor/resourcefile.cpp +++ b/src/shared/qrceditor/resourcefile.cpp @@ -61,7 +61,7 @@ namespace qdesigner_internal { bool FileList::containsFile(File *file) { - foreach(File *tmpFile, *this) + foreach (const File *tmpFile, *this) if (tmpFile->name == file->name && tmpFile->prefix() == file->prefix()) return true; return false; @@ -168,7 +168,7 @@ bool ResourceFile::save() foreach (const QString &name, name_list) { FileList file_list; QString lang; - foreach (Prefix *pref, m_prefix_list) { + foreach (const Prefix *pref, m_prefix_list) { if (pref->name == name){ file_list += pref->file_list; lang = pref->lang; @@ -599,7 +599,7 @@ bool ResourceModel::iconFileExtension(const QString &path) } } - foreach (QString ext, ext_list) { + foreach (const QString &ext, ext_list) { if (path.endsWith(ext, Qt::CaseInsensitive)) return true; } @@ -669,10 +669,9 @@ QVariant ResourceModel::data(const QModelIndex &index, int role) const QString stringRes = conv_file.replace(QDir::separator(), QLatin1Char('/')); const QString &alias_file = file->alias; if (!alias_file.isEmpty()) - appendParenthesized(alias_file, stringRes); + appendParenthesized(alias_file, stringRes); result = stringRes; - result = "Qt::ToolTipRole " + stringRes; } break; @@ -690,14 +689,14 @@ void ResourceModel::getItem(const QModelIndex &index, QString &prefix, QString & if (!index.isValid()) return; - void * const internalPointer = index.internalPointer(); - Node * const node = reinterpret_cast<Node *>(internalPointer); - Prefix * const p = node->prefix(); + const void *internalPointer = index.internalPointer(); + const Node *node = reinterpret_cast<const Node *>(internalPointer); + const Prefix *p = node->prefix(); Q_ASSERT(p); - bool const isFileNode = (p != node); + const bool isFileNode = (p != node); if (isFileNode) { - File *const f = node->file(); + const File *f = node->file(); Q_ASSERT(f); if (!f->alias.isEmpty()) file = f->alias; @@ -810,7 +809,7 @@ void ResourceModel::addFiles(int prefixIndex, const QStringList &fileNames, int const int prefix_idx = prefixIndex; QStringList unique_list; - foreach (QString file, file_list) { + foreach (const QString &file, file_list) { if (!m_resource_file.contains(prefix_idx, file) && !unique_list.contains(file)) unique_list.append(file); } @@ -821,7 +820,7 @@ void ResourceModel::addFiles(int prefixIndex, const QStringList &fileNames, int const int cnt = m_resource_file.fileCount(prefix_idx); beginInsertRows(prefix_model_idx, cnt, cnt + unique_list.count() - 1); // ### FIXME - foreach (QString file, unique_list) + foreach (const QString &file, unique_list) m_resource_file.addFile(prefix_idx, file); const QFileInfo fi(file_list.last()); diff --git a/src/shared/qrceditor/resourcefile_p.h b/src/shared/qrceditor/resourcefile_p.h index 3ee346cb0e6..00d999c90c6 100644 --- a/src/shared/qrceditor/resourcefile_p.h +++ b/src/shared/qrceditor/resourcefile_p.h @@ -69,8 +69,8 @@ protected: Q_ASSERT(m_prefix); } public: - File *file() { return m_file; } - Prefix *prefix() { return m_prefix; } + File *file() const { return m_file; } + Prefix *prefix() const { return m_prefix; } private: File *m_file; Prefix *m_prefix; -- GitLab