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

Eugeniy Meshcheryakov eugen at debian.org
Mon Aug 27 12:32:13 UTC 2007


The branch, master has been updated
       via  f2ffc31e8d7f363cf452dff397771261a7c3de79 (commit)
      from  773c6b376fa8f2b9857af9c49bc3821e3bb0a949 (commit)


- Shortlog ------------------------------------------------------------
f2ffc31 add functions to handle rows removal

Summary of changes:
 gui/unicodeproxymodel.cxx |   86 +++++++++++++++++++++++++++++++++++++++++++++
 gui/unicodeproxymodel.h   |    4 ++
 2 files changed, 90 insertions(+), 0 deletions(-)
-----------------------------------------------------------------------
Details of changes:

commit f2ffc31e8d7f363cf452dff397771261a7c3de79
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Mon Aug 27 14:32:03 2007 +0200

    add functions to handle rows removal

diff --git a/gui/unicodeproxymodel.cxx b/gui/unicodeproxymodel.cxx
index fa758c2..88c56b2 100644
--- a/gui/unicodeproxymodel.cxx
+++ b/gui/unicodeproxymodel.cxx
@@ -40,6 +40,10 @@ void UnicodeProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
 				this, SLOT(sourceLayoutAboutToBeChanged()));
 		disconnect(this->sourceModel(), SIGNAL(layoutChanged()),
 				this, SLOT(sourceLayoutChanged));
+		disconnect(this->sourceModel(), SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
+				this, SLOT(sourceRowsAboutToBeRemoved(QModelIndex, int, int)));
+		disconnect(this->sourceModel(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
+				this, SLOT(sourceRowsRemoved(QModelIndex, int, int)));
 	}
 	QAbstractProxyModel::setSourceModel(sourceModel);
 
@@ -52,6 +56,10 @@ void UnicodeProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
 				this, SLOT(sourceLayoutAboutToBeChanged()));
 		connect(sourceModel, SIGNAL(layoutChanged()),
 				this, SLOT(sourceLayoutChanged()));
+		connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
+				this, SLOT(sourceRowsAboutToBeRemoved(QModelIndex, int, int)));
+		connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex, int, int)),
+				this, SLOT(sourceRowsRemoved(QModelIndex, int, int)));
 	}
 }
 
@@ -244,3 +252,81 @@ void UnicodeProxyModel::sourceLayoutChanged()
 
 	emit layoutChanged();
 }
+
+bool UnicodeProxyModel::removeRows(int row, int count, const QModelIndex &parent)
+{
+	if (!sourceModel())
+		return false;
+	if (parent.isValid())
+		return false;
+
+	QList<int> sourceRows;
+
+	for (int i = 0; i < count; i++)
+		if (toSourceMap.contains(row + i))
+			sourceRows << toSourceMap[row + i];
+	bool ok = true;
+	foreach (int sourceRow, sourceRows) {
+		ok = ok && sourceModel()->removeRow(sourceRow);
+	}
+	return ok; 
+}
+
+void UnicodeProxyModel::sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
+{
+	Q_ASSERT(sourceModel());
+	if (parent.isValid())
+		return;
+
+	for (int i = start; i <= end; i++) {
+		Q_ASSERT(fromSourceMap.contains(i));
+		int proxyRow = fromSourceMap[i];
+		if (proxyRow > MAX_UNICODE) {
+			beginRemoveRows(QModelIndex(), proxyRow, proxyRow);
+			fromSourceMap.remove(i);
+			toSourceMap.remove(proxyRow);
+			QHash<int, int> newToSourceMap;
+			QHashIterator<int, int> elem(toSourceMap);
+			while (elem.hasNext()) {
+				elem.next();
+				if (elem.key() != proxyRow)
+					newToSourceMap[elem.key() > proxyRow ? elem.key() - 1: elem.key()] = elem.value();
+			}
+			toSourceMap = newToSourceMap;
+			unencodedGlyphs--;
+			endRemoveRows();
+		}
+		else {
+			fromSourceMap.remove(i);
+			toSourceMap.remove(proxyRow);
+			emit dataChanged(createIndex(proxyRow, 0), createIndex(proxyRow, GlyphsModel::NColumns));
+		}
+	}
+}
+
+void UnicodeProxyModel::sourceRowsRemoved(const QModelIndex &parent, int start, int end)
+{
+	Q_ASSERT(sourceModel());
+	if (parent.isValid())
+		return;
+
+	int diff = end - start + 1;
+
+	// adjust fromSourceMap
+	QHash<int, int> newFromSourceMap;
+	QHashIterator<int, int> elem(fromSourceMap);
+	while (elem.hasNext()) {
+		elem.next();
+		newFromSourceMap[elem.key() > end ? elem.key() - diff : elem.key()] = elem.value();
+	}
+	fromSourceMap = newFromSourceMap;
+
+	// adjust toSourceMap
+	QHashIterator<int, int> i(toSourceMap);
+	while (i.hasNext()) {
+		i.next();
+		if (i.value() > end) {
+			toSourceMap[i.key()] = i.value() - diff;
+		}
+	}
+}
diff --git a/gui/unicodeproxymodel.h b/gui/unicodeproxymodel.h
index 6e4999b..a0e66e7 100644
--- a/gui/unicodeproxymodel.h
+++ b/gui/unicodeproxymodel.h
@@ -22,10 +22,14 @@ public:
 	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;
+
+	bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
 public slots:
 	void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
 	void sourceLayoutAboutToBeChanged();
 	void sourceLayoutChanged();
+	void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
+	void sourceRowsRemoved(const QModelIndex &parent, int start, int end);
 private:
 	QHash<int, int> toSourceMap;
 	QHash<int, int> fromSourceMap;

-- 
Fondue Font Editor



More information about the fondue-commits mailing list