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