kexi

kexidataawareview.cpp

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