• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

lokalize

  • sources
  • kde-4.12
  • kdesdk
  • lokalize
  • src
  • glossary
glossary.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2007-2011 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License or (at your option) version 3 or any later version
10  accepted by the membership of KDE e.V. (or its successor approved
11  by the membership of KDE e.V.), which shall act as a proxy
12  defined in Section 14 of version 3 of the license.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 **************************************************************************** */
23 
24 #include "glossary.h"
25 
26 #include "stemming.h"
27 // #include "tbxparser.h"
28 #include "project.h"
29 #include "prefs_lokalize.h"
30 #include "domroutines.h"
31 
32 #include <kdebug.h>
33 
34 #include <QFile>
35 #include <QXmlSimpleReader>
36 #include <QXmlStreamReader>
37 #include <QBuffer>
38 #include <QApplication>
39 
40 using namespace GlossaryNS;
41 
42 static const QString defaultLang="en_US";
43 static const QString xmlLang="xml:lang";
44 static const QString ntig="ntig";
45 static const QString tig="tig";
46 static const QString termGrp="termGrp";
47 static const QString langSet="langSet";
48 static const QString term="term";
49 static const QString id="id";
50 
51 
52 
53 QList<QByteArray> Glossary::idsForLangWord(const QString& lang, const QString& word) const
54 {
55  return idsByLangWord[lang].values(word);
56 }
57 
58 
59 Glossary::Glossary(QObject* parent)
60  : QObject(parent)
61 {
62 }
63 
64 
65 //BEGIN DISK
66 bool Glossary::load(const QString& newPath)
67 {
68  QTime a;a.start();
69 //BEGIN NEW
70  QIODevice* device=new QFile(newPath);
71  if (!device->open(QFile::ReadOnly | QFile::Text))
72  {
73  delete device;
74  //return;
75  device=new QBuffer();
76  static_cast<QBuffer*>(device)->setData(QByteArray(
77 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
78 "<!DOCTYPE martif PUBLIC \"ISO 12200:1999A//DTD MARTIF core (DXFcdV04)//EN\" \"TBXcdv04.dtd\">\n"
79 "<martif type=\"TBX\" xml:lang=\"en_US\">\n"
80 " <text>\n"
81 " <body>\n"
82 " </body>\n"
83 " </text>\n"
84 "</martif>\n"
85 ));
86  }
87 
88  QXmlSimpleReader reader;
89  //reader.setFeature("http://qtsoftware.com/xml/features/report-whitespace-only-CharData",true);
90  reader.setFeature("http://xml.org/sax/features/namespaces",false);
91  QXmlInputSource source(device);
92 
93  QDomDocument newDoc;
94  QString errorMsg;
95  int errorLine;//+errorColumn;
96  bool success=newDoc.setContent(&source, &reader, &errorMsg, &errorLine/*,errorColumn*/);
97 
98  delete device;
99 
100  if (!success)
101  {
102  kWarning()<<errorMsg;
103  return false; //errorLine+1;
104  }
105  clear();//does setClean(true);
106  m_path=newPath;
107  m_doc=newDoc;
108 
109  //QDomElement file=m_doc.elementsByTagName("file").at(0).toElement();
110  m_entries=m_doc.elementsByTagName("termEntry");
111  for(int i=0;i<m_entries.size();i++)
112  hashTermEntry(m_entries.at(i).toElement());
113  m_idsForEntriesById=m_entriesById.keys();
114 
115 //END NEW
116 #if 0
117  TbxParser parser(this);
118  QXmlSimpleReader reader1;
119  reader1.setContentHandler(&parser);
120 
121  QFile file(p);
122  if (!file.open(QFile::ReadOnly | QFile::Text))
123  return;
124  QXmlInputSource xmlInputSource(&file);
125  if (!reader1.parse(xmlInputSource))
126  kWarning() << "failed to load "<< path;
127 #endif
128  emit loaded();
129 
130  qDebug()<<"glossary loaded in"<<a.elapsed();
131 
132  return true;
133 }
134 
135 bool Glossary::save()
136 {
137  if (m_path.isEmpty())
138  return false;
139 
140  QFile* device=new QFile(m_path);
141  if (!device->open(QFile::WriteOnly | QFile::Truncate))
142  {
143  device->deleteLater();
144  return false;
145  }
146  QTextStream stream(device);
147  m_doc.save(stream,2);
148 
149  device->deleteLater();
150 
151  setClean(true);
152  return true;
153 }
154 
155 void Glossary::setClean(bool clean)
156 {
157  m_clean=clean;
158  emit changed();//may be emitted multiple times in a row. so what? :)
159 }
160 
161 //END DISK
162 
163 //BEGIN MODEL
164 #define FETCH_SIZE 128
165 
166 void GlossarySortFilterProxyModel::setFilterRegExp(const QString& s)
167 {
168  if (!sourceModel())
169  return;
170 
171  //static const QRegExp lettersOnly("^[a-z]");
172  QSortFilterProxyModel::setFilterRegExp(s);
173 
174  fetchMore(QModelIndex());
175 }
176 
177 void GlossarySortFilterProxyModel::fetchMore(const QModelIndex& parent)
178 {
179  int expectedCount=rowCount()+FETCH_SIZE/2;
180  while (rowCount(QModelIndex())<expectedCount && sourceModel()->canFetchMore(QModelIndex()))
181  {
182  sourceModel()->fetchMore(QModelIndex());
183  //qDebug()<<"filter:"<<rowCount(QModelIndex())<<"/"<<sourceModel()->rowCount();
184  qApp->processEvents();
185  }
186 }
187 
188 GlossaryModel::GlossaryModel(QObject* parent)
189  : QAbstractListModel(parent)
190  , m_visibleCount(0)
191  , m_glossary(Project::instance()->glossary())
192 {
193  connect(m_glossary, SIGNAL(loaded()), this, SLOT(forceReset()));
194 }
195 
196 void GlossaryModel::forceReset()
197 {
198  beginResetModel();
199  m_visibleCount=0;
200  endResetModel();
201 }
202 
203 bool GlossaryModel::canFetchMore(const QModelIndex& parent) const
204 {
205  return false;
206 }
207 
208 void GlossaryModel::fetchMore(const QModelIndex& parent)
209 {
210  int newVisibleCount=qMin(m_visibleCount+FETCH_SIZE,m_glossary->size());
211  beginInsertRows(parent, m_visibleCount, newVisibleCount-1);
212  m_visibleCount=newVisibleCount;
213  endInsertRows();
214 }
215 
216 int GlossaryModel::rowCount(const QModelIndex& parent) const
217 {
218  if (parent.isValid())
219  return 0;
220  return m_glossary->size();//m_visibleCount;
221 }
222 
223 QVariant GlossaryModel::headerData( int section, Qt::Orientation /*orientation*/, int role) const
224 {
225  if (role!=Qt::DisplayRole)
226  return QVariant();
227 
228  switch (section)
229  {
230  //case ID: return i18nc("@title:column","ID");
231  case English: return i18nc("@title:column Original text","Source");;
232  case Target: return i18nc("@title:column Text in target language","Target");
233  case SubjectField: return i18nc("@title:column","Subject Field");
234  }
235  return QVariant();
236 }
237 
238 QVariant GlossaryModel::data(const QModelIndex& index, int role) const
239 {
240  //if (role==Qt::SizeHintRole)
241  // return QVariant(QSize(50, 30));
242 
243  if (role!=Qt::DisplayRole)
244  return QVariant();
245 
246  static const QString nl=QString(" ")+QChar(0x00B7)+' ';
247  static Project* project=Project::instance();
248  Glossary* glossary=m_glossary;
249 
250  QByteArray id=glossary->id(index.row());
251  switch (index.column())
252  {
253  case ID: return id;
254  case English: return glossary->terms(id, project->sourceLangCode()).join(nl);
255  case Target: return glossary->terms(id, project->targetLangCode()).join(nl);
256  case SubjectField: return glossary->subjectField(id);
257  }
258  return QVariant();
259 }
260 
261 /*
262 QModelIndex GlossaryModel::index (int row,int column,const QModelIndex& parent) const
263 {
264  return createIndex (row, column);
265 }
266 */
267 
268 int GlossaryModel::columnCount(const QModelIndex&) const
269 {
270  return GlossaryModelColumnCount;
271 }
272 
273 /*
274 Qt::ItemFlags GlossaryModel::flags ( const QModelIndex & index ) const
275 {
276  return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
277  //if (index.column()==FuzzyFlag)
278  // return Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled;
279  //return QAbstractItemModel::flags(index);
280 }
281 */
282 
283 
284 //END MODEL general (GlossaryModel continues below)
285 
286 //BEGIN EDITING
287 
288 QByteArray Glossary::generateNewId()
289 {
290  // generate unique ID
291  int idNumber=0;
292  QList<int> busyIdNumbers;
293 
294  QString authorId(Settings::authorName().toLower());
295  authorId.replace(' ','_');
296  QRegExp rx('^'+authorId+"\\-([0-9]*)$");
297 
298 
299  foreach(const QByteArray& id, m_idsForEntriesById)
300  {
301  if (rx.exactMatch(QString::fromLatin1(id)))
302  busyIdNumbers.append(rx.cap(1).toInt());
303  }
304 
305  int i=removedIds.size();
306  while(--i>=0)
307  {
308  if (rx.exactMatch(QString::fromLatin1(removedIds.at(i))))
309  busyIdNumbers.append(rx.cap(1).toInt());
310  }
311 
312  if (!busyIdNumbers.isEmpty())
313  {
314  qSort(busyIdNumbers);
315  while (busyIdNumbers.contains(idNumber))
316  ++idNumber;
317  }
318 
319  return QString(authorId+"-%1").arg(idNumber).toLatin1();
320 }
321 
322 QStringList Glossary::subjectFields() const
323 {
324  QSet<QString> result;
325  foreach(const QByteArray& id, m_idsForEntriesById)
326  result.insert(subjectField(id));
327  return result.toList();
328 }
329 
330 QByteArray Glossary::id(int index) const
331 {
332  if (index<m_idsForEntriesById.size())
333  return m_idsForEntriesById.at(index);
334  return QByteArray();
335 }
336 
337 QStringList Glossary::terms(const QByteArray& id, const QString& language) const
338 {
339  QString minusLang=language; minusLang.replace('_', '-');
340  QStringRef soleLang=language.leftRef(2);
341  QStringList result;
342  QDomElement n = m_entriesById.value(id).firstChildElement(langSet);
343  while (!n.isNull())
344  {
345  QString lang=n.attribute(xmlLang, defaultLang);
346 
347  if (language==lang || minusLang==lang || soleLang==lang)
348  {
349  QDomElement ntigElem=n.firstChildElement(ntig);
350  while (!ntigElem.isNull())
351  {
352  result<<ntigElem.firstChildElement(termGrp).firstChildElement(term).text();
353  ntigElem=ntigElem.nextSiblingElement(ntig);
354  }
355  QDomElement tigElem=n.firstChildElement(tig);
356  while (!tigElem.isNull())
357  {
358  result<<tigElem.firstChildElement(term).text();
359  tigElem=tigElem.nextSiblingElement(tig);
360  }
361  }
362 
363  n = n.nextSiblingElement(langSet);
364  }
365 
366  return result;
367 }
368 
369 // QDomElement ourLangSetElement will reference the lang tag we want (if it exists)
370 static void getElementsForTermLangIndex(QDomElement termEntry, QString& lang, int index,
371  QDomElement& ourLangSetElement,
372  QDomElement& tigElement, //<-- can point to <ntig> as well
373  QDomElement& termElement)
374 {
375  QString minusLang=lang; minusLang.replace('_', '-');
376  QStringRef soleLang=lang.leftRef(2);
377 
378  //qDebug()<<"started walking over"<<lang<<index;
379  QDomElement n = termEntry.firstChildElement(langSet);
380  QDomDocument document=n.ownerDocument();
381  int i=0;
382  while (!n.isNull())
383  {
384  QString nLang=n.attribute(xmlLang, defaultLang);
385 
386  if (lang==nLang || minusLang==nLang || soleLang==nLang)
387  {
388  ourLangSetElement=n;
389  QDomElement ntigElem=n.firstChildElement(ntig);
390  while(!ntigElem.isNull())
391  {
392  //qDebug()<<i<<ntigElem.firstChildElement(termGrp).firstChildElement(term).text();
393  if (i==index)
394  {
395  tigElement=ntigElem;
396  termElement=ntigElem.firstChildElement(termGrp).firstChildElement(term);
397  return;
398  }
399  ntigElem = ntigElem.nextSiblingElement(ntig);
400  i++;
401  }
402  QDomElement tigElem=n.firstChildElement(tig);
403  while(!tigElem.isNull())
404  {
405  //qDebug()<<i<<tigElem.firstChildElement(term).text();
406  if (i==index)
407  {
408  tigElement=tigElem;
409  termElement=tigElem.firstChildElement(term);
410  return;
411  }
412  tigElem = tigElem.nextSiblingElement(tig);
413  i++;
414  }
415  }
416  n = n.nextSiblingElement(langSet);
417  }
418 }
419 
420 
421 void Glossary::setTerm(const QByteArray& id, QString lang, int index, const QString& termText)
422 {
423  setClean(false);
424 
425  QDomElement ourLangSetElement; //will reference the lang we want if it exists
426  QDomElement tigElement;
427  QDomElement termElement;
428  getElementsForTermLangIndex(m_entriesById.value(id), lang, index,
429  ourLangSetElement, tigElement, termElement);
430 
431  if (!termElement.isNull())
432  {
433  setText(termElement,termText);
434  return;
435  }
436  QDomElement entry=m_entriesById.value(id);
437  QDomDocument document=entry.ownerDocument();
438  if (ourLangSetElement.isNull())
439  {
440  ourLangSetElement=entry.appendChild( document.createElement(langSet)).toElement();
441  lang.replace('_', '-');
442  ourLangSetElement.setAttribute(xmlLang,lang);
443  }
444 /*
445  QDomElement ntigElement=ourLangSetElement.appendChild( document.createElement(ntig)).toElement();
446  QDomElement termGrpElement=ntigElement.appendChild( document.createElement(termGrp)).toElement();
447  termElement=termGrpElement.appendChild( document.createElement(term)).toElement();
448  termElement.appendChild( document.createTextNode(termText));
449 */
450  tigElement=ourLangSetElement.appendChild( document.createElement(tig)).toElement();
451  termElement=tigElement.appendChild( document.createElement(term)).toElement();
452  termElement.appendChild( document.createTextNode(termText));
453 }
454 
455 void Glossary::rmTerm(const QByteArray& id, QString lang, int index)
456 {
457  setClean(false);
458 
459  QDomElement ourLangSetElement; //will reference the lang we want if it exists
460  QDomElement tigElement;
461  QDomElement termElement;
462  getElementsForTermLangIndex(m_entriesById.value(id), lang, index,
463  ourLangSetElement, tigElement, termElement);
464 
465  if (!tigElement.isNull())
466  ourLangSetElement.removeChild(tigElement);
467 }
468 
469 
470 static QDomElement firstDescripElemForLang(QDomElement termEntry, const QString& lang)
471 {
472  if (lang.isEmpty())
473  return termEntry.firstChildElement("descrip");
474 
475  QString minusLang=lang;
476  minusLang.replace('_', '-');
477 
478  //disable this for now
479  //bool enUSLangGiven=defaultLang==lang; //treat en_US and en as equal
480  //bool enLangGiven="en"==lang; //treat en_US and en as equal
481 
482  QDomElement n=termEntry.firstChildElement(langSet);
483  while (!n.isNull())
484  {
485  const QString& curLang=n.attribute(xmlLang);
486  if (curLang==lang || curLang==minusLang
487  //|| (enUSLangGiven && curLang=="en")
488  //|| (enLangGiven && curLang==defaultLang)
489  )
490  return n.firstChildElement("descrip");
491 
492  n = n.nextSiblingElement(langSet);
493  }
494  return QDomElement();
495 }
496 
497 
498 QString Glossary::descrip(const QByteArray& id, const QString& lang, const QString& type) const
499 {
500  QDomElement n = firstDescripElemForLang(m_entriesById.value(id), lang);
501  if (n.isNull())
502  return QString();
503 
504  while (!n.isNull())
505  {
506  if (n.attribute("type")==type)
507  return n.text();
508 
509  n = n.nextSiblingElement("descrip");
510  }
511  return QString();
512 }
513 
514 void Glossary::setDescrip(const QByteArray& id, QString lang, const QString& type, const QString& value)
515 {
516  setClean(false);
517 
518  QDomElement descripElem = firstDescripElemForLang(m_entriesById.value(id), lang);
519 
520  QDomDocument document=descripElem.ownerDocument();
521  while (!descripElem.isNull())
522  {
523  if (descripElem.attribute("type")==type)
524  return setText(descripElem,value);;
525 
526  descripElem = descripElem.nextSiblingElement("descrip");
527  }
528 
529  //create new descrip element
530  QDomElement parentForDescrip = m_entriesById.value(id);
531  if (!lang.isEmpty())
532  {
533  //find/create a langSet elem that should be parent of the new descrip
534  QDomElement langSetElem = m_entriesById.value(id).firstChildElement(langSet);
535  while (!langSetElem.isNull())
536  {
537  QString nLang=langSetElem.attribute(xmlLang, defaultLang);
538  nLang.replace('-','_');
539  if (lang=="en") //NOTE COMPAT
540  {
541  lang=defaultLang;
542  nLang.replace('_','-');
543  langSetElem.setAttribute(xmlLang, defaultLang);
544  }
545 
546  if (lang==nLang)
547  break;
548 
549  langSetElem = langSetElem.nextSiblingElement(langSet);
550  }
551  if (!langSetElem.isNull())
552  parentForDescrip=langSetElem;
553  else
554  {
555  parentForDescrip=parentForDescrip.appendChild( document.createElement(langSet)).toElement();
556  lang.replace('_', '-');
557  parentForDescrip.setAttribute(xmlLang,lang);
558  }
559  }
560  QDomElement descrip=parentForDescrip.insertBefore( document.createElement("descrip"), parentForDescrip.firstChild() ).toElement();
561  descrip.setAttribute("type",type);
562  descrip.appendChild( document.createTextNode(value));
563 }
564 
565 QString Glossary::subjectField(const QByteArray& id, const QString& lang) const
566 {
567  return descrip(id, lang, "subjectField");
568 }
569 
570 QString Glossary::definition(const QByteArray& id, const QString& lang) const
571 {
572  return descrip(id, lang, "definition");
573 }
574 
575 void Glossary::setSubjectField(const QByteArray& id, const QString& lang, const QString& value)
576 {
577  setDescrip(id, lang, "subjectField", value);
578 }
579 
580 void Glossary::setDefinition(const QByteArray& id, const QString& lang, const QString& value)
581 {
582  setDescrip(id, lang, "definition", value);
583 }
584 
585 
586 
587 //add words to the hash
588 // static void addToHash(const QMultiHash<QString,int>& wordHash,
589 // const QString& what,
590 // int index)
591 void Glossary::hashTermEntry(const QDomElement& termEntry)
592 {
593  QByteArray entryId=termEntry.attribute(::id).toLatin1();
594  if (entryId.isEmpty())
595  return;
596 
597  m_entriesById.insert(entryId,termEntry);
598 
599  QString sourceLangCode=Project::instance()->sourceLangCode();
600  foreach(const QString& termText, terms(entryId, sourceLangCode))
601  {
602  foreach(const QString& word, termText.split(' ',QString::SkipEmptyParts))
603  idsByLangWord[sourceLangCode].insert(stem(sourceLangCode,word),entryId);
604  }
605 }
606 
607 void Glossary::unhashTermEntry(const QDomElement& termEntry)
608 {
609  QByteArray entryId=termEntry.attribute(::id).toLatin1();
610  m_entriesById.remove(entryId);
611 
612  QString sourceLangCode=Project::instance()->sourceLangCode();
613  foreach(const QString& termText, terms(entryId, sourceLangCode))
614  {
615  foreach(const QString& word, termText.split(' ',QString::SkipEmptyParts))
616  idsByLangWord[sourceLangCode].remove(stem(sourceLangCode,word),entryId);
617  }
618 }
619 
620 #if 0
621 void Glossary::hashTermEntry(int index)
622 {
623  Q_ASSERT(index<termList.size());
624  foreach(const QString& term, termList_.at(index).english)
625  {
626  foreach(const QString& word, term.split(' ',QString::SkipEmptyParts))
627  wordHash_.insert(stem(Project::instance()->sourceLangCode(),word),index);
628  }
629 }
630 
631 void Glossary::unhashTermEntry(int index)
632 {
633  Q_ASSERT(index<termList.size());
634  foreach(const QString& term, termList_.at(index).english)
635  {
636  foreach(const QString& word, term.split(' ',QString::SkipEmptyParts))
637  wordHash_.remove(stem(Project::instance()->sourceLangCode(),word),index);
638  }
639 }
640 #endif
641 
642 void Glossary::removeEntry(const QByteArray& id)
643 {
644  if (!m_entriesById.contains(id))
645  return;
646 
647  QDomElement entry = m_entriesById.value(id);
648  if (entry.nextSibling().isCharacterData())
649  entry.parentNode().removeChild(entry.nextSibling()); //nice formatting
650  entry.parentNode().removeChild(entry);
651  m_entriesById.remove(id);
652 
653  unhashTermEntry(entry);
654  m_idsForEntriesById=m_entriesById.keys();
655  removedIds.append(id); //for new id generation goodness
656 
657  setClean(false);
658 }
659 
660 static void appendTerm(QDomElement langSetElem, const QString& termText)
661 {
662  QDomDocument doc=langSetElem.ownerDocument();
663 /*
664  QDomElement ntigElement=doc.createElement(ntig); langSetElem.appendChild(ntigElement);
665  QDomElement termGrpElement=doc.createElement(termGrp); ntigElement.appendChild(termGrpElement);
666  QDomElement termElement=doc.createElement(term); termGrpElement.appendChild(termElement);
667  termElement.appendChild(doc.createTextNode(termText));
668 */
669  QDomElement tigElement=doc.createElement(tig); langSetElem.appendChild(tigElement);
670  QDomElement termElement=doc.createElement(term); tigElement.appendChild(termElement);
671  termElement.appendChild(doc.createTextNode(termText));
672 }
673 
674 QByteArray Glossary::append(const QStringList& sourceTerms, const QStringList& targetTerms)
675 {
676  if (!m_doc.elementsByTagName("body").count())
677  return QByteArray();
678 
679  setClean(false);
680  QDomElement termEntry=m_doc.createElement("termEntry");
681  m_doc.elementsByTagName("body").at(0).appendChild(termEntry);
682 
683  //m_entries=m_doc.elementsByTagName("termEntry");
684 
685  QByteArray newId=generateNewId();
686  termEntry.setAttribute(::id, QString::fromLatin1(newId));
687 
688  QDomElement sourceElem=m_doc.createElement(langSet); termEntry.appendChild(sourceElem);
689  sourceElem.setAttribute(xmlLang, Project::instance()->sourceLangCode().replace('_','-'));
690  foreach (QString sourceTerm, sourceTerms)
691  appendTerm(sourceElem, sourceTerm);
692 
693  QDomElement targetElem=m_doc.createElement(langSet); termEntry.appendChild(targetElem);
694  targetElem.setAttribute(xmlLang, Project::instance()->targetLangCode().replace('_', '-'));
695  foreach (QString targetTerm, targetTerms)
696  appendTerm(targetElem, targetTerm);
697 
698  hashTermEntry(termEntry);
699  m_idsForEntriesById=m_entriesById.keys();
700 
701  return newId;
702 }
703 
704 void Glossary::append(const QString& _english, const QString& _target)
705 {
706  append(QStringList(_english), QStringList(_target));
707 }
708 
709 void Glossary::clear()
710 {
711  setClean(true);
712  //path.clear();
713  idsByLangWord.clear();
714  m_entriesById.clear();
715  m_idsForEntriesById.clear();
716 
717  removedIds.clear();
718  changedIds_.clear();
719  addedIds_.clear();
720  wordHash_.clear();
721  termList_.clear();
722  langWordEntry_.clear();
723  subjectFields_=QStringList(QLatin1String(""));
724 
725  m_doc.clear();
726 }
727 
728 
729 bool GlossaryModel::removeRows(int row, int count, const QModelIndex& parent)
730 {
731  beginRemoveRows(parent,row,row+count-1);
732 
733  Glossary* glossary=Project::instance()->glossary();
734  int i=row+count;
735  while (--i>=row)
736  glossary->removeEntry(glossary->id(i));
737 
738  endRemoveRows();
739  return true;
740 }
741 
742 // bool GlossaryModel::insertRows(int row,int count,const QModelIndex& parent)
743 // {
744 // if (row!=rowCount())
745 // return false;
746 QByteArray GlossaryModel::appendRow(const QString& _english, const QString& _target)
747 {
748  bool notify=!canFetchMore(QModelIndex());
749  if (notify)
750  beginInsertRows(QModelIndex(),rowCount(),rowCount());
751 
752  QByteArray id=m_glossary->append(QStringList(_english), QStringList(_target));
753 
754  if (notify)
755  {
756  m_visibleCount++;
757  endInsertRows();
758  }
759  return id;
760 }
761 
762 //END EDITING
763 
764 #include "glossary.moc"
FETCH_SIZE
#define FETCH_SIZE
Definition: glossary.cpp:164
GlossaryNS::Glossary::setClean
void setClean(bool)
Definition: glossary.cpp:155
project.h
GlossaryNS::Glossary::setSubjectField
void setSubjectField(const QByteArray &id, const QString &lang, const QString &value)
Definition: glossary.cpp:575
GlossaryNS::GlossaryModel::English
Definition: glossary.h:188
GlossaryNS::GlossaryModel::headerData
QVariant headerData(int section, Qt::Orientation, int role=Qt::DisplayRole) const
Definition: glossary.cpp:223
GlossaryNS::TbxParser
loads only data we need to store in memory e.g.
Definition: tbxparser_obsolete.h:41
GlossaryNS::GlossaryModel::appendRow
QByteArray appendRow(const QString &_english, const QString &_target)
Definition: glossary.cpp:746
GlossaryNS::GlossaryModel::forceReset
void forceReset()
Definition: glossary.cpp:196
GlossaryNS::Glossary::subjectField
QString subjectField(const QByteArray &id, const QString &lang=QString()) const
Definition: glossary.cpp:565
stem
QString stem(const QString &langCode, const QString &word)
Definition: stemming.cpp:72
GlossaryNS::GlossaryModel::fetchMore
void fetchMore(const QModelIndex &parent)
Definition: glossary.cpp:208
GlossaryNS::Glossary::size
int size() const
Definition: glossary.h:125
id
static const QString id
Definition: glossary.cpp:49
GlossaryNS::GlossaryModel::GlossaryModel
GlossaryModel(QObject *parent)
Definition: glossary.cpp:188
GlossaryNS::Glossary::id
QByteArray id(int index) const
Definition: glossary.cpp:330
Project::instance
static Project * instance()
Definition: project.cpp:67
GlossaryNS::GlossaryModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: glossary.cpp:268
GlossaryNS::GlossarySortFilterProxyModel::setFilterRegExp
void setFilterRegExp(const QString &s)
Definition: glossary.cpp:166
term
static const QString term
Definition: glossary.cpp:48
QAbstractListModel
xmlLang
static const QString xmlLang
Definition: glossary.cpp:43
QObject
GlossaryNS::Glossary::Glossary
Glossary(QObject *parent)
Definition: glossary.cpp:59
GlossaryNS::Glossary::rmTerm
void rmTerm(const QByteArray &id, QString lang, int i)
Definition: glossary.cpp:455
Settings::authorName
static QString authorName()
Get authorName.
Definition: prefs_lokalize.h:25
GlossaryNS::GlossaryModel::data
QVariant data(const QModelIndex &, int role=Qt::DisplayRole) const
Definition: glossary.cpp:238
Project
Singleton object that represents project.
Definition: project.h:51
GlossaryNS::Glossary
Internal representation of glossary.
Definition: glossary.h:95
GlossaryNS::GlossaryModel::ID
Definition: glossary.h:187
GlossaryNS::Glossary::load
bool load(const QString &)
Definition: glossary.cpp:66
GlossaryNS::Glossary::path
QString path() const
Definition: glossary.h:104
setText
void setText(QDomElement element, QString text)
Definition: domroutines.cpp:26
GlossaryNS::Glossary::hashTermEntry
void hashTermEntry(const QDomElement &)
Definition: glossary.cpp:591
Project::glossary
GlossaryNS::Glossary * glossary() const
Definition: project.h:73
GlossaryNS::Glossary::unhashTermEntry
void unhashTermEntry(const QDomElement &)
Definition: glossary.cpp:607
domroutines.h
Project::targetLangCode
Q_SCRIPTABLE QString targetLangCode() const
Definition: project.h:87
GlossaryNS::Glossary::removeEntry
void removeEntry(const QByteArray &id)
Definition: glossary.cpp:642
glossary.h
GlossaryNS::Glossary::save
bool save()
Definition: glossary.cpp:135
GlossaryNS::GlossaryModel::SubjectField
Definition: glossary.h:190
GlossaryNS::Glossary::idsForLangWord
QList< QByteArray > idsForLangWord(const QString &lang, const QString &word) const
Definition: glossary.cpp:53
stemming.h
GlossaryNS::Glossary::setTerm
void setTerm(const QByteArray &id, QString lang, int i, const QString &term)
Definition: glossary.cpp:421
GlossaryNS::Glossary::clear
void clear()
Definition: glossary.cpp:709
GlossaryNS::Glossary::terms
QStringList terms(const QByteArray &id, const QString &lang) const
Definition: glossary.cpp:337
prefs_lokalize.h
firstDescripElemForLang
static QDomElement firstDescripElemForLang(QDomElement termEntry, const QString &lang)
Definition: glossary.cpp:470
appendTerm
static void appendTerm(QDomElement langSetElem, const QString &termText)
Definition: glossary.cpp:660
getElementsForTermLangIndex
static void getElementsForTermLangIndex(QDomElement termEntry, QString &lang, int index, QDomElement &ourLangSetElement, QDomElement &tigElement, QDomElement &termElement)
Definition: glossary.cpp:370
GlossaryNS::GlossarySortFilterProxyModel::fetchMore
void fetchMore(const QModelIndex &parent)
Definition: glossary.cpp:177
GlossaryNS::GlossaryModel::canFetchMore
bool canFetchMore(const QModelIndex &parent) const
Definition: glossary.cpp:203
GlossaryNS::GlossaryModel::Target
Definition: glossary.h:189
tig
static const QString tig
Definition: glossary.cpp:45
GlossaryNS::GlossaryModel::removeRows
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: glossary.cpp:729
GlossaryNS::Glossary::subjectFields
QStringList subjectFields() const
Definition: glossary.cpp:322
GlossaryNS::Glossary::generateNewId
QByteArray generateNewId()
Definition: glossary.cpp:288
GlossaryNS::Glossary::append
void append(const QString &_english, const QString &_target)
Definition: glossary.cpp:704
termGrp
static const QString termGrp
Definition: glossary.cpp:46
GlossaryNS::GlossaryModel::GlossaryModelColumnCount
Definition: glossary.h:191
ntig
static const QString ntig
Definition: glossary.cpp:44
GlossaryNS::Glossary::definition
QString definition(const QByteArray &id, const QString &lang=QString()) const
Definition: glossary.cpp:570
GlossaryNS::Glossary::setDefinition
void setDefinition(const QByteArray &id, const QString &lang, const QString &value)
Definition: glossary.cpp:580
defaultLang
static const QString defaultLang
Definition: glossary.cpp:42
GlossaryNS::Glossary::changed
void changed()
GlossaryNS::Glossary::loaded
void loaded()
langSet
static const QString langSet
Definition: glossary.cpp:47
Project::sourceLangCode
Q_SCRIPTABLE QString sourceLangCode() const
Definition: project.h:88
GlossaryNS::GlossaryModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: glossary.cpp:216
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:45 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal