kexi

kexidataawareview.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005-2007 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexidataawareview.h"
21
22#include <kexidataawareobjectiface.h>
23#include <utils/kexisharedactionclient.h>
24#include <core/keximainwindow.h>
25
26#include <tqlayout.h>
27
28#include <tdepopupmenu.h>
29
30KexiDataAwareView::KexiDataAwareView(KexiMainWindow *mainWin, TQWidget *parent, const char *name)
31 : KexiViewBase(mainWin, parent, name)
33 , m_internalView(0)
34 , m_actionClient(0)
35 , m_dataAwareObject(0)
36{
37}
38
39void KexiDataAwareView::init( TQWidget* viewWidget, KexiSharedActionClient* actionClient,
40 KexiDataAwareObjectInterface* dataAwareObject, bool noDataAware )
41{
42 m_internalView = viewWidget;
43 m_actionClient = actionClient;
44 m_dataAwareObject = dataAwareObject;
45 setViewWidget(m_internalView, true);
46
47 if (!noDataAware) {
48 m_dataAwareObject->connectCellSelectedSignal(this, TQ_SLOT(slotCellSelected(int,int)));
49
51 connect(this, TQ_SIGNAL(closing(bool&)), this, TQ_SLOT(slotClosing(bool&)));
52
54 m_dataAwareObject->connectRowEditStartedSignal(this, TQ_SLOT(slotUpdateRowActions(int)));
55 m_dataAwareObject->connectRowEditTerminatedSignal(this, TQ_SLOT(slotUpdateRowActions(int)));
56 m_dataAwareObject->connectReloadActionsSignal(this, TQ_SLOT(reloadActions()));
57 }
58
59 TQVBoxLayout *box = new TQVBoxLayout(this);
60 box->addWidget(m_internalView);
61
62 setMinimumSize(m_internalView->minimumSizeHint().width(),
63 m_internalView->minimumSizeHint().height());
64 resize( preferredSizeHint( m_internalView->sizeHint() ) );
65 setFocusProxy(m_internalView);
66
67 if (!noDataAware) {
69 reloadActions();
70 }
71}
72
74{
75 plugSharedAction("edit_delete_row", this, TQ_SLOT(deleteCurrentRow()));
76 m_actionClient->plugSharedAction(sharedAction("edit_delete_row")); //for proper shortcut
77
78 plugSharedAction("edit_delete", this, TQ_SLOT(deleteAndStartEditCurrentCell()));
79 m_actionClient->plugSharedAction(sharedAction("edit_delete")); //for proper shortcut
80
81 plugSharedAction("edit_edititem", this, TQ_SLOT(startEditOrToggleValue()));
82 m_actionClient->plugSharedAction(sharedAction("edit_edititem")); //for proper shortcut
83
84 plugSharedAction("data_save_row", this, TQ_SLOT(acceptRowEdit()));
85 m_actionClient->plugSharedAction(sharedAction("data_save_row")); //for proper shortcut
86
87 plugSharedAction("data_cancel_row_changes", this, TQ_SLOT(cancelRowEdit()));
88 m_actionClient->plugSharedAction(sharedAction("data_cancel_row_changes")); //for proper shortcut
89
90 if (m_dataAwareObject->isSortingEnabled()) {
91 plugSharedAction("data_sort_az", this, TQ_SLOT(sortAscending()));
92 plugSharedAction("data_sort_za", this, TQ_SLOT(sortDescending()));
93 }
94
95 m_actionClient->plugSharedAction(sharedAction("edit_insert_empty_row")); //for proper shortcut
96
97 setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
98 setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
100
101 plugSharedAction("data_go_to_first_record", this, TQ_SLOT(slotGoToFirstRow()));
102 plugSharedAction("data_go_to_previous_record", this, TQ_SLOT(slotGoToPreviusRow()));
103 plugSharedAction("data_go_to_next_record", this, TQ_SLOT(slotGoToNextRow()));
104 plugSharedAction("data_go_to_last_record", this, TQ_SLOT(slotGoToLastRow()));
105 plugSharedAction("data_go_to_new_record", this, TQ_SLOT(slotGoToNewRow()));
106
108 setAvailable("data_go_to_first_record", true);
109 setAvailable("data_go_to_previous_record", true);
110 setAvailable("data_go_to_next_record", true);
111 setAvailable("data_go_to_last_record", true);
112 setAvailable("data_go_to_new_record", true);
113
114 plugSharedAction("edit_copy", this, TQ_SLOT(copySelection()));
115 m_actionClient->plugSharedAction(sharedAction("edit_copy")); //for proper shortcut
116
117 plugSharedAction("edit_cut", this, TQ_SLOT(cutSelection()));
118 m_actionClient->plugSharedAction(sharedAction("edit_cut")); //for proper shortcut
119
120 plugSharedAction("edit_paste", this, TQ_SLOT(paste()));
121 m_actionClient->plugSharedAction(sharedAction("edit_paste")); //for proper shortcut
122
123// plugSharedAction("edit_find", this, TQ_SLOT(editFind()));
124// m_actionClient->plugSharedAction(sharedAction("edit_find")); //for proper shortcut
125
126// plugSharedAction("edit_findnext", this, TQ_SLOT(editFindNext()));
127// m_actionClient->plugSharedAction(sharedAction("edit_findnext")); //for proper shortcut
128
129// plugSharedAction("edit_findprevious", this, TQ_SLOT(editFindPrevious()));
130// m_actionClient->plugSharedAction(sharedAction("edit_findprev")); //for proper shortcut
131
134
135// setAvailable("edit_find", true);
136// setAvailable("edit_findnext", true);
137// setAvailable("edit_findprevious", true);
139}
140
141void KexiDataAwareView::slotUpdateRowActions(int row)
142{
143 const bool ro = m_dataAwareObject->isReadOnly();
144// const bool inserting = m_dataAwareObject->isInsertingEnabled();
145 const bool deleting = m_dataAwareObject->isDeleteEnabled();
146 const bool emptyInserting = m_dataAwareObject->isEmptyRowInsertingEnabled();
147 const bool editing = m_dataAwareObject->rowEditing();
148 const bool sorting = m_dataAwareObject->isSortingEnabled();
149 const int rows = m_dataAwareObject->rows();
150
151 setAvailable("edit_cut", !ro);
152 setAvailable("edit_paste", !ro);
153 setAvailable("edit_delete", !ro); // && !(inserting && row==rows));
154 setAvailable("edit_delete_row", !ro && !(deleting && row==rows));
155 setAvailable("edit_insert_empty_row", !ro && emptyInserting);
156 setAvailable("edit_clear_table", !ro && deleting && rows>0);
157 setAvailable("data_save_row", editing);
158 setAvailable("data_cancel_row_changes", editing);
159 setAvailable("data_sort_az", sorting);
160 setAvailable("data_sort_za", sorting);
161}
162
163TQWidget* KexiDataAwareView::mainWidget()
164{
165 return m_internalView;
166}
167
168TQSize KexiDataAwareView::minimumSizeHint() const
169{
170 return m_internalView ? m_internalView->minimumSizeHint() : TQSize(0,0);//KexiViewBase::minimumSizeHint();
171}
172
173TQSize KexiDataAwareView::sizeHint() const
174{
175 return m_internalView ? m_internalView->sizeHint() : TQSize(0,0);//KexiViewBase::sizeHint();
176}
177
179{
180 setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
181 setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
183}
184
185void KexiDataAwareView::reloadActions()
186{
187// m_view->initActions(guiClient()->actionCollection());
188//warning FIXME Move this to the table part
189/*
190 kdDebug()<<"INIT ACTIONS***********************************************************************"<<endl;
191 new TDEAction(i18n("Filter"), "filter", 0, this, TQ_SLOT(filter()), actionCollection(), "tablepart_filter");
192 setXMLFile("kexidatatableui.rc");
193*/
194 m_dataAwareObject->contextMenu()->clear();
195
196 plugSharedAction("edit_cut", m_dataAwareObject->contextMenu());
197 plugSharedAction("edit_copy", m_dataAwareObject->contextMenu());
198 plugSharedAction("edit_paste", m_dataAwareObject->contextMenu());
199
200 bool separatorNeeded = true;
201
202 unplugSharedAction("edit_clear_table");
203 plugSharedAction("edit_clear_table", this, TQ_SLOT(deleteAllRows()));
204
205 if (m_dataAwareObject->isEmptyRowInsertingEnabled()) {
206 unplugSharedAction("edit_insert_empty_row");
207 plugSharedAction("edit_insert_empty_row", m_internalView, TQ_SLOT(insertEmptyRow()));
208 if (separatorNeeded)
209 m_dataAwareObject->contextMenu()->insertSeparator();
210 plugSharedAction("edit_insert_empty_row", m_dataAwareObject->contextMenu());
211 }
212 else {
213 unplugSharedAction("edit_insert_empty_row");
214 unplugSharedAction("edit_insert_empty_row", m_dataAwareObject->contextMenu());
215 }
216
217 if (m_dataAwareObject->isDeleteEnabled()) {
218 if (separatorNeeded)
219 m_dataAwareObject->contextMenu()->insertSeparator();
220 plugSharedAction("edit_delete", m_dataAwareObject->contextMenu());
221 plugSharedAction("edit_delete_row", m_dataAwareObject->contextMenu());
222 }
223 else {
224 unplugSharedAction("edit_delete_row", m_dataAwareObject->contextMenu());
225 unplugSharedAction("edit_delete_row", m_dataAwareObject->contextMenu());
226 }
227 //if (!m_view->isSortingEnabled()) {
228// unplugSharedAction("data_sort_az");
229// unplugSharedAction("data_sort_za");
230 //}
231 setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
232 setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
233
234 slotCellSelected( m_dataAwareObject->currentColumn(), m_dataAwareObject->currentRow() );
235}
236
237void KexiDataAwareView::slotCellSelected(int /*col*/, int row)
238{
239 slotUpdateRowActions(row);
240}
241
242void KexiDataAwareView::deleteAllRows()
243{
244 m_dataAwareObject->deleteAllRows(true/*ask*/, true/*repaint*/);
245}
246
247void KexiDataAwareView::deleteCurrentRow()
248{
249 m_dataAwareObject->deleteCurrentRow();
250}
251
252void KexiDataAwareView::deleteAndStartEditCurrentCell()
253{
254 m_dataAwareObject->deleteAndStartEditCurrentCell();
255}
256
257void KexiDataAwareView::startEditOrToggleValue()
258{
259 m_dataAwareObject->startEditOrToggleValue();
260}
261
262bool KexiDataAwareView::acceptRowEdit()
263{
264 return m_dataAwareObject->acceptRowEdit();
265}
266
267void KexiDataAwareView::slotClosing(bool& cancel)
268{
269 if (!acceptRowEdit())
270 cancel = true;
271}
272
273void KexiDataAwareView::cancelRowEdit()
274{
275 m_dataAwareObject->cancelRowEdit();
276}
277
278void KexiDataAwareView::sortAscending()
279{
280 m_dataAwareObject->sortAscending();
281}
282
283void KexiDataAwareView::sortDescending()
284{
285 m_dataAwareObject->sortDescending();
286}
287
288void KexiDataAwareView::copySelection()
289{
290 m_dataAwareObject->copySelection();
291}
292
293void KexiDataAwareView::cutSelection()
294{
295 m_dataAwareObject->cutSelection();
296}
297
298void KexiDataAwareView::paste()
299{
300 m_dataAwareObject->paste();
301}
302
303void KexiDataAwareView::slotGoToFirstRow() { m_dataAwareObject->selectFirstRow(); }
304void KexiDataAwareView::slotGoToPreviusRow() { m_dataAwareObject->selectPrevRow(); }
305void KexiDataAwareView::slotGoToNextRow() { m_dataAwareObject->selectNextRow(); }
306void KexiDataAwareView::slotGoToLastRow() { m_dataAwareObject->selectLastRow(); }
307void KexiDataAwareView::slotGoToNewRow() { m_dataAwareObject->addNewRecordRequested(); }
308
309bool KexiDataAwareView::setupFindAndReplace(TQStringList& columnNames, TQStringList& columnCaptions,
310 TQString& currentColumnName)
311{
312 if (!dataAwareObject() || !dataAwareObject()->data())
313 return false;
314 KexiTableViewColumn::List columns( dataAwareObject()->data()->columns );
315 for (KexiTableViewColumn::ListIterator it(columns); it.current(); ++it) {
316 if (!it.current()->visible())
317 continue;
318 columnNames.append( it.current()->field()->name() );
319 columnCaptions.append( it.current()->captionAliasOrName() );
320 }
321
322 //update "look in" selection if there was any
323 const int currentColumnNumber = dataAwareObject()->currentColumn();
324 if (currentColumnNumber!=-1) {
325 KexiTableViewColumn *col = columns.at( currentColumnNumber );
326 if (col && col->field())
327 currentColumnName = col->field()->name();
328 }
329 return true;
330}
331
332tristate KexiDataAwareView::find(const TQVariant& valueToFind,
333 const KexiSearchAndReplaceViewInterface::Options& options, bool next)
334{
335 if (!dataAwareObject() || !dataAwareObject()->data())
336 return cancelled;
337
338// const KexiDataAwareObjectInterface::FindAndReplaceOptions options(dlg->options());
339/* if (res == KexiFindDialog::Find) {*/
340// TQVariant valueToFind(dlg->valueToFind());
341 return dataAwareObject()->find( valueToFind, options, next );
342/*
344
345 }
346 else if (res == KexiFindDialog::Replace) {
348 }
349 else if (res == KexiFindDialog::ReplaceAll) {
351 }
352 */
353}
354
356 const TQVariant& replacement,
357 const KexiSearchAndReplaceViewInterface::Options& options, bool replaceAll)
358{
359 if (!dataAwareObject() || !dataAwareObject()->data())
360 return cancelled;
361
362 return dataAwareObject()->findNextAndReplace(valueToFind, replacement, options, replaceAll);
363}
364
365/*
366void KexiDataAwareView::editFindNext()
367{
369}
370
371void KexiDataAwareView::editFindPrevious()
372{
374}
375
376void KexiDataAwareView::editReplace()
377{
380 // When ready, update KexiDataAwareView::initActions() and KexiMainWindowImpl
381}*/
382
383#include "kexidataawareview.moc"
void plugSharedAction(const char *action_name, TQObject *receiver, const char *slot)
The KexiDataAwareObjectInterface is an interface for record-based data object.
virtual tristate findNextAndReplace(const TQVariant &valueToFind, const TQVariant &replacement, const KexiSearchAndReplaceViewInterface::Options &options, bool replaceAll)
virtual void updateActions(bool activated)
virtual bool setupFindAndReplace(TQStringList &columnNames, TQStringList &columnCaptions, TQString &currentColumnName)
void init(TQWidget *viewWidget, KexiSharedActionClient *actionClient, KexiDataAwareObjectInterface *dataAwareObject, bool noDataAware=false)
virtual tristate find(const TQVariant &valueToFind, const KexiSearchAndReplaceViewInterface::Options &options, bool next)
Kexi's main window interface This interface is implemented by KexiMainWindowImpl class.
Specifies options for find and replace operations.
An interface used by Kexi views (KexiViewBase) supporting search/replace features.
The KexiSharedActionClient is an interface using application-wide (shared) actions.
KexiDB::Field * field() const
Base class for single view embeddable of in KexiDialogBase.
virtual TDEAction * sharedAction(const char *action_name)
virtual void setAvailable(const char *action_name, bool set)
void closing(bool &cancel)
emitted when the view is about to close
virtual TQSize preferredSizeHint(const TQSize &otherSize)
virtual void updateActions(bool activated)
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition tristate.h:100