1 // Updating the main window’s additional-info area
2 // Copyright © 2009 The University of Chicago
3 #include "linguisticamainwindow.h"
6 #include <Q3TextStream>
10 #include "MiniLexicon.h"
12 #include "GraphicView.h"
13 #include "LPreferences.h"
20 #include "SignatureCollection.h"
21 #include "TemplateCollection.h"
22 #include "SuffixCollection.h"
23 #include "PrefixCollection.h"
25 void LinguisticaMainWindow::setCommandLineStyle( QString style
)
27 QFont font
= m_eastFont
;
28 QString color
= GetPreference( style
+ "_Color" );
29 if( color
.length() == 0 ) color
= "black";
31 m_commandLine
->setColor( QColor( color
) );
33 m_commandLine
->setFamily( font
.family() );
34 m_commandLine
->setPointSize( font
.pointSize() );
36 font
= GetFontPreference( style
);
37 m_commandLine
->setBold( font
.bold() );
38 m_commandLine
->setItalic( font
.italic() );
39 m_commandLine
->setUnderline( font
.underline() );
43 void LinguisticaMainWindow::updateCommandLineSlot()
45 updateCommandLineSlot( NULL
);
48 void LinguisticaMainWindow::updateCommandLineSlot(Q3ListViewItem
* item
)
51 // set m_commandParse and m_commandMini for the selected
52 // collection view item.
57 case ALL_ANALYZED_WORDS
:
58 if (m_lexicon
->GetActiveMiniIndex() != -1) {
59 CWordListViewItem
* word
=
60 static_cast<CWordListViewItem
*>(item
);
62 if (!word
->isFullLex()) {
63 m_commandParse
= word
->GetWord();
73 CSuffixListViewItem
* suffix_item
=
74 static_cast<CSuffixListViewItem
*>(item
);
75 if (CSuffix
* suffix
= suffix_item
->GetAffix()) {
76 m_commandParse
= suffix
;
77 m_commandMini
= suffix
->GetMyMini()->GetIndex();
83 CPrefixListViewItem
* prefix_item
=
84 static_cast<CPrefixListViewItem
*>(item
);
85 if (CPrefix
* prefix
= prefix_item
->GetAffix()) {
86 m_commandParse
= prefix
;
87 m_commandMini
= prefix
->GetMyMini()->GetIndex();
95 CStemListViewItem
* stem_item
=
96 static_cast<CStemListViewItem
*>(item
);
97 if (CStem
* stem
= stem_item
->GetStem()) {
98 m_commandParse
= stem
;
99 m_commandMini
= stem
->GetMyMini()->GetIndex();
104 case PREFIX_SIGNATURES
:
105 case SUFFIX_SIGNATURES
:
107 CSignatureListViewItem
* sig_item
=
108 static_cast<CSignatureListViewItem
*>(item
);
109 if (CSignature
* sig
= sig_item
->GetSignature()) {
110 m_commandParse
= sig
;
111 m_commandMini
= sig
->GetMyMini()->GetIndex();
116 m_commandParse
= static_cast<CCompoundListViewItem
*>(item
)
119 case INITIALSTRINGEDITTEMPLATES
:
121 static_cast<CTemplateListViewItem
*>(item
)
124 case WORKINGSTRINGEDITTEMPLATES
:
126 static_cast<CTemplateListViewItem
*>(item
)
131 GUIPOSListViewItem
* pos_item
=
132 static_cast<GUIPOSListViewItem
*>(item
);
133 if (LxPoS
* pos
= pos_item
->GetPoS())
134 m_commandParse
= pos
;
145 // Clear the command line
146 m_commandLine
->clear();
147 m_commandLine
->setFont(m_eastFont
);
149 if (m_commandParse
== 0 && m_CommonState
== 0 && item
== 0)
153 QTextStream
ts(&text
, QIODevice::WriteOnly
);
155 CMiniLexicon
* mini
= m_lexicon
->GetMiniLexicon(m_commandMini
);
156 QMap
<QString
, QString
>* const filter
= m_lexicon
->GetOutFilter();
161 case ALL_ANALYZED_WORDS
:
163 // selected item in collection view
164 CWordListViewItem
* word_item
=
165 static_cast<CWordListViewItem
*>(item
);
166 CStem
* word
= word_item
->GetWord();
168 setCommandLineStyle("Stem");
169 m_commandLine
->insert(item
->text(1));
171 setCommandLineStyle("Affix");
172 const int nColumns
= m_lexicon
->GetMiniCount() + 2;
173 for (int i
= 2; i
< nColumns
; ++i
)
174 if (!item
->text(i
).isEmpty()) {
175 m_commandLine
->insert(QString(" %1")
176 .arg(item
->text(i
)));
179 m_commandLine
->insert(QString("\n%1").arg(
180 word
->GetProbabilityInformation()));
183 updateSmallGraphicDisplaySlotForPhonogy(word
);
185 // just updating the “command line” text
186 // XXX. Reconcile with other case.
188 CStem
* word
= static_cast<CStem
*>(m_commandParse
);
190 if (CPrefix
* pPrefix
= word
->GetPrefixPtr()) {
191 setCommandLineStyle("Affix");
192 m_commandLine
->insert(QString("%1 ")
193 .arg(pPrefix
->Display(filter
)));
196 if (CStem
* pStem
= word
->GetStemPtr()) {
197 setCommandLineStyle("Stem");
198 m_commandLine
->insert(QString("%1 ")
199 .arg(pStem
->Display(filter
)));
201 m_commandLine
->insert(word
->Display(filter
));
204 if (CSuffix
* pSuffix
= word
->GetSuffixPtr()) {
205 setCommandLineStyle("Affix");
206 m_commandLine
->insert(pSuffix
->Display(filter
));
209 m_commandLine
->insert(QString("\n%1")
210 .arg(word
->GetProbabilityInformation()));
213 updateSmallGraphicDisplaySlotForPhonogy(word
);
218 if (m_commandParse
== 0)
221 CSuffix
* suffix
= static_cast<CSuffix
*>(m_commandParse
);
222 QString selected
= suffix
->Display(filter
);
223 if (selected
.isEmpty()) {
224 setCommandLineStyle("Error");
225 m_commandLine
->insert(QString("Not found."));
230 setCommandLineStyle("Affix");
231 m_commandLine
->insert(selected
);
235 // Corresponding signatures
236 setCommandLineStyle("Main");
237 m_commandLine
->insert("\n\nSignatures:\n");
240 CSignatureCollection
* Signatures
= mini
->GetSignatures();
241 setCommandLineStyle("Signature");
242 for (int i
= 0; i
< Signatures
->GetCount(); ++i
) {
243 const CSignature
& sig
= *Signatures
->GetAt(i
);
245 if (sig
.Contains(selected
))
246 m_commandLine
->insert(QString("\t%1\n")
247 .arg(sig
.Display('.', filter
)));
250 // Corresponding stems
251 setCommandLineStyle("Main");
252 m_commandLine
->insert("\n\nStems:\n\t");
253 setCommandLineStyle("Stem");
256 if (CSuffix
* pSuffix
= *mini
->GetSuffixes() ^= selected
) {
257 CParse
* pParse
= pSuffix
->GetStemString();
259 for (int i
= 1; i
<= pParse
->Size(); ) {
260 for(int j
= 1; j
<= nColumns
; ++j
) {
261 QString text
= pParse
->GetPiece(i
)
265 m_commandLine
->insert(QString("%1\t")
268 // Make tab length depend on the longest
269 // word and font size
270 tablength
= std::max(tablength
,
272 m_commandLine
->pointSize());
273 m_commandLine
->insert("\n\t");
275 m_commandLine
->setTabStopWidth(tablength
);
282 if (m_commandParse
== 0)
285 CPrefix
* prefix
= static_cast<CPrefix
*>(m_commandParse
);
286 QString selected
= prefix
->Display(filter
);
287 if (selected
.isEmpty()) {
288 setCommandLineStyle("Error");
289 m_commandLine
->insert(QString("Not found."));
294 setCommandLineStyle("Affix");
295 m_commandLine
->insert(selected
);
299 // Corresponding signatures
300 setCommandLineStyle("Main");
301 m_commandLine
->insert("\n\nSignatures:\n");
304 CSignatureCollection
* Signatures
= mini
->GetSignatures();
305 setCommandLineStyle("Signature");
306 for (int i
= 0; i
< Signatures
->GetCount(); ++i
) {
307 const CSignature
& sig
= *Signatures
->GetAt(i
);
309 if (sig
.Contains(selected
))
310 m_commandLine
->insert(QString("\t%1\n")
311 .arg(sig
.Display('.', filter
)));
314 // Corresponding stems
315 setCommandLineStyle("Main");
316 m_commandLine
->insert("\n\nStems:\n\t");
317 setCommandLineStyle("Stem");
320 if (CPrefix
* pPrefix
= *mini
->GetPrefixes() ^= selected
) {
321 CParse
* pParse
= pPrefix
->GetStemString();
323 for (int i
= 1; i
<= pParse
->Size(); ) {
324 for(int j
= 1; j
<= nColumns
; ++j
) {
325 QString text
= pParse
->GetPiece(i
)
329 m_commandLine
->insert(QString("%1\t")
332 // Make tab length depend on the longest
333 // word and font size
334 tablength
= std::max(tablength
,
336 m_commandLine
->pointSize());
337 m_commandLine
->insert("\n\t");
339 m_commandLine
->setTabStopWidth(tablength
);
348 case SIGNATURE_SUBSET
:
350 case PREFIX_SIGNATURES
:
351 case SUFFIX_SIGNATURES
:
353 const QString sigPrefix
= " : ";
355 if (m_commandParse
== 0)
358 // XXX. avoid work if “command line” is not visible
360 CSignature
* sig
= static_cast<CSignature
*>(m_commandParse
);
361 QString selected
= sig
->Display('.', filter
);
362 if (selected
.left(3) == sigPrefix
)
363 selected
= selected
.mid(3);
365 if (selected
.isEmpty()) {
366 setCommandLineStyle("Error");
367 m_commandLine
->insert(QString("Not found."));
371 setCommandLineStyle("Signature");
372 m_commandLine
->insert(selected
);
374 setCommandLineStyle("Normal");
375 m_commandLine
->insert("\n\nStems:\n");
376 setCommandLineStyle("Stem");
378 CSignature
* pSig
= *mini
->GetSignatures() ^= selected
;
381 // alphabetize stems from the right end.
382 CParse StemList
= pSig
->GetStems();
384 StemList
.ReverseAlphabetize(); // from the end of the stem.
386 m_commandLine
->insert("\n\n");
389 for (int i
= 1; i
<= pSig
->GetNumberOfStems(); ) {
390 for (int j
= 1; j
<= nColumns
; ++j
) {
391 QString text
= StemList
[i
].Display(filter
)
395 m_commandLine
->insert(QString("%1\t")
398 // Make tab length depend on the longest
399 // word and font size
400 tablength
= std::max(tablength
,
402 m_commandLine
->pointSize());
405 m_commandLine
->insert("\n");
407 m_commandLine
->setTabStopWidth(tablength
);
409 m_commandLine
->insert("\nDL of my corpus: ");
410 m_commandLine
->insert(QString::number(
411 pSig
->ComputeDLofMyCorpus()));
413 m_commandLine
->insert("\nDL of my stem pointers: ");
414 m_commandLine
->insert(QString::number(
415 pSig
->GetDLofMyStemPointers()));
417 m_commandLine
->insert("\nDL of my suffix pointers: ");
418 m_commandLine
->insert(QString::number(
419 pSig
->GetDLofMyAffixPointers()));
421 m_commandLine
->insert("\nNumber of stem pointers: ");
422 m_commandLine
->insert(QString::number(
423 pSig
->GetStemPtrList()->count()));
425 // XXX. Display signature's stems graphically
426 // updateSmallGraphicDisplaySlotForMultiDimensionData(...)
433 if (m_commandParse
== 0)
435 LxPoS
* pos
= static_cast<LxPoS
*>(m_commandParse
);
436 pSig
= pos
->GetSignature();
437 QString selected
= pSig
->Display('.', filter
);
439 if (selected
.isEmpty()) {
440 setCommandLineStyle("Error");
441 m_commandLine
->insert(QString("Not found."));
447 setCommandLineStyle("Signature");
448 m_commandLine
->insert(selected
+ "\t" + dummy
.setNum(pSig
->GetNumberOfStems() ) + " stems") ;
451 for (int signo
= 0; signo
< pos
->GetNumberOfSignatures()-1; signo
++ ) // it's -1 because the number of signatures is one more than in the List; don't forget the "mother" signature
453 CSignature
* qSig
= pos
->GetSignature(signo
);
454 m_commandLine
->insert( "\n" + qSig
->Display() + "\t"+ dummy
.setNum( qSig
->GetNumberOfStems()) + " stems") ;
458 setCommandLineStyle("Normal");
459 m_commandLine
->insert("\n\nSatellite affixes:\n");
464 updateSmallGraphicDisplaySlot();
468 FSAListViewItem
* pFSAListViewItem
=
469 static_cast<FSAListViewItem
*>(item
);
470 pFSAListViewItem
->DisplayEdgePath(m_commandLine
);
471 QPixmap
* pFSAImage
= pFSAListViewItem
->GetQPixmap();
472 if(!pFSAImage
->isNull()) //if using graph-viz
474 this->pImgLabel
->setPixmap(
475 pFSAImage
->scaled(pImgLabel
->size(),
477 Qt::SmoothTransformation
) );
479 updateSmallGraphicDisplaySlot();
487 // further additions use plain text
488 setCommandLineStyle("Main");
489 m_commandLine
->setCursorPosition(0, 0);