kexi

kexidataawareview.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 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 "kexidataawareview.h"
00021 
00022 #include <kexidataawareobjectiface.h>
00023 #include <utils/kexisharedactionclient.h>
00024 
00025 #include <qlayout.h>
00026 
00027 #include <kpopupmenu.h>
00028 
00029 KexiDataAwareView::KexiDataAwareView(KexiMainWindow *mainWin, QWidget *parent, const char *name)
00030  : KexiViewBase(mainWin, parent, name)
00031  , m_internalView(0)
00032  , m_actionClient(0)
00033  , m_dataAwareObject(0)
00034 {
00035 }
00036 
00037 void KexiDataAwareView::init( QWidget* viewWidget, KexiSharedActionClient* actionClient,
00038     KexiDataAwareObjectInterface* dataAwareObject, bool noDataAware )
00039 {
00040     m_internalView = viewWidget;
00041     m_actionClient = actionClient;
00042     m_dataAwareObject = dataAwareObject;
00043     setViewWidget(m_internalView, true);
00044 
00045     if (!noDataAware) {
00046         m_dataAwareObject->connectCellSelectedSignal(this, SLOT(slotCellSelected(int,int)));
00047 
00049         connect(this, SIGNAL(closing(bool&)), this, SLOT(slotClosing(bool&)));
00050 
00052         m_dataAwareObject->connectRowEditStartedSignal(this, SLOT(slotUpdateRowActions(int)));
00053         m_dataAwareObject->connectRowEditTerminatedSignal(this, SLOT(slotUpdateRowActions(int)));
00054         m_dataAwareObject->connectReloadActionsSignal(this, SLOT(reloadActions()));
00055     }
00056 
00057     QVBoxLayout *box = new QVBoxLayout(this);
00058     box->addWidget(m_internalView);
00059 
00060     setMinimumSize(m_internalView->minimumSizeHint().width(), 
00061         m_internalView->minimumSizeHint().height());
00062     resize( preferredSizeHint( m_internalView->sizeHint() ) );
00063     setFocusProxy(m_internalView);
00064     
00065     if (!noDataAware) {
00066         initActions();
00067         reloadActions();
00068     }
00069 }
00070 
00071 void KexiDataAwareView::initActions()
00072 {
00073     plugSharedAction("edit_delete_row", this, SLOT(deleteCurrentRow()));
00074     m_actionClient->plugSharedAction(sharedAction("edit_delete_row")); //for proper shortcut
00075 
00076     plugSharedAction("edit_delete", this, SLOT(deleteAndStartEditCurrentCell()));
00077     m_actionClient->plugSharedAction(sharedAction("edit_delete")); //for proper shortcut
00078 
00079     plugSharedAction("edit_edititem", this, SLOT(startEditOrToggleValue()));
00080     m_actionClient->plugSharedAction(sharedAction("edit_edititem")); //for proper shortcut
00081 
00082     plugSharedAction("data_save_row", this, SLOT(acceptRowEdit()));
00083     m_actionClient->plugSharedAction(sharedAction("data_save_row")); //for proper shortcut
00084 
00085     plugSharedAction("data_cancel_row_changes", this, SLOT(cancelRowEdit()));
00086     m_actionClient->plugSharedAction(sharedAction("data_cancel_row_changes")); //for proper shortcut
00087 
00088     if (m_dataAwareObject->isSortingEnabled()) {
00089         plugSharedAction("data_sort_az", this, SLOT(sortAscending()));
00090         plugSharedAction("data_sort_za", this, SLOT(sortDescending()));
00091     }
00092 
00093     m_actionClient->plugSharedAction(sharedAction("edit_insert_empty_row")); //for proper shortcut
00094 
00095     setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
00096     setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
00098 }
00099 
00100 void KexiDataAwareView::slotUpdateRowActions(int row)
00101 {
00102     const bool ro = m_dataAwareObject->isReadOnly();
00103     const bool inserting = m_dataAwareObject->isInsertingEnabled();
00104     const bool deleting = m_dataAwareObject->isDeleteEnabled();
00105     const bool emptyInserting = m_dataAwareObject->isEmptyRowInsertingEnabled();
00106     const bool editing = m_dataAwareObject->rowEditing();
00107     const bool sorting = m_dataAwareObject->isSortingEnabled();
00108     const int rows = m_dataAwareObject->rows();
00109 
00110     setAvailable("edit_delete", !ro && !(inserting && row==rows));
00111     setAvailable("edit_delete_row", !ro && !(deleting && row==rows));
00112     setAvailable("edit_insert_empty_row", !ro && emptyInserting);
00113     setAvailable("edit_clear_table", !ro && deleting && rows>0);
00114     setAvailable("data_save_row", editing);
00115     setAvailable("data_cancel_row_changes", editing);
00116     setAvailable("data_sort_az", sorting);
00117     setAvailable("data_sort_za", sorting);
00118 }
00119 
00120 QWidget* KexiDataAwareView::mainWidget() 
00121 {
00122     return m_internalView;
00123 }
00124 
00125 QSize KexiDataAwareView::minimumSizeHint() const
00126 {
00127     return m_internalView ? m_internalView->minimumSizeHint() : QSize(0,0);//KexiViewBase::minimumSizeHint();
00128 }
00129 
00130 QSize KexiDataAwareView::sizeHint() const
00131 {
00132     return m_internalView ? m_internalView->sizeHint() : QSize(0,0);//KexiViewBase::sizeHint();
00133 }
00134 
00135 void KexiDataAwareView::updateActions(bool activated)
00136 {
00137     setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
00138     setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
00139     KexiViewBase::updateActions(activated);
00140 }
00141 
00142 void KexiDataAwareView::reloadActions()
00143 {
00144 //  m_view->initActions(guiClient()->actionCollection());
00145 //warning FIXME Move this to the table part
00146 /*
00147     kdDebug()<<"INIT ACTIONS***********************************************************************"<<endl;
00148     new KAction(i18n("Filter"), "filter", 0, this, SLOT(filter()), actionCollection(), "tablepart_filter");
00149     setXMLFile("kexidatatableui.rc");
00150 */
00151     m_dataAwareObject->contextMenu()->clear();
00152 
00153     unplugSharedAction("edit_clear_table");
00154     plugSharedAction("edit_clear_table", this, SLOT(deleteAllRows()));
00155 
00156     if (m_dataAwareObject->isEmptyRowInsertingEnabled()) {
00157         unplugSharedAction("edit_insert_empty_row");
00158         plugSharedAction("edit_insert_empty_row", m_internalView, SLOT(insertEmptyRow()));
00159         plugSharedAction("edit_insert_empty_row", m_dataAwareObject->contextMenu());
00160     }
00161     else {
00162         unplugSharedAction("edit_insert_empty_row");
00163         unplugSharedAction("edit_insert_empty_row", m_dataAwareObject->contextMenu());
00164     }
00165 
00166     if (m_dataAwareObject->isDeleteEnabled())
00167         plugSharedAction("edit_delete_row", m_dataAwareObject->contextMenu());
00168     else
00169         unplugSharedAction("edit_delete_row", m_dataAwareObject->contextMenu());
00170 
00171     //if (!m_view->isSortingEnabled()) {
00172 //      unplugSharedAction("data_sort_az");
00173 //      unplugSharedAction("data_sort_za");
00174     //}
00175     setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
00176     setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
00177 
00178     slotCellSelected( m_dataAwareObject->currentColumn(), m_dataAwareObject->currentRow() );
00179 }
00180 
00181 /*void KexiDataAwareView::slotCellSelected(const QVariant& v)
00182 {
00183     slotCellSelected( v.toPoint().x(), v.toPoint().y() );
00184 }*/
00185 
00186 void KexiDataAwareView::slotCellSelected(int /*col*/, int row)
00187 {
00188     slotUpdateRowActions(row);
00189 }
00190 
00191 void KexiDataAwareView::deleteAllRows()
00192 {
00193     m_dataAwareObject->deleteAllRows(true/*ask*/, true/*repaint*/);
00194 }
00195 
00196 void KexiDataAwareView::deleteCurrentRow()
00197 {
00198     m_dataAwareObject->deleteCurrentRow();
00199 }
00200 
00201 void KexiDataAwareView::deleteAndStartEditCurrentCell()
00202 {
00203     m_dataAwareObject->deleteAndStartEditCurrentCell();
00204 }
00205 
00206 void KexiDataAwareView::startEditOrToggleValue()
00207 {
00208     m_dataAwareObject->startEditOrToggleValue();
00209 }
00210 
00211 bool KexiDataAwareView::acceptRowEdit()
00212 {
00213     return m_dataAwareObject->acceptRowEdit();
00214 }
00215 
00216 void KexiDataAwareView::slotClosing(bool& cancel)
00217 {
00218     if (!acceptRowEdit())
00219         cancel = true;
00220 }
00221 
00222 void KexiDataAwareView::cancelRowEdit()
00223 {
00224     m_dataAwareObject->cancelRowEdit();
00225 }
00226 
00227 void KexiDataAwareView::sortAscending()
00228 {
00229     m_dataAwareObject->sortAscending();
00230 }
00231 
00232 void KexiDataAwareView::sortDescending()
00233 {
00234     m_dataAwareObject->sortDescending();
00235 }
00236 
00237 #include "kexidataawareview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys