kexi
kexidatatableview.cpp
00001 /* This file is part of the KDE project 00002 Copyright (C) 2003 Lucijan Busch <lucijan@kde.org> 00003 Copyright (C) 2003 Joseph Wenninger <jowenn@kde.org> 00004 Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl> 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this program; see the file COPYING. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include <qtimer.h> 00023 #include <qapplication.h> 00024 00025 #include <kmessagebox.h> 00026 #include <klocale.h> 00027 #include <kdebug.h> 00028 #include <kaction.h> 00029 00030 #include <kexidb/connection.h> 00031 #include <kexidb/cursor.h> 00032 00033 #include "kexidatatableview.h" 00034 00035 00036 KexiDataTableView::KexiDataTableView(QWidget *parent, const char *name) 00037 : KexiTableView(0, parent, name) 00038 { 00039 init(); 00040 } 00041 00042 KexiDataTableView::KexiDataTableView(QWidget *parent, const char *name, KexiDB::Cursor *cursor) 00043 : KexiTableView(0, parent, name) 00044 { 00045 init(); 00046 setData(cursor); 00047 } 00048 00049 KexiDataTableView::~KexiDataTableView() 00050 { 00051 } 00052 00053 void 00054 KexiDataTableView::init() 00055 { 00056 m_cursor = 0; 00057 00058 // m_maxRecord = 0; 00059 // m_records = 0; 00060 // m_first = false; 00061 00062 // connect(this, SIGNAL(contentsMoving(int, int)), this, SLOT(slotMoving(int))); 00063 // connect(verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(slotMoving(int))); 00064 } 00065 00066 /*void KexiDataTableView::initActions(KActionCollection *col) 00067 { 00068 KexiTableView::initActions(col); 00069 new KAction(i18n("Filter"), "filter", 0, this, SLOT(filter()), col, "tablepart_filter"); 00070 }*/ 00071 00072 bool KexiDataTableView::setData(KexiDB::Cursor *cursor) 00073 { 00074 //js if (!m_first) 00075 //js clearColumns(); 00076 if (!cursor) { 00077 clearColumns(); 00078 m_cursor = 0; 00079 return true; 00080 } 00081 if (cursor!=m_cursor) { 00082 clearColumns(); 00083 } 00084 m_cursor = cursor; 00085 00086 if (!m_cursor->query()) { 00087 kdDebug() << "KexiDataTableView::setData(): WARNING: cursor should have query schema defined!\n--aborting setData()." << endl; 00088 m_cursor->debug(); 00089 clearColumns(); 00090 return false; 00091 } 00092 00093 if (m_cursor->fieldCount()<1) { 00094 clearColumns(); 00095 return true; 00096 } 00097 00098 if (!m_cursor->isOpened() && !m_cursor->open()) { 00099 kdDebug() << "KexiDataTableView::setData(): WARNING: cannot open cursor\n--aborting setData()." << endl; 00100 m_cursor->debug(); 00101 clearColumns(); 00102 return false; 00103 } 00104 00105 KexiTableViewData *tv_data = new KexiTableViewData(m_cursor); 00106 00107 QString caption = m_cursor->query()->caption(); 00108 if (caption.isEmpty()) 00109 caption = m_cursor->query()->name(); 00110 00111 setCaption( caption ); 00112 00113 //PRIMITIVE!! data setting: 00114 tv_data->preloadAllRows(); 00115 00116 KexiTableView::setData(tv_data); 00117 return true; 00118 } 00119 00120 #include "kexidatatableview.moc"