kexi

debuggui.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "utils.h"
00021 #include "utils_p.h"
00022 
00023 #include <qheader.h>
00024 #include <qlayout.h>
00025 
00026 #include <ktabwidget.h>
00027 #include <klistview.h>
00028 #include <kiconloader.h>
00029 #include <kdialogbase.h>
00030 #include <kpushbutton.h>
00031 #include <kguiitem.h>
00032 
00033 #ifdef KEXI_DEBUG_GUI
00034 
00035 static DebugWindowDialog* debugWindow = 0;
00036 static KTabWidget* debugWindowTab = 0;
00037 static KListView* kexiDBDebugPage = 0;
00038 static KListView* kexiAlterTableActionDebugPage = 0;
00039 
00040 QWidget *KexiUtils::createDebugWindow(QWidget *parent)
00041 {
00042     // (this is internal code - do not use i18n() here)
00043     debugWindow = new DebugWindowDialog(parent);
00044     debugWindow->setSizeGripEnabled( true );
00045     QBoxLayout *lyr = new QVBoxLayout(debugWindow, KDialogBase::marginHint());
00046     debugWindowTab = new KTabWidget(debugWindow, "debugWindowTab");
00047     lyr->addWidget( debugWindowTab );
00048     debugWindow->resize(900, 600);
00049     debugWindow->setIcon( DesktopIcon("info") );
00050     debugWindow->setCaption("Kexi Internal Debugger");
00051     debugWindow->show();
00052     return debugWindow;
00053 }
00054 
00055 void KexiUtils::addKexiDBDebug(const QString& text)
00056 {
00057     // (this is internal code - do not use i18n() here)
00058     if (!debugWindowTab)
00059         return;
00060     if (!kexiDBDebugPage) {
00061         QWidget *page = new QWidget(debugWindowTab);
00062         QVBoxLayout *vbox = new QVBoxLayout(page);
00063         QHBoxLayout *hbox = new QHBoxLayout(page);
00064         vbox->addLayout(hbox);
00065         hbox->addStretch(1);
00066         KPushButton *btn_clear = new KPushButton(KGuiItem("Clear", "clear_left"), page);
00067         hbox->addWidget(btn_clear);
00068 
00069         kexiDBDebugPage = new KListView(page, "kexiDbDebugPage");
00070         QObject::connect(btn_clear, SIGNAL(clicked()), kexiDBDebugPage, SLOT(clear()));
00071         vbox->addWidget(kexiDBDebugPage);
00072         kexiDBDebugPage->addColumn("");
00073         kexiDBDebugPage->header()->hide();
00074         kexiDBDebugPage->setSorting(-1);
00075         kexiDBDebugPage->setAllColumnsShowFocus ( true );
00076         kexiDBDebugPage->setColumnWidthMode( 0, QListView::Maximum );
00077         kexiDBDebugPage->setRootIsDecorated( true );
00078         debugWindowTab->addTab( page, "KexiDB" );
00079         debugWindowTab->showPage(page);
00080         kexiDBDebugPage->show();
00081     }
00082     //add \n after (about) every 30 characters
00083 //TODO  QString realText
00084 
00085     KListViewItem * li = new KListViewItem( kexiDBDebugPage, kexiDBDebugPage->lastItem(), text );
00086     li->setMultiLinesEnabled( true );
00087 }
00088 
00089 void KexiUtils::addAlterTableActionDebug(const QString& text, int nestingLevel)
00090 {
00091     // (this is internal code - do not use i18n() here)
00092     if (!debugWindowTab)
00093         return;
00094     if (!kexiAlterTableActionDebugPage) {
00095         QWidget *page = new QWidget(debugWindowTab);
00096         QVBoxLayout *vbox = new QVBoxLayout(page);
00097         QHBoxLayout *hbox = new QHBoxLayout(page);
00098         vbox->addLayout(hbox);
00099         hbox->addStretch(1);
00100         KPushButton *btn_exec = new KPushButton(KGuiItem("Real Alter Table", "filesave"), page);
00101         btn_exec->setName("executeRealAlterTable");
00102         hbox->addWidget(btn_exec);
00103         KPushButton *btn_clear = new KPushButton(KGuiItem("Clear", "clear_left"), page);
00104         hbox->addWidget(btn_clear);
00105         KPushButton *btn_sim = new KPushButton(KGuiItem("Simulate Execution", "exec"), page);
00106         btn_sim->setName("simulateAlterTableExecution");
00107         hbox->addWidget(btn_sim);
00108 
00109         kexiAlterTableActionDebugPage = new KListView(page, "kexiAlterTableActionDebugPage");
00110         QObject::connect(btn_clear, SIGNAL(clicked()), kexiAlterTableActionDebugPage, SLOT(clear()));
00111         vbox->addWidget(kexiAlterTableActionDebugPage);
00112         kexiAlterTableActionDebugPage->addColumn("");
00113         kexiAlterTableActionDebugPage->header()->hide();
00114         kexiAlterTableActionDebugPage->setSorting(-1);
00115         kexiAlterTableActionDebugPage->setAllColumnsShowFocus ( true );
00116         kexiAlterTableActionDebugPage->setColumnWidthMode( 0, QListView::Maximum );
00117         kexiAlterTableActionDebugPage->setRootIsDecorated( true );
00118         debugWindowTab->addTab( page, "AlterTable Actions" );
00119         debugWindowTab->showPage(page);
00120         page->show();
00121     }
00122     if (text.isEmpty()) //don't move up!
00123         return;
00124     KListViewItem * li;
00125     int availableNestingLevels = 0;
00126     // compute availableNestingLevels
00127     QListViewItem * lastItem = kexiAlterTableActionDebugPage->lastItem();
00128     //kdDebug() << "lastItem: " << (lastItem ? lastItem->text(0) : QString::null) << endl;
00129     while (lastItem) {
00130         lastItem = lastItem->parent();
00131         availableNestingLevels++;
00132     }
00133     //kdDebug() << "availableNestingLevels: " << availableNestingLevels << endl;
00134     //go up (availableNestingLevels-levelsToGoUp) levels
00135     lastItem = kexiAlterTableActionDebugPage->lastItem();
00136     int levelsToGoUp = availableNestingLevels - nestingLevel;
00137     while (levelsToGoUp > 0 && lastItem) {
00138         lastItem = lastItem->parent();
00139         levelsToGoUp--;
00140     }
00141     //kdDebug() << "lastItem2: " << (lastItem ? lastItem->text(0) : QString::null) << endl;
00142     if (lastItem) {
00143         QListViewItem *after = lastItem->firstChild(); //find last child so we can insert a new item after it
00144         while (after && after->nextSibling())
00145             after = after->nextSibling();
00146         if (after)
00147             li = new KListViewItem( lastItem, after, text ); //child, after
00148         else
00149             li = new KListViewItem( lastItem, text ); //1st child
00150     }
00151     else {
00152         lastItem = kexiAlterTableActionDebugPage->lastItem();
00153         while (lastItem && lastItem->parent())
00154             lastItem = lastItem->parent();
00155         //kdDebug() << "lastItem2: " << (lastItem ? lastItem->text(0) : QString::null) << endl;
00156         li = new KListViewItem( kexiAlterTableActionDebugPage, lastItem, text ); //after
00157     }
00158     li->setOpen(true);
00159     li->setMultiLinesEnabled( true );
00160 }
00161 
00162 void KexiUtils::connectPushButtonActionForDebugWindow(const char* actionName, 
00163     const QObject *receiver, const char* slot)
00164 {
00165     if (debugWindow) {
00166         KPushButton* btn = findFirstChild<KPushButton>(debugWindow, "KPushButton", actionName);
00167         if (btn)
00168             QObject::connect(btn, SIGNAL(clicked()), receiver, slot);
00169     }
00170 }
00171 
00172 #endif //KEXI_DEBUG_GUI
KDE Home | KDE Accessibility Home | Description of Access Keys