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     plugSharedAction("edit_copy", this, SLOT(copySelection()));
00100     m_actionClient->plugSharedAction(sharedAction("edit_copy")); //for proper shortcut
00101 
00102     plugSharedAction("edit_cut", this, SLOT(cutSelection()));
00103     m_actionClient->plugSharedAction(sharedAction("edit_cut")); //for proper shortcut
00104 
00105     plugSharedAction("edit_paste", this, SLOT(paste()));
00106     m_actionClient->plugSharedAction(sharedAction("edit_paste")); //for proper shortcut
00107 }
00108 
00109 void KexiDataAwareView::slotUpdateRowActions(int row)
00110 {
00111     const bool ro = m_dataAwareObject->isReadOnly();
00112 //  const bool inserting = m_dataAwareObject->isInsertingEnabled();
00113     const bool deleting = m_dataAwareObject->isDeleteEnabled();
00114     const bool emptyInserting = m_dataAwareObject->isEmptyRowInsertingEnabled();
00115     const bool editing = m_dataAwareObject->rowEditing();
00116     const bool sorting = m_dataAwareObject->isSortingEnabled();
00117     const int rows = m_dataAwareObject->rows();
00118 
00119     setAvailable("edit_delete", !ro); // && !(inserting && row==rows));
00120     setAvailable("edit_delete_row", !ro && !(deleting && row==rows));
00121     setAvailable("edit_insert_empty_row", !ro && emptyInserting);
00122     setAvailable("edit_clear_table", !ro && deleting && rows>0);
00123     setAvailable("data_save_row", editing);
00124     setAvailable("data_cancel_row_changes", editing);
00125     setAvailable("data_sort_az", sorting);
00126     setAvailable("data_sort_za", sorting);
00127 }
00128 
00129 QWidget* KexiDataAwareView::mainWidget() 
00130 {
00131     return m_internalView;
00132 }
00133 
00134 QSize KexiDataAwareView::minimumSizeHint() const
00135 {
00136     return m_internalView ? m_internalView->minimumSizeHint() : QSize(0,0);//KexiViewBase::minimumSizeHint();
00137 }
00138 
00139 QSize KexiDataAwareView::sizeHint() const
00140 {
00141     return m_internalView ? m_internalView->sizeHint() : QSize(0,0);//KexiViewBase::sizeHint();
00142 }
00143 
00144 void KexiDataAwareView::updateActions(bool activated)
00145 {
00146     setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
00147     setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
00148     KexiViewBase::updateActions(activated);
00149 }
00150 
00151 void KexiDataAwareView::reloadActions()
00152 {
00153 //  m_view->initActions(guiClient()->actionCollection());
00154 //warning FIXME Move this to the table part
00155 /*
00156     kdDebug()<<"INIT ACTIONS***********************************************************************"<<endl;
00157     new KAction(i18n("Filter"), "filter", 0, this, SLOT(filter()), actionCollection(), "tablepart_filter");
00158     setXMLFile("kexidatatableui.rc");
00159 */
00160     m_dataAwareObject->contextMenu()->clear();
00161 
00162     unplugSharedAction("edit_clear_table");
00163     plugSharedAction("edit_clear_table", this, SLOT(deleteAllRows()));
00164 
00165     if (m_dataAwareObject->isEmptyRowInsertingEnabled()) {
00166         unplugSharedAction("edit_insert_empty_row");
00167         plugSharedAction("edit_insert_empty_row", m_internalView, SLOT(insertEmptyRow()));
00168         plugSharedAction("edit_insert_empty_row", m_dataAwareObject->contextMenu());
00169     }
00170     else {
00171         unplugSharedAction("edit_insert_empty_row");
00172         unplugSharedAction("edit_insert_empty_row", m_dataAwareObject->contextMenu());
00173     }
00174 
00175     if (m_dataAwareObject->isDeleteEnabled())
00176         plugSharedAction("edit_delete_row", m_dataAwareObject->contextMenu());
00177     else
00178         unplugSharedAction("edit_delete_row", m_dataAwareObject->contextMenu());
00179 
00180     //if (!m_view->isSortingEnabled()) {
00181 //      unplugSharedAction("data_sort_az");
00182 //      unplugSharedAction("data_sort_za");
00183     //}
00184     setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
00185     setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
00186 
00187     slotCellSelected( m_dataAwareObject->currentColumn(), m_dataAwareObject->currentRow() );
00188 }
00189 
00190 /*void KexiDataAwareView::slotCellSelected(const QVariant& v)
00191 {
00192     slotCellSelected( v.toPoint().x(), v.toPoint().y() );
00193 }*/
00194 
00195 void KexiDataAwareView::slotCellSelected(int /*col*/, int row)
00196 {
00197     slotUpdateRowActions(row);
00198 }
00199 
00200 void KexiDataAwareView::deleteAllRows()
00201 {
00202     m_dataAwareObject->deleteAllRows(true/*ask*/, true/*repaint*/);
00203 }
00204 
00205 void KexiDataAwareView::deleteCurrentRow()
00206 {
00207     m_dataAwareObject->deleteCurrentRow();
00208 }
00209 
00210 void KexiDataAwareView::deleteAndStartEditCurrentCell()
00211 {
00212     m_dataAwareObject->deleteAndStartEditCurrentCell();
00213 }
00214 
00215 void KexiDataAwareView::startEditOrToggleValue()
00216 {
00217     m_dataAwareObject->startEditOrToggleValue();
00218 }
00219 
00220 bool KexiDataAwareView::acceptRowEdit()
00221 {
00222     return m_dataAwareObject->acceptRowEdit();
00223 }
00224 
00225 void KexiDataAwareView::slotClosing(bool& cancel)
00226 {
00227     if (!acceptRowEdit())
00228         cancel = true;
00229 }
00230 
00231 void KexiDataAwareView::cancelRowEdit()
00232 {
00233     m_dataAwareObject->cancelRowEdit();
00234 }
00235 
00236 void KexiDataAwareView::sortAscending()
00237 {
00238     m_dataAwareObject->sortAscending();
00239 }
00240 
00241 void KexiDataAwareView::sortDescending()
00242 {
00243     m_dataAwareObject->sortDescending();
00244 }
00245 
00246 void KexiDataAwareView::copySelection()
00247 {
00248     m_dataAwareObject->copySelection();
00249 }
00250 
00251 void KexiDataAwareView::cutSelection()
00252 {
00253     m_dataAwareObject->cutSelection();
00254 }
00255 
00256 void KexiDataAwareView::paste()
00257 {
00258     m_dataAwareObject->paste();
00259 }
00260 
00261 #include "kexidataawareview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys