kexi

kexidatatable.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-2005 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 
00023 #include <qlayout.h>
00024 #include <qlabel.h>
00025 
00026 #include <kiconloader.h>
00027 #include <klocale.h>
00028 #include <kaction.h>
00029 #include <kpopupmenu.h>
00030 
00031 #include <kexidb/cursor.h>
00032 
00033 #include "kexidatatableview.h"
00034 #include "kexidatatable.h"
00035 #include "kexidialogbase.h"
00036 
00037 KexiDataTable::KexiDataTable(KexiMainWindow *mainWin, QWidget *parent, 
00038     const char *name, bool dbAware)
00039 // : KexiViewBase(mainWin, parent, name)
00040  : KexiDataAwareView( mainWin, parent, name )
00041 {
00042     KexiTableView *view;
00043     if (dbAware)
00044         view = new KexiDataTableView(this, 
00045             QString("%1_datatableview").arg(name ? name : "KexiDataTableView").latin1());
00046     else
00047         view = new KexiTableView(0, this, 
00048             QString("%1_tableview").arg(name ? name : "KexiTableView").latin1());
00049 
00050     KexiDataAwareView::init( view, view, view );
00051 //  init();
00052 }
00053 
00054 //KexiDataTable::KexiDataTable(KexiMainWindow *win, KexiDB::Cursor *cursor, 
00055 //  const QString &caption)
00056 KexiDataTable::KexiDataTable(KexiMainWindow *mainWin, QWidget *parent, 
00057     KexiDB::Cursor *cursor, const char *name)
00058  : KexiDataAwareView( mainWin, parent, name )
00059 // : KexiViewBase(mainWin, parent, name)
00060 // , m_view(0)
00061 {
00062 //  m_view = new KexiDataTableView(this, "view", cursor);
00063     KexiTableView *view = new KexiDataTableView(this, "view", cursor);
00064     KexiDataAwareView::init( view, view, view );
00065 //  init();
00066 }
00067 
00068 KexiDataTable::~KexiDataTable()
00069 {
00070 }
00071 
00072 #if 0 //moved
00073 
00074 void KexiDataTable::init()
00075 {
00076     connect(m_view, SIGNAL(cellSelected(int,int)), this, SLOT(slotCellSelected(int,int)));
00078     connect(this,SIGNAL(closing()),m_view,SLOT(acceptRowEdit()));
00079 
00081     connect(m_view, SIGNAL(rowEditStarted(int)), this, SLOT(slotUpdateRowActions(int)));
00082     connect(m_view, SIGNAL(rowEditTerminated(int)), this, SLOT(slotUpdateRowActions(int)));
00083     connect(m_view, SIGNAL(reloadActions()), this, SLOT(reloadActions()));
00084 
00085     QVBoxLayout *box = new QVBoxLayout(this);
00086     box->addWidget(m_view);
00087 
00088     //resize to preferred size
00089 /*  QSize preferredSize = m_view->sizeHint();
00090     KexiDialogBase* dlg = parentDialog();
00091     if (dlg && dlg->mdiParent()) {
00092         QRect r = dlg->mdiParent()->mdiAreaContentsRect();
00093         preferredSize = preferredSize.boundedTo( QSize(
00094             r.width() - 10,
00095             r.height() - dlg->mdiParent()->captionHeight() - 10
00096         ) );
00097     }*/
00098 
00099     setMinimumSize(m_view->minimumSizeHint().width(),m_view->minimumSizeHint().height());
00100     resize( preferredSizeHint( m_view->sizeHint() ) );
00101 //js    m_view->show();
00102     setFocusProxy(m_view);
00103 //  m_view->setFocus();
00104 //not needed    setIcon(SmallIcon("table"));
00105     
00106     initActions();
00107 //js already done in keximainwindow:    registerDialog();
00108     reloadActions();
00109 }
00110 
00111 void
00112 KexiDataTable::initActions()
00113 {
00114     plugSharedAction("edit_delete_row", m_view, SLOT(deleteCurrentRow()));
00115     m_view->plugSharedAction(sharedAction("edit_delete_row")); //for proper shortcut
00116 
00117     plugSharedAction("edit_delete",m_view, SLOT(deleteAndStartEditCurrentCell()));
00118     m_view->plugSharedAction(sharedAction("edit_delete")); //for proper shortcut
00119 
00120     plugSharedAction("edit_edititem",m_view, SLOT(startEditOrToggleValue()));
00121     m_view->plugSharedAction(sharedAction("edit_edititem")); //for proper shortcut
00122 
00123     plugSharedAction("data_save_row",m_view, SLOT(acceptRowEdit()));
00124     m_view->plugSharedAction(sharedAction("data_save_row")); //for proper shortcut
00125 
00126     plugSharedAction("data_cancel_row_changes",m_view, SLOT(cancelRowEdit()));
00127     m_view->plugSharedAction(sharedAction("data_cancel_row_changes")); //for proper shortcut
00128 
00129     if (m_view->isSortingEnabled()) {
00130         plugSharedAction("data_sort_az", m_view, SLOT(sortAscending()));
00131         plugSharedAction("data_sort_za", m_view, SLOT(sortDescending()));
00132     }
00133 
00134     m_view->plugSharedAction(sharedAction("edit_insert_empty_row")); //for proper shortcut
00135 
00136     setAvailable("data_sort_az", m_view->isSortingEnabled());
00137     setAvailable("data_sort_za", m_view->isSortingEnabled());
00139 }
00140 
00141 void KexiDataTable::reloadActions()
00142 {
00143 //  m_view->initActions(guiClient()->actionCollection());
00144 //warning FIXME Move this to the table part
00145 /*
00146     kdDebug()<<"INIT ACTIONS***********************************************************************"<<endl;
00147     new KAction(i18n("Filter"), "filter", 0, this, SLOT(filter()), actionCollection(), "tablepart_filter");
00148     setXMLFile("kexidatatableui.rc");
00149 */
00150     m_view->popup()->clear();
00151 
00152     unplugSharedAction("edit_clear_table");
00153     plugSharedAction("edit_clear_table", this, SLOT(deleteAllRows()));
00154 
00155     if (m_view->isEmptyRowInsertingEnabled()) {
00156         unplugSharedAction("edit_insert_empty_row");
00157         plugSharedAction("edit_insert_empty_row", m_view, SLOT(insertEmptyRow()));
00158         plugSharedAction("edit_insert_empty_row", m_view->popup());
00159     }
00160     else {
00161         unplugSharedAction("edit_insert_empty_row");
00162         unplugSharedAction("edit_insert_empty_row", m_view->popup());
00163     }
00164 
00165     if (m_view->isDeleteEnabled())
00166         plugSharedAction("edit_delete_row", m_view->popup());
00167     else
00168         unplugSharedAction("edit_delete_row", m_view->popup());
00169 
00170     //if (!m_view->isSortingEnabled()) {
00171 //      unplugSharedAction("data_sort_az");
00172 //      unplugSharedAction("data_sort_za");
00173     //}
00174     setAvailable("data_sort_az", m_view->isSortingEnabled());
00175     setAvailable("data_sort_za", m_view->isSortingEnabled());
00176 
00177     slotCellSelected( m_view->currentColumn(), m_view->currentRow() );
00178 }
00179 #endif
00180 
00181 /*moved
00182 void
00183 KexiDataTable::updateActions(bool activated)
00184 {
00185     setAvailable("data_sort_az", m_view->isSortingEnabled());
00186     setAvailable("data_sort_za", m_view->isSortingEnabled());
00187     KexiViewBase::updateActions(activated);
00188 }*/
00189 
00190 void
00191 KexiDataTable::setData(KexiDB::Cursor *c)
00192 {
00193     if (!dynamic_cast<KexiDataTableView*>(mainWidget()))
00194         return;
00195     dynamic_cast<KexiDataTableView*>(mainWidget())->setData(c);
00196 }
00197 
00198 void KexiDataTable::filter()
00199 {
00200 }
00201 
00202 /*moved
00203 QSize KexiDataTable::minimumSizeHint() const
00204 {
00205 //  QWidget*const w= (QWidget*const)mainWidget();
00206     return m_view ? m_view->minimumSizeHint() : KexiViewBase::minimumSizeHint();
00207 //  return mainWidget() ? mainWidget()->minimumSizeHint() : KMdiChildView::minimumSizeHint();
00208 }
00209 
00210 QSize KexiDataTable::sizeHint() const
00211 {
00212     return m_view ? m_view->sizeHint() : KexiViewBase::sizeHint();
00213 }
00214 */
00215 
00216 // update actions --------------
00217 #if 0
00218 void KexiDataTable::slotCellSelected(int /*col*/, int row)
00219 {
00220     slotUpdateRowActions(row);
00221 }
00222 
00223 void KexiDataTable::deleteAllRows()
00224 {
00225     m_view->deleteAllRows(true/*ask*/, true/*repaint*/);
00226 }
00227 
00228 #endif
00229 
00230 /*moved
00231 void KexiDataTable::slotUpdateRowActions(int row)
00232 {
00233     setAvailable("edit_delete", !m_view->isReadOnly() && !(m_view->isInsertingEnabled() && row==m_view->rows()));
00234     setAvailable("edit_delete_row", !m_view->isReadOnly() && !(m_view->isDeleteEnabled() && row==m_view->rows()) );
00235     setAvailable("edit_insert_empty_row", !m_view->isReadOnly() && m_view->isEmptyRowInsertingEnabled());
00236     setAvailable("edit_clear_table", !m_view->isReadOnly() && m_view->isDeleteEnabled() && m_view->rows()>0);
00237     setAvailable("data_save_row", m_view->rowEditing());
00238     setAvailable("data_cancel_row_changes", m_view->rowEditing());
00239     setAvailable("data_sort_az", m_view->isSortingEnabled());
00240     setAvailable("data_sort_za", m_view->isSortingEnabled());
00241 }*.
00242 */
00243 
00244 KexiTableView* KexiDataTable::tableView() const
00245 {
00246     return dynamic_cast<KexiTableView*>(m_internalView);
00247 }
00248 
00249 #include "kexidatatable.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys