[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. 8d2fbec30263ec381373ef78d38b0fb8a9a85449
Eugeniy Meshcheryakov
eugen at debian.org
Mon Aug 27 09:43:18 UTC 2007
The branch, master has been updated
via 8d2fbec30263ec381373ef78d38b0fb8a9a85449 (commit)
via f51ea9d310ad23af6aa8be8fcb77335c971ed139 (commit)
via fcd6803f53dc9f0d2fe119b45da9ad3a012dc219 (commit)
from b1caf07308702e22ef91a8a2a35791cb17878b87 (commit)
- Shortlog ------------------------------------------------------------
8d2fbec simplify sourceDataChanged()
f51ea9d split source <-> proxy mapping function
fcd6803 s/parentDataChanged/sourceDataChanged
Summary of changes:
gui/unicodeproxymodel.cxx | 110 ++++++++++++---------------------------------
gui/unicodeproxymodel.h | 5 +-
2 files changed, 31 insertions(+), 84 deletions(-)
-----------------------------------------------------------------------
Details of changes:
commit 8d2fbec30263ec381373ef78d38b0fb8a9a85449
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Mon Aug 27 11:43:00 2007 +0200
simplify sourceDataChanged()
Strange thing is that it became faster...
diff --git a/gui/unicodeproxymodel.cxx b/gui/unicodeproxymodel.cxx
index 7ea00ff..44b1738 100644
--- a/gui/unicodeproxymodel.cxx
+++ b/gui/unicodeproxymodel.cxx
@@ -174,46 +174,20 @@ void UnicodeProxyModel::sourceDataChanged(const QModelIndex &topLeft, const QMod
if (fromSourceMap.contains(i)) {
int proxyRow = fromSourceMap.value(i);
emit dataChanged(createIndex(proxyRow, left), createIndex(proxyRow, right));
- if (reorder) {
- // we've got a problem, some reordering may be needed
- int newUnicode = data(createIndex(proxyRow, GlyphsModel::UnicodeColumn)).toInt();
- if (proxyRow <= MAX_UNICODE) {
- if (newUnicode != -1) {
- if (newUnicode != proxyRow) {
- // glyph encoding changed
- Q_ASSERT(!toSourceMap.contains(newUnicode));
- emit layoutAboutToBeChanged();
- moveRow(i, proxyRow, newUnicode);
- emit layoutChanged();
- }
- }
- else {
- // encoded glyph became unencoded
- // move glyph to the end of the list
- beginInsertRows(QModelIndex(), MAX_UNICODE + unencodedGlyphs + 1,
- MAX_UNICODE + unencodedGlyphs + 1);
- unencodedGlyphs++;
- endInsertRows();
- emit layoutAboutToBeChanged();
- moveRow(i, proxyRow, MAX_UNICODE + unencodedGlyphs);
- emit layoutChanged();
- }
- }
- else {
- // unencoded glyph...
- if (newUnicode != -1) {
- // ...became encoded
- emit layoutAboutToBeChanged();
- moveRow(i, proxyRow, newUnicode);
- emit layoutChanged();
- shrink(proxyRow);
- beginRemoveRows(QModelIndex(), MAX_UNICODE + unencodedGlyphs,
- MAX_UNICODE + unencodedGlyphs);
- unencodedGlyphs--;
- endRemoveRows();
- }
- }
- }
+ }
+ }
+
+ if (reorder) {
+ QModelIndexList oldIndices = persistentIndexList();
+ if (!oldIndices.isEmpty()) {
+ QModelIndexList sourceIndices;
+ foreach (const QModelIndex &idx, oldIndices)
+ sourceIndices << mapToSource(idx);
+ createMapping();
+ QModelIndexList newIndices;
+ foreach (const QModelIndex &idx, sourceIndices)
+ newIndices << mapFromSource(idx);
+ changePersistentIndexList(oldIndices, newIndices);
}
}
}
@@ -229,36 +203,3 @@ bool UnicodeProxyModel::setData(const QModelIndex &index, const QVariant &value,
return sourceModel()->setData(sourceIndex, value, role);
return false;
}
-
-void UnicodeProxyModel::moveRow(int sourceRow, int from, int to)
-{
- QModelIndexList oldIndices, newIndices;
- for (int col = 0; col < GlyphsModel::NColumns; col++) {
- oldIndices << createIndex(from, col);
- newIndices << createIndex(to, col);
- }
- changePersistentIndexList(oldIndices, newIndices);
- toSourceMap.remove(from);
- toSourceMap[to] = sourceRow;
- fromSourceMap[sourceRow] = to;
-}
-
-void UnicodeProxyModel::shrink(int start)
-{
- Q_ASSERT(start > MAX_UNICODE);
- QModelIndexList oldIndices, newIndices;
- int row;
- for (row = start + 1; row < rowCount(); row++) {
- for (int col = 0; col < GlyphsModel::NColumns; col++) {
- oldIndices << createIndex(row, col);
- newIndices << createIndex(row - 1, col);
- }
- }
- changePersistentIndexList(oldIndices, newIndices);
- for (int row = start + 1; row < rowCount(); row++) {
- int sourceRow = toSourceMap[row];
- toSourceMap.remove(row);
- toSourceMap[row - 1] = sourceRow;
- fromSourceMap[sourceRow] = row - 1;
- }
-}
diff --git a/gui/unicodeproxymodel.h b/gui/unicodeproxymodel.h
index 41850fa..bcec115 100644
--- a/gui/unicodeproxymodel.h
+++ b/gui/unicodeproxymodel.h
@@ -29,9 +29,6 @@ private:
QHash<int, int> fromSourceMap;
int unencodedGlyphs;
- void moveRow(int sourceRow, int from, int to);
- void shrink(int start);
-
void createMapping();
};
commit f51ea9d310ad23af6aa8be8fcb77335c971ed139
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Mon Aug 27 11:30:59 2007 +0200
split source <-> proxy mapping function
diff --git a/gui/unicodeproxymodel.cxx b/gui/unicodeproxymodel.cxx
index 6f4ab63..7ea00ff 100644
--- a/gui/unicodeproxymodel.cxx
+++ b/gui/unicodeproxymodel.cxx
@@ -39,17 +39,24 @@ void UnicodeProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
}
QAbstractProxyModel::setSourceModel(sourceModel);
- toSourceMap.clear();
- fromSourceMap.clear();
- unencodedGlyphs = 0;
-
+ createMapping();
if (sourceModel) {
connect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &)));
- int numGlyphs = sourceModel->rowCount();
+ }
+}
+
+void UnicodeProxyModel::createMapping()
+{
+ toSourceMap.clear();
+ fromSourceMap.clear();
+ unencodedGlyphs = 0;
+
+ if (sourceModel()) {
+ int numGlyphs = sourceModel()->rowCount();
for (int i = 0; i < numGlyphs; i++) {
- QModelIndex unicodeIdx = sourceModel->index(i, GlyphsModel::UnicodeColumn);
+ QModelIndex unicodeIdx = sourceModel()->index(i, GlyphsModel::UnicodeColumn);
Q_ASSERT(unicodeIdx.isValid());
int unicode = unicodeIdx.data().toInt();
if (unicode < 0) {
diff --git a/gui/unicodeproxymodel.h b/gui/unicodeproxymodel.h
index cbdbf84..41850fa 100644
--- a/gui/unicodeproxymodel.h
+++ b/gui/unicodeproxymodel.h
@@ -31,6 +31,8 @@ private:
void moveRow(int sourceRow, int from, int to);
void shrink(int start);
+
+ void createMapping();
};
#endif
commit fcd6803f53dc9f0d2fe119b45da9ad3a012dc219
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date: Mon Aug 27 10:52:50 2007 +0200
s/parentDataChanged/sourceDataChanged
diff --git a/gui/unicodeproxymodel.cxx b/gui/unicodeproxymodel.cxx
index 44127bd..6f4ab63 100644
--- a/gui/unicodeproxymodel.cxx
+++ b/gui/unicodeproxymodel.cxx
@@ -35,7 +35,7 @@ void UnicodeProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
{
if (this->sourceModel()) {
disconnect(this->sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
- this, SLOT(parentDataChanged(const QModelIndex &, const QModelIndex &)));
+ this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &)));
}
QAbstractProxyModel::setSourceModel(sourceModel);
@@ -46,7 +46,7 @@ void UnicodeProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
if (sourceModel) {
connect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
- this, SLOT(parentDataChanged(const QModelIndex &, const QModelIndex &)));
+ this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &)));
int numGlyphs = sourceModel->rowCount();
for (int i = 0; i < numGlyphs; i++) {
QModelIndex unicodeIdx = sourceModel->index(i, GlyphsModel::UnicodeColumn);
@@ -152,7 +152,7 @@ Qt::ItemFlags UnicodeProxyModel::flags(const QModelIndex &index) const
return Qt::ItemIsSelectable;
}
-void UnicodeProxyModel::parentDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
+void UnicodeProxyModel::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
int left = topLeft.column();
int right = bottomRight.column();
diff --git a/gui/unicodeproxymodel.h b/gui/unicodeproxymodel.h
index b1abb55..cbdbf84 100644
--- a/gui/unicodeproxymodel.h
+++ b/gui/unicodeproxymodel.h
@@ -23,7 +23,7 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
Qt::ItemFlags flags(const QModelIndex &index) const;
public slots:
- void parentDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
+ void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
private:
QHash<int, int> toSourceMap;
QHash<int, int> fromSourceMap;
--
Fondue Font Editor
More information about the fondue-commits
mailing list