Skip to content

Commit

Permalink
Moved Hanyu pinyin appending functions from GUI code (MainWindow) to …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
DaoWen committed Aug 7, 2009
1 parent dfbf3f6 commit 4493da3
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 67 deletions.
9 changes: 8 additions & 1 deletion Changes.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
* Support for appending Hanyu Pinyin data to the ROMN field
2 changes: 2 additions & 0 deletions GedTools.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions Readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GedTools v1.5.1
GedTools v1.6.0
Copyright � 2009 Nick Vrvilo
http://ouuuuch.phoenixteam.org/

Expand All @@ -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/
http://unicode.org/Public/UNIDATA/
45 changes: 45 additions & 0 deletions inc/GPinyinAppender.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion installer/GedTools.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/GFamily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 15 additions & 3 deletions src/GIndiEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
78 changes: 78 additions & 0 deletions src/GPinyinAppender.cpp
Original file line number Diff line number Diff line change
@@ -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<name.length();++j) {
// If it's a Hanzi then try to append pinyin for it
if (name[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;
}
71 changes: 11 additions & 60 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<name.length();++j) {
// If it's a Hanzi then append pinyin for it
if (name[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"));
Expand Down

0 comments on commit 4493da3

Please sign in to comment.