kexi

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