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

Eugeniy Meshcheryakov eugen at debian.org
Wed Aug 22 14:33:01 UTC 2007


The branch, master has been updated
       via  2b77d6be23717c0e4b3d559c1fe963eda1e3b5fe (commit)
       via  474080d739bb76fd46afc5ff8bc3c9ff05245a43 (commit)
       via  7827852d6fc6884c53c7846994373b13196251c2 (commit)
      from  e667253ed5deaa2c87975c8a61012e430bad3d45 (commit)


- Log -----------------------------------------------------------------
commit 2b77d6be23717c0e4b3d559c1fe963eda1e3b5fe
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Wed Aug 22 16:32:52 2007 +0200

    check if sourceModel() is not 0

commit 474080d739bb76fd46afc5ff8bc3c9ff05245a43
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Wed Aug 22 16:30:10 2007 +0200

    handle dataChanged() signal from GlyphsModel in UnicodeProxyModel

commit 7827852d6fc6884c53c7846994373b13196251c2
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Wed Aug 22 16:06:46 2007 +0200

    GlyphEditWidget does not crash anymore

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

Summary of changes:
 gui/gui.rules             |    3 ++-
 gui/mainwindow.cxx        |   30 ++++++++++++++++++------------
 gui/mainwindow.h          |    2 ++
 gui/unicodeproxymodel.cxx |   34 ++++++++++++++++++++++++++++++++++
 gui/unicodeproxymodel.h   |    3 +++
 5 files changed, 59 insertions(+), 13 deletions(-)

diff --git a/gui/gui.rules b/gui/gui.rules
index 0a18db3..091e9e5 100644
--- a/gui/gui.rules
+++ b/gui/gui.rules
@@ -29,7 +29,8 @@ nodist_libfonduegui_a_SOURCES =			\
 	gui/unicodevalueeditor.moc.cxx		\
 	gui/ttieditor.moc.cxx			\
 	gui/glyphsmodel.moc.cxx			\
-	gui/glyphsmodeldelegate.moc.cxx
+	gui/glyphsmodeldelegate.moc.cxx		\
+	gui/unicodeproxymodel.moc.cxx
 
 gui/instnames.tbl.cxx: data/instructions.xml
 gui/instnames.tbl.cxx: DATAFILE=$(srcdir)/data/instructions.xml
diff --git a/gui/mainwindow.cxx b/gui/mainwindow.cxx
index 3aacdc3..2185462 100644
--- a/gui/mainwindow.cxx
+++ b/gui/mainwindow.cxx
@@ -33,7 +33,8 @@
 #include <QSettings>
 #include "unicodeproxymodel.h"
 
-MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
+MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
+	model(0), unicodeProxy(0)
 {
 	setAttribute(Qt::WA_DeleteOnClose);
 
@@ -167,11 +168,11 @@ void MainWindow::loadFile(const QString &fileName)
 
 	connect(m_doc, SIGNAL(documentChanged()), this, SLOT(documentChanged()));
 
-	model = new GlyphsModel;
+	model = new GlyphsModel(this);
 	model->setDocument(m_doc);
-	UnicodeProxyModel *proxy = new UnicodeProxyModel(model);
-	proxy->setSourceModel(model);
-	glyphsView->setModel(proxy); // FIXME
+	unicodeProxy = new UnicodeProxyModel(this);
+	unicodeProxy->setSourceModel(model);
+	glyphsView->setModel(unicodeProxy);
 
 	setCurrentFile(fileName);
 	changeDocumentName(m_doc->fontName());
@@ -305,14 +306,19 @@ void MainWindow::about()
 
 void MainWindow::editGlyph(const QModelIndex &index)
 {	
-	GlyphEditWidget *editor = new GlyphEditWidget(this, qobject_cast<GlyphsModel *>(glyphsView->model()), index);
-	if (editor->isValid()) {
-		// Is it realy needed?
-		connect(this, SIGNAL(documentClosed()), editor, SLOT(close()));
-		editor->show();
+	Q_ASSERT(model);
+
+	QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(glyphsView->model());
+	if (proxy) {
+		GlyphEditWidget *editor = new GlyphEditWidget(this, qobject_cast<GlyphsModel *>(proxy->sourceModel()), proxy->mapToSource(index));
+		if (editor->isValid()) {
+			// Is it realy needed?
+			connect(this, SIGNAL(documentClosed()), editor, SLOT(close()));
+			editor->show();
+		}
+		else
+			delete editor;
 	}
-	else
-		delete editor;
 }
 
 void MainWindow::closeEvent(QCloseEvent *event)
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index 3bcf765..ca8f87d 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -26,6 +26,7 @@ class GlyphsGridWidget;
 class GlyphsModel;
 class QModelIndex;
 class QActionGroup;
+class UnicodeProxyModel;
 
 class MainWindow: public QMainWindow {
 	Q_OBJECT
@@ -91,6 +92,7 @@ private:
 
 	GlyphsGridWidget *glyphsView;
 	GlyphsModel *model;
+	UnicodeProxyModel *unicodeProxy;
 };
 
 #endif
diff --git a/gui/unicodeproxymodel.cxx b/gui/unicodeproxymodel.cxx
index 53a8490..077a6f8 100644
--- a/gui/unicodeproxymodel.cxx
+++ b/gui/unicodeproxymodel.cxx
@@ -1,5 +1,6 @@
 #include "unicodeproxymodel.h"
 #include "glyphsmodel.h"
+#include <QDebug>
 
 UnicodeProxyModel::UnicodeProxyModel(QObject *parent) : QAbstractProxyModel(parent),
 	unencodedGlyphs(0)
@@ -18,6 +19,8 @@ QModelIndex UnicodeProxyModel::mapFromSource(const QModelIndex &sourceIndex) con
 
 QModelIndex UnicodeProxyModel::mapToSource(const QModelIndex &proxyIndex) const
 {
+	if (!sourceModel())
+		return QModelIndex();
 	if (proxyIndex.isValid()) {
 		if (toSourceMap.contains(proxyIndex.row())) {
 			return sourceModel()->index(toSourceMap.value(proxyIndex.row()), proxyIndex.column());
@@ -30,12 +33,20 @@ QModelIndex UnicodeProxyModel::mapToSource(const QModelIndex &proxyIndex) const
 
 void UnicodeProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
 {
+	if (this->sourceModel()) {
+		disconnect(this->sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
+				this, SLOT(parentDataChanged(const QModelIndex &, const QModelIndex &)));
+	}
 	QAbstractProxyModel::setSourceModel(sourceModel);
+
 	toSourceMap.clear();
 	fromSourceMap.clear();
 	unencodedGlyphs = 0;
 
+
 	if (sourceModel) {
+		connect(sourceModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
+				this, SLOT(parentDataChanged(const QModelIndex &, const QModelIndex &)));
 		int numGlyphs = sourceModel->rowCount();
 		for (int i = 0; i < numGlyphs; i++) {
 			QModelIndex unicodeIdx = sourceModel->index(i, GlyphsModel::UnicodeColumn);
@@ -67,6 +78,8 @@ int UnicodeProxyModel::rowCount(const QModelIndex &parent) const
 
 int UnicodeProxyModel::columnCount(const QModelIndex &parent) const
 {
+	if (!sourceModel())
+		return 0;
 	if (parent.isValid())
 		return 0;
 	return sourceModel()->columnCount();
@@ -74,6 +87,8 @@ int UnicodeProxyModel::columnCount(const QModelIndex &parent) const
 
 QModelIndex UnicodeProxyModel::index(int row, int column, const QModelIndex &parent) const
 {
+	if (!sourceModel())
+		return QModelIndex();
 	if (parent.isValid())
 		return QModelIndex();
 	if (column < sourceModel()->columnCount() && row < MAX_UNICODE + unencodedGlyphs)
@@ -83,6 +98,8 @@ QModelIndex UnicodeProxyModel::index(int row, int column, const QModelIndex &par
 
 QVariant UnicodeProxyModel::data(const QModelIndex &index, int role) const
 {
+	if (!sourceModel())
+		return QVariant();
 	if (!index.isValid())
 		return QVariant();
 	if (index.column() < sourceModel()->columnCount() && index.row() < MAX_UNICODE + unencodedGlyphs) {
@@ -125,6 +142,8 @@ QVariant UnicodeProxyModel::data(const QModelIndex &index, int role) const
 
 Qt::ItemFlags UnicodeProxyModel::flags(const QModelIndex &index) const
 {
+	if (!sourceModel())
+		return 0;
 	if (!index.isValid())
 		return 0;
 	QModelIndex sourceIndex = mapToSource(index);
@@ -132,3 +151,18 @@ Qt::ItemFlags UnicodeProxyModel::flags(const QModelIndex &index) const
 		return sourceModel()->flags(sourceIndex);
 	return Qt::ItemIsSelectable;
 }
+
+void UnicodeProxyModel::parentDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
+{
+	int left = topLeft.column();
+	int right = bottomRight.column();
+	int top = topLeft.row();
+	int bottom = bottomRight.row();
+
+	for (int i = top; i <= bottom; i++) {
+		if (fromSourceMap.contains(i)) {
+			int proxyRow = fromSourceMap.value(i);
+			emit dataChanged(createIndex(proxyRow, left), createIndex(proxyRow, right));
+		}
+	}
+}
diff --git a/gui/unicodeproxymodel.h b/gui/unicodeproxymodel.h
index 4b9bd8f..e39fb5b 100644
--- a/gui/unicodeproxymodel.h
+++ b/gui/unicodeproxymodel.h
@@ -6,6 +6,7 @@
 // XXX TODO handle model updates
 
 class UnicodeProxyModel : public QAbstractProxyModel {
+	Q_OBJECT
 public:
 	UnicodeProxyModel(QObject *parent = 0);
 	QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
@@ -20,6 +21,8 @@ public:
 
 	QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
 	Qt::ItemFlags flags(const QModelIndex &index) const;
+public slots:
+	void parentDataChanged(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