[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. ddf8a6d4a949a795d7e4188d82e3d7823f503284

Eugeniy Meshcheryakov eugen at debian.org
Wed Aug 22 19:49:58 UTC 2007


The branch, master has been updated
       via  ddf8a6d4a949a795d7e4188d82e3d7823f503284 (commit)
       via  c40007f7f2988fe46f33fa000a0e6f289427fa89 (commit)
       via  40500d4c0df201403a31d9aa1d8fd81b114a6561 (commit)
       via  d9bf0e63a7ace948349477a036dfa571d485e079 (commit)
       via  547d476a45142010e3099f4596ccd25484c49d14 (commit)
      from  2b77d6be23717c0e4b3d559c1fe963eda1e3b5fe (commit)


- Log -----------------------------------------------------------------
commit ddf8a6d4a949a795d7e4188d82e3d7823f503284
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Wed Aug 22 21:49:46 2007 +0200

    add support for changing glyph encoding (veryyyy slow)

commit c40007f7f2988fe46f33fa000a0e6f289427fa89
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Wed Aug 22 21:19:03 2007 +0200

    do not add unicode value -1 to unicodeHash

commit 40500d4c0df201403a31d9aa1d8fd81b114a6561
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Wed Aug 22 20:25:08 2007 +0200

    add setData() to UnicodeProxyModel

commit d9bf0e63a7ace948349477a036dfa571d485e079
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Wed Aug 22 18:01:37 2007 +0200

    use QString::sprintf() to generate names for missing glyphs.

commit 547d476a45142010e3099f4596ccd25484c49d14
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Wed Aug 22 17:16:28 2007 +0200

    set parrent of UnicodeProxyModel to GlyphsModel

-----------------------------------------------------------------------

Summary of changes:
 gui/mainwindow.cxx        |    2 +-
 gui/unicodeproxymodel.cxx |  103 +++++++++++++++++++++++++++++++++++++++++---
 gui/unicodeproxymodel.h   |    4 ++
 nongui/fontdocument.cxx   |    6 ++-
 4 files changed, 105 insertions(+), 10 deletions(-)

diff --git a/gui/mainwindow.cxx b/gui/mainwindow.cxx
index 2185462..036fbfe 100644
--- a/gui/mainwindow.cxx
+++ b/gui/mainwindow.cxx
@@ -170,7 +170,7 @@ void MainWindow::loadFile(const QString &fileName)
 
 	model = new GlyphsModel(this);
 	model->setDocument(m_doc);
-	unicodeProxy = new UnicodeProxyModel(this);
+	unicodeProxy = new UnicodeProxyModel(model);
 	unicodeProxy->setSourceModel(model);
 	glyphsView->setModel(unicodeProxy);
 
diff --git a/gui/unicodeproxymodel.cxx b/gui/unicodeproxymodel.cxx
index 077a6f8..609e924 100644
--- a/gui/unicodeproxymodel.cxx
+++ b/gui/unicodeproxymodel.cxx
@@ -73,7 +73,7 @@ int UnicodeProxyModel::rowCount(const QModelIndex &parent) const
 {
 	if (parent.isValid())
 		return 0;
-	return MAX_UNICODE + unencodedGlyphs;
+	return MAX_UNICODE + unencodedGlyphs + 1;
 }
 
 int UnicodeProxyModel::columnCount(const QModelIndex &parent) const
@@ -91,7 +91,7 @@ QModelIndex UnicodeProxyModel::index(int row, int column, const QModelIndex &par
 		return QModelIndex();
 	if (parent.isValid())
 		return QModelIndex();
-	if (column < sourceModel()->columnCount() && row < MAX_UNICODE + unencodedGlyphs)
+	if (column < sourceModel()->columnCount() && row < rowCount())
 		return createIndex(row, column);
 	return QModelIndex();
 }
@@ -102,7 +102,7 @@ QVariant UnicodeProxyModel::data(const QModelIndex &index, int role) const
 		return QVariant();
 	if (!index.isValid())
 		return QVariant();
-	if (index.column() < sourceModel()->columnCount() && index.row() < MAX_UNICODE + unencodedGlyphs) {
+	if (index.column() < sourceModel()->columnCount() && index.row() < rowCount()) {
 		QModelIndex sourceIndex = mapToSource(index);
 		if (sourceIndex.isValid())
 			return sourceModel()->data(sourceIndex, role);
@@ -113,9 +113,9 @@ QVariant UnicodeProxyModel::data(const QModelIndex &index, int role) const
 			if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
 				QString name;
 				if (index.row() < 0x10000)
-					name = QString("uni%1").arg(index.row(), 4, 16, QLatin1Char('0'));
+					name.sprintf("uni%04X", index.row());
 				else
-					name = QString("u%1").arg(index.row(), 0, 16);
+					name.sprintf("u%X", index.row());
 				return name;
 			}
 			break;
@@ -123,9 +123,9 @@ QVariant UnicodeProxyModel::data(const QModelIndex &index, int role) const
 			if (role == Qt::DisplayRole || role == Qt::EditRole) {
 				QString name;
 				if (index.row() < 0x10000)
-					name = QString("uni%1").arg(index.row(), 4, 16, QLatin1Char('0'));
+					name.sprintf("uni%04X", index.row());
 				else
-					name = QString("u%1").arg(index.row(), 0, 16);
+					name.sprintf("u%X", index.row());
 				return name;
 			}
 			break;
@@ -159,10 +159,99 @@ void UnicodeProxyModel::parentDataChanged(const QModelIndex &topLeft, const QMod
 	int top = topLeft.row();
 	int bottom = bottomRight.row();
 
+	Q_ASSERT(left <= right && top <= bottom);
+
+	bool reorder = left <= GlyphsModel::UnicodeColumn && right >= GlyphsModel::UnicodeColumn;
+
 	for (int i = top; i <= bottom; i++) {
 		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
+						emit beginInsertRows(QModelIndex(), MAX_UNICODE + unencodedGlyphs + 1,
+								MAX_UNICODE + unencodedGlyphs + 1);
+						unencodedGlyphs++;
+						emit 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);
+						emit beginRemoveRows(QModelIndex(), MAX_UNICODE + unencodedGlyphs,
+								MAX_UNICODE + unencodedGlyphs);
+						unencodedGlyphs--;
+						emit endRemoveRows();
+					}
+				}
+			}		
 		}
 	}
 }
+
+bool UnicodeProxyModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+	if (!sourceModel())
+		return false;
+	if (!index.isValid())
+		return false;
+	QModelIndex sourceIndex = mapToSource(index);
+	if (sourceIndex.isValid())
+		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 e39fb5b..b1abb55 100644
--- a/gui/unicodeproxymodel.h
+++ b/gui/unicodeproxymodel.h
@@ -20,6 +20,7 @@ public:
 	QModelIndex parent(const QModelIndex &index) const {Q_UNUSED(index); return QModelIndex();}
 
 	QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+	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);
@@ -27,6 +28,9 @@ private:
 	QHash<int, int> toSourceMap;
 	QHash<int, int> fromSourceMap;
 	int unencodedGlyphs;
+
+	void moveRow(int sourceRow, int from, int to);
+	void shrink(int start);
 };
 
 #endif
diff --git a/nongui/fontdocument.cxx b/nongui/fontdocument.cxx
index d7d6a18..54c2178 100644
--- a/nongui/fontdocument.cxx
+++ b/nongui/fontdocument.cxx
@@ -84,9 +84,11 @@ bool FontDocument::changeUnicodeValue(Glyph *glyph, int unicode)
 		return true;
 	if (hasUnicodeGlyph(unicode))
 		return false;
-	unicodeHash.remove(oldValue);
+	if (oldValue != -1)
+		unicodeHash.remove(oldValue);
 	glyph->setUnicode(unicode);
-	unicodeHash[unicode] = glyph;
+	if (unicode != -1)
+		unicodeHash[unicode] = glyph;
 	setChanged();
 	return true;
 }

-- 
Fondue Font Editor



More information about the fondue-commits mailing list