From 4493da391860b0269bc9e967ec2eae3c542913d7 Mon Sep 17 00:00:00 2001 From: Nick Vrvilo Date: Fri, 7 Aug 2009 22:19:13 +0000 Subject: [PATCH] Moved Hanyu pinyin appending functions from GUI code (MainWindow) to a separate class (GPinyinAppender) Changed GDateEstimator to only insert PLACE nodes if the defaultPlace value is non-null and non-empty Updated to version 1.6.0 *** Major bug fixes *** Fixed GIndiEntry and GFamily so that new PLACE nodes are properly appended to the GNode tree (now PACE data will be saved) Fixed GIndiEntry::parseDeath() to parse PLACE nodes git-svn-id: http://svn.phoenixteam.org/repos/GedTools@46 9dab71d7-c464-4d9a-89bf-b85db2a2fdf8 --- Changes.txt | 9 ++++- GedTools.pro | 2 ++ Readme.txt | 4 +-- inc/GPinyinAppender.h | 45 ++++++++++++++++++++++++ installer/GedTools.nsi | 2 +- src/GFamily.cpp | 3 ++ src/GIndiEntry.cpp | 18 ++++++++-- src/GPinyinAppender.cpp | 78 +++++++++++++++++++++++++++++++++++++++++ src/MainWindow.cpp | 71 ++++++------------------------------- 9 files changed, 165 insertions(+), 67 deletions(-) create mode 100644 inc/GPinyinAppender.h create mode 100644 src/GPinyinAppender.cpp diff --git a/Changes.txt b/Changes.txt index cfeef8d..74fa0bc 100644 --- a/Changes.txt +++ b/Changes.txt @@ -1,5 +1,12 @@ GedTools - Version History +1.6.0 - 7 August 2009 +* Changed GDateEstimator to only insert PLACE nodes if the + defaultPlace value is non-null and non-empty +* Fixed GIndiEntry and GFamily so that new PLACE nodes are properly + appended to the GNode tree (now PACE data will be saved) +* Fixed GIndiEntry::parseDeath() to parse PLACE nodes + 1.5.1 - 3 August 2009 * Added a separate sorting algorithm for the number-type columns (e.g. ID, Birth Year and Death Year) @@ -37,4 +44,4 @@ GedTools - Version History * Interface added to view individuals in a tree format 1.0.0 - 23 March 2009 -* Support for appending Hanyu Pinyin data to the ROMN field \ No newline at end of file +* Support for appending Hanyu Pinyin data to the ROMN field diff --git a/GedTools.pro b/GedTools.pro index 4396f60..4dafaa3 100644 --- a/GedTools.pro +++ b/GedTools.pro @@ -24,6 +24,7 @@ HEADERS = inc/GFile.h \ inc/GFamilyTreeModel.h\ inc/GNode.h \ inc/GDateEstimator.h \ + inc/GPinyinAppender.h \ inc/PinyinMap.h \ inc/MainWindow.h \ inc/MainMenuBar.h \ @@ -39,6 +40,7 @@ SOURCES = src/GFile.cpp \ src/GFamilyTreeModel.cpp\ src/GNode.cpp \ src/GDateEstimator.cpp \ + src/GPinyinAppender.cpp \ src/PinyinMap.cpp \ src/MainWindow.cpp \ src/MainMenuBar.cpp \ diff --git a/Readme.txt b/Readme.txt index 39705c9..25261c2 100644 --- a/Readme.txt +++ b/Readme.txt @@ -1,4 +1,4 @@ -GedTools v1.5.1 +GedTools v1.6.0 Copyright © 2009 Nick Vrvilo http://ouuuuch.phoenixteam.org/ @@ -11,4 +11,4 @@ http://unicode.org/charts/unihan.html Unihan.zip contains a plain text version of the Unihan database The latest version of Unihan.zip is available for download at -http://unicode.org/Public/UNIDATA/ \ No newline at end of file +http://unicode.org/Public/UNIDATA/ diff --git a/inc/GPinyinAppender.h b/inc/GPinyinAppender.h new file mode 100644 index 0000000..4ee975f --- /dev/null +++ b/inc/GPinyinAppender.h @@ -0,0 +1,45 @@ +#ifndef V_G_PINYIN_APPENDER_H +#define V_G_PINYIN_APPENDER_H + +#include "GIndiMap.h" +#include "PinyinMap.h" + +/* GPinyinAppender: Adds pinyin data to all entries + * in a GIndiMap based on the data contained in the + * PinyinMap.dat file (accessed through PinyinMap). + */ +class GPinyinAppender { + +public: + + //=== Constructor/Destructor ===// + + /* Constructor */ + GPinyinAppender(); + + /* Destructor */ + ~GPinyinAppender(); + + //=== Methods ===// + + /* Appends pinyin data to the specified + * GIndiMap's individual entries + * @return incomplete ("?") entry count + */ + int appendTo(GIndiMap & indiMap); + +private: + + //=== Constants ===// + + // First unicode point for Chinese characters + static const int CJK_CODEPOINT; + + //=== Private Data Members ===// + + // Map containing pinyin data from PinyinMap.dat + PinyinMap * _pinyinMap; + +}; + +#endif diff --git a/installer/GedTools.nsi b/installer/GedTools.nsi index c5a7b71..e71ce0b 100644 --- a/installer/GedTools.nsi +++ b/installer/GedTools.nsi @@ -7,7 +7,7 @@ ;Name and file Name "GedTools" - OutFile "GedTools-1_5_0.exe" + OutFile "GedTools-1_6_0.exe" ;Default installation folder InstallDir $PROGRAMFILES\GedTools diff --git a/src/GFamily.cpp b/src/GFamily.cpp index 2aea837..49556ad 100644 --- a/src/GFamily.cpp +++ b/src/GFamily.cpp @@ -178,6 +178,9 @@ void GFamily::setMarriagePlace(const QString & place) { // Create the place node if needed if (!_marriagePlaceNode) { _marriagePlaceNode = new GNode(ENTRY_PLACE); + // Add the new node into the tree + if (_marriageDateNode) _marriageDateNode->setNext(_marriagePlaceNode); + else _marriageNode->setFirstChild(_marriagePlaceNode); } _marriagePlaceNode->setData(place); } diff --git a/src/GIndiEntry.cpp b/src/GIndiEntry.cpp index 2946e64..2964ea2 100644 --- a/src/GIndiEntry.cpp +++ b/src/GIndiEntry.cpp @@ -244,6 +244,9 @@ void GIndiEntry::setBirthPlace(const QString & place) { // Create the place node if needed if (!_birthPlaceNode) { _birthPlaceNode = new GNode(ENTRY_PLACE); + // Add the new node into the tree + if (_birthDateNode) _birthDateNode->setNext(_birthPlaceNode); + else _birthNode->setFirstChild(_birthPlaceNode); } _birthPlaceNode->setData(place); } @@ -269,6 +272,9 @@ void GIndiEntry::setDeathPlace(const QString & place) { // Create the place node if needed if (!_deathPlaceNode) { _deathPlaceNode = new GNode(ENTRY_PLACE); + // Add the new node into the tree + if (_deathDateNode) _deathDateNode->setNext(_deathPlaceNode); + else _deathNode->setFirstChild(_deathPlaceNode); } _deathPlaceNode->setData(place); } @@ -369,12 +375,18 @@ void GIndiEntry::parseDeath(GNode * n) { if (n) { _deathNode = n; n = n->firstChild(); - while (n && n->type() != TYPE_DATE) { + while (n) { + // Extract death date + if (n->type() == TYPE_DATE) { + _deathDateNode = n; + } + // Extract death place + else if (n->type() == TYPE_PLACE) { + _deathPlaceNode = n; + } n = n->next(); } } - // Extract death date - _deathDateNode = n; // Convert date string to an object for calculation purposes _deathYear = GNode::parseDateNode(_deathDateNode); } diff --git a/src/GPinyinAppender.cpp b/src/GPinyinAppender.cpp new file mode 100644 index 0000000..deb2fc3 --- /dev/null +++ b/src/GPinyinAppender.cpp @@ -0,0 +1,78 @@ + +#include "GPinyinAppender.h" + +//=== Constants ===// + +// First unicode point for Chinese characters +const int GPinyinAppender::CJK_CODEPOINT = 0x3400; + +//=== Constructor/Destructor ===// + +/* Constructor */ +GPinyinAppender::GPinyinAppender() { + _pinyinMap = new PinyinMap(); +} + +/* Destructor */ +GPinyinAppender::~GPinyinAppender() { + delete _pinyinMap; +} + +//=== Methods ===// + +/* Appends pinyin data to the specified + * GIndiMap's individual entries + * @return incomplete ("?") entry count + */ +int GPinyinAppender::appendTo(GIndiMap & indiMap) { + // Define loop variables + QString name; // Chinese name of individual + QString romanName; // Romanized name of individual + QString pinyin; // Hanyu pinyin for an individual character in the name + bool needSpace; // Don't append spaces between hanzi + bool hasHanzi; // If there are no hanzi then we don't need a romanized name + bool incomplete; // If this romanization has a "?" then it's incomplete + int incompleteCount = 0; // Total number of incomplete ("?") entries + GIndiMap::Iterator i, end = indiMap.end(); + // Loop through every GIndiEntry in the GIndiMap + for (i=indiMap.begin();i!=end;++i) { + // Reset variables for this name entry + name = i.value()->name(); + romanName = ""; + hasHanzi = false; + needSpace = false; + incomplete = false; + // Loop through each character in their name to append Pinyin + for (int j=0;j= CJK_CODEPOINT) { + // Append space if needed + if (needSpace) romanName.append(' '); + hasHanzi = true; + // Find the pinyin entry for this hanzi + pinyin = _pinyinMap->lookup(name[j]); + // If pinyin data is found then append it + if (!pinyin.isNull()) { + romanName.append(pinyin); + needSpace = true; + } + // If there is no pinyin found then append "?" + else { + romanName.append('?'); + needSpace = true; + incomplete = true; + } + } + // Otherwise append whatever the character is + else { + romanName.append(name[j]); + needSpace = false; + } + } + // Update the romanized name entry if needed + if (hasHanzi) i.value()->setRomanizedName(romanName); + // If this entry was incomplete then increment the count + if (incomplete) ++incompleteCount; + } + return incompleteCount; +} diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 76289d1..784b84f 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1,18 +1,16 @@ #include "MainWindow.h" #include "MainMenuBar.h" -#include "PinyinMap.h" +#include "TreeWindow.h" + +#include "GPinyinAppender.h" #include "GFamilyTreeModel.h" #include "GDateEstimator.h" -#include "TreeWindow.h" //=== Constants ===// -// First unicode point for Chinese characters -const int CJK_CODEPOINT = 0x3400; - // Program Version -const char * MainWindow::VERSION_NUMBER = "1.5.1"; +const char * MainWindow::VERSION_NUMBER = "1.6.0"; // File that disables auto updates const char * MainWindow::NO_UPDATE_FILE = "noUpdates"; @@ -179,67 +177,20 @@ void MainWindow::saveFile() { /* Append Hanyu Pinyin data */ void MainWindow::appendPinyin() { // Todo: Separate this from the GUI - int incompleteCount = 0; try { // PinyinMap may throw an exception if there's an IO problem - PinyinMap pinyinMap; - GIndiMap & indiMap = _gedFile->indiMap(); - GIndiMap::Iterator i, end = indiMap.end(); - QString name, romanName, pinyin; - bool needSpace; // Don't append spaces between hanzi - bool hasHanzi; // If there are no hanzi then we don't need a romanized name - bool incomplete; // If this romanization has a "?" then it's incomplete - // Loop through every GIndiEntry in the GIndiMap - for (i=indiMap.begin();i!=end;++i) { - // Reset variables for this name entry - name = i.value()->name(); - romanName = ""; - hasHanzi = false; - needSpace = false; - incomplete = false; - // Loop through each character in their name to append Pinyin - for (int j=0;j= CJK_CODEPOINT) { - // Append space if needed - if (needSpace) romanName.append(' '); - hasHanzi = true; - // Find the pinyin entry for this hanzi - pinyin = pinyinMap.lookup(name[j]); - // If pinyin data is found then append it - if (!pinyin.isNull()) { - romanName.append(pinyin); - needSpace = true; - } - // If there is no pinyin found then append "?" - else { - romanName.append('?'); - needSpace = true; - incomplete = true; - } - } - // Otherwise append whatever the character is - else { - romanName.append(name[j]); - needSpace = false; - } - } - // Update the romanized name entry if needed - if (hasHanzi) i.value()->setRomanizedName(romanName); - // If this entry was incomplete then increment the count - if (incomplete) ++incompleteCount; - } + // Append pinyin data to all individuals in the GIndiMap + GPinyinAppender pinyinAppender; + int incompleteCount = pinyinAppender.appendTo(_gedFile->indiMap()); // Update the Model/View now that data has been changed _indiModel->resetViews(); - // Display "?" count (number of hanzi without pinyin) + // Update status bar message QString statusMsg = tr("Pinyin added successfully!"); - if (incompleteCount == 0) { - statusBar()->showMessage(statusMsg); - } - else { + // Display "?" count (number of hanzi without pinyin) + if (incompleteCount > 0) { // Display "?" count (hanzi w/o pinyin) statusMsg.append(tr(" Incomplete Entries: ")); statusMsg.append(QString::number(incompleteCount)); - statusBar()->showMessage(statusMsg); } + statusBar()->showMessage(statusMsg); } catch (QString msg) { QMessageBox::critical(this, tr("Error"), tr("Unable to read PinyinMap.dat"));