KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

debuggui.cpp 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* This file is part of the KDE project
  2. Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this program; see the file COPYING. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. * Boston, MA 02110-1301, USA.
  15. */
  16. #include "utils.h"
  17. #include "utils_p.h"
  18. #include <tqheader.h>
  19. #include <tqlayout.h>
  20. #include <ktabwidget.h>
  21. #include <tdelistview.h>
  22. #include <kiconloader.h>
  23. #include <kdialogbase.h>
  24. #include <kpushbutton.h>
  25. #include <kguiitem.h>
  26. #ifdef KEXI_DEBUG_GUI
  27. static DebugWindowDialog* debugWindow = 0;
  28. static KTabWidget* debugWindowTab = 0;
  29. static TDEListView* kexiDBDebugPage = 0;
  30. static TDEListView* kexiAlterTableActionDebugPage = 0;
  31. TQWidget *KexiUtils::createDebugWindow(TQWidget *parent)
  32. {
  33. // (this is internal code - do not use i18n() here)
  34. debugWindow = new DebugWindowDialog(parent);
  35. debugWindow->setSizeGripEnabled( true );
  36. TQBoxLayout *lyr = new TQVBoxLayout(debugWindow, KDialogBase::marginHint());
  37. debugWindowTab = new KTabWidget(debugWindow, "debugWindowTab");
  38. lyr->addWidget( debugWindowTab );
  39. debugWindow->resize(900, 600);
  40. debugWindow->setIcon( DesktopIcon("application-vnd.tde.info") );
  41. debugWindow->setCaption("Kexi Internal Debugger");
  42. debugWindow->show();
  43. return debugWindow;
  44. }
  45. void KexiUtils::addKexiDBDebug(const TQString& text)
  46. {
  47. // (this is internal code - do not use i18n() here)
  48. if (!debugWindowTab)
  49. return;
  50. if (!kexiDBDebugPage) {
  51. TQWidget *page = new TQWidget(debugWindowTab);
  52. TQVBoxLayout *vbox = new TQVBoxLayout(page);
  53. TQHBoxLayout *hbox = new TQHBoxLayout(page);
  54. vbox->addLayout(hbox);
  55. hbox->addStretch(1);
  56. KPushButton *btn_clear = new KPushButton(KGuiItem("Clear", "clear_left"), page);
  57. hbox->addWidget(btn_clear);
  58. kexiDBDebugPage = new TDEListView(page, "kexiDbDebugPage");
  59. TQObject::connect(btn_clear, TQT_SIGNAL(clicked()), kexiDBDebugPage, TQT_SLOT(clear()));
  60. vbox->addWidget(kexiDBDebugPage);
  61. kexiDBDebugPage->addColumn("");
  62. kexiDBDebugPage->header()->hide();
  63. kexiDBDebugPage->setSorting(-1);
  64. kexiDBDebugPage->setAllColumnsShowFocus ( true );
  65. kexiDBDebugPage->setColumnWidthMode( 0, TQListView::Maximum );
  66. kexiDBDebugPage->setRootIsDecorated( true );
  67. debugWindowTab->addTab( page, "KexiDB" );
  68. debugWindowTab->showPage(page);
  69. kexiDBDebugPage->show();
  70. }
  71. //add \n after (about) every 30 characters
  72. //TODO TQString realText
  73. TDEListViewItem * li = new TDEListViewItem( kexiDBDebugPage, kexiDBDebugPage->lastItem(), text );
  74. li->setMultiLinesEnabled( true );
  75. }
  76. void KexiUtils::addAlterTableActionDebug(const TQString& text, int nestingLevel)
  77. {
  78. // (this is internal code - do not use i18n() here)
  79. if (!debugWindowTab)
  80. return;
  81. if (!kexiAlterTableActionDebugPage) {
  82. TQWidget *page = new TQWidget(debugWindowTab);
  83. TQVBoxLayout *vbox = new TQVBoxLayout(page);
  84. TQHBoxLayout *hbox = new TQHBoxLayout(page);
  85. vbox->addLayout(hbox);
  86. hbox->addStretch(1);
  87. KPushButton *btn_exec = new KPushButton(KGuiItem("Real Alter Table", "document-save"), page);
  88. btn_exec->setName("executeRealAlterTable");
  89. hbox->addWidget(btn_exec);
  90. KPushButton *btn_clear = new KPushButton(KGuiItem("Clear", "clear_left"), page);
  91. hbox->addWidget(btn_clear);
  92. KPushButton *btn_sim = new KPushButton(KGuiItem("Simulate Execution", "exec"), page);
  93. btn_sim->setName("simulateAlterTableExecution");
  94. hbox->addWidget(btn_sim);
  95. kexiAlterTableActionDebugPage = new TDEListView(page, "kexiAlterTableActionDebugPage");
  96. TQObject::connect(btn_clear, TQT_SIGNAL(clicked()), kexiAlterTableActionDebugPage, TQT_SLOT(clear()));
  97. vbox->addWidget(kexiAlterTableActionDebugPage);
  98. kexiAlterTableActionDebugPage->addColumn("");
  99. kexiAlterTableActionDebugPage->header()->hide();
  100. kexiAlterTableActionDebugPage->setSorting(-1);
  101. kexiAlterTableActionDebugPage->setAllColumnsShowFocus ( true );
  102. kexiAlterTableActionDebugPage->setColumnWidthMode( 0, TQListView::Maximum );
  103. kexiAlterTableActionDebugPage->setRootIsDecorated( true );
  104. debugWindowTab->addTab( page, "AlterTable Actions" );
  105. debugWindowTab->showPage(page);
  106. page->show();
  107. }
  108. if (text.isEmpty()) //don't move up!
  109. return;
  110. TDEListViewItem * li;
  111. int availableNestingLevels = 0;
  112. // compute availableNestingLevels
  113. TQListViewItem * lastItem = kexiAlterTableActionDebugPage->lastItem();
  114. //kdDebug() << "lastItem: " << (lastItem ? lastItem->text(0) : TQString()) << endl;
  115. while (lastItem) {
  116. lastItem = lastItem->parent();
  117. availableNestingLevels++;
  118. }
  119. //kdDebug() << "availableNestingLevels: " << availableNestingLevels << endl;
  120. //go up (availableNestingLevels-levelsToGoUp) levels
  121. lastItem = kexiAlterTableActionDebugPage->lastItem();
  122. int levelsToGoUp = availableNestingLevels - nestingLevel;
  123. while (levelsToGoUp > 0 && lastItem) {
  124. lastItem = lastItem->parent();
  125. levelsToGoUp--;
  126. }
  127. //kdDebug() << "lastItem2: " << (lastItem ? lastItem->text(0) : TQString()) << endl;
  128. if (lastItem) {
  129. TQListViewItem *after = lastItem->firstChild(); //find last child so we can insert a new item after it
  130. while (after && after->nextSibling())
  131. after = after->nextSibling();
  132. if (after)
  133. li = new TDEListViewItem( lastItem, after, text ); //child, after
  134. else
  135. li = new TDEListViewItem( lastItem, text ); //1st child
  136. }
  137. else {
  138. lastItem = kexiAlterTableActionDebugPage->lastItem();
  139. while (lastItem && lastItem->parent())
  140. lastItem = lastItem->parent();
  141. //kdDebug() << "lastItem2: " << (lastItem ? lastItem->text(0) : TQString()) << endl;
  142. li = new TDEListViewItem( kexiAlterTableActionDebugPage, lastItem, text ); //after
  143. }
  144. li->setOpen(true);
  145. li->setMultiLinesEnabled( true );
  146. }
  147. void KexiUtils::connectPushButtonActionForDebugWindow(const char* actionName,
  148. const TQObject *receiver, const char* slot)
  149. {
  150. if (debugWindow) {
  151. KPushButton* btn = findFirstChild<KPushButton>(debugWindow, "KPushButton", actionName);
  152. if (btn)
  153. TQObject::connect(btn, TQT_SIGNAL(clicked()), receiver, slot);
  154. }
  155. }
  156. #endif //KEXI_DEBUG_GUI