00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexidataawareview.h"
00021
00022 #include <kexidataawareobjectiface.h>
00023 #include <utils/kexisharedactionclient.h>
00024 #include <core/keximainwindow.h>
00025
00026 #include <qlayout.h>
00027
00028 #include <kpopupmenu.h>
00029
00030 KexiDataAwareView::KexiDataAwareView(KexiMainWindow *mainWin, QWidget *parent, const char *name)
00031 : KexiViewBase(mainWin, parent, name)
00032 , KexiSearchAndReplaceViewInterface()
00033 , m_internalView(0)
00034 , m_actionClient(0)
00035 , m_dataAwareObject(0)
00036 {
00037 }
00038
00039 void KexiDataAwareView::init( QWidget* viewWidget, KexiSharedActionClient* actionClient,
00040 KexiDataAwareObjectInterface* dataAwareObject, bool noDataAware )
00041 {
00042 m_internalView = viewWidget;
00043 m_actionClient = actionClient;
00044 m_dataAwareObject = dataAwareObject;
00045 setViewWidget(m_internalView, true);
00046
00047 if (!noDataAware) {
00048 m_dataAwareObject->connectCellSelectedSignal(this, SLOT(slotCellSelected(int,int)));
00049
00051 connect(this, SIGNAL(closing(bool&)), this, SLOT(slotClosing(bool&)));
00052
00054 m_dataAwareObject->connectRowEditStartedSignal(this, SLOT(slotUpdateRowActions(int)));
00055 m_dataAwareObject->connectRowEditTerminatedSignal(this, SLOT(slotUpdateRowActions(int)));
00056 m_dataAwareObject->connectReloadActionsSignal(this, SLOT(reloadActions()));
00057 }
00058
00059 QVBoxLayout *box = new QVBoxLayout(this);
00060 box->addWidget(m_internalView);
00061
00062 setMinimumSize(m_internalView->minimumSizeHint().width(),
00063 m_internalView->minimumSizeHint().height());
00064 resize( preferredSizeHint( m_internalView->sizeHint() ) );
00065 setFocusProxy(m_internalView);
00066
00067 if (!noDataAware) {
00068 initActions();
00069 reloadActions();
00070 }
00071 }
00072
00073 void KexiDataAwareView::initActions()
00074 {
00075 plugSharedAction("edit_delete_row", this, SLOT(deleteCurrentRow()));
00076 m_actionClient->plugSharedAction(sharedAction("edit_delete_row"));
00077
00078 plugSharedAction("edit_delete", this, SLOT(deleteAndStartEditCurrentCell()));
00079 m_actionClient->plugSharedAction(sharedAction("edit_delete"));
00080
00081 plugSharedAction("edit_edititem", this, SLOT(startEditOrToggleValue()));
00082 m_actionClient->plugSharedAction(sharedAction("edit_edititem"));
00083
00084 plugSharedAction("data_save_row", this, SLOT(acceptRowEdit()));
00085 m_actionClient->plugSharedAction(sharedAction("data_save_row"));
00086
00087 plugSharedAction("data_cancel_row_changes", this, SLOT(cancelRowEdit()));
00088 m_actionClient->plugSharedAction(sharedAction("data_cancel_row_changes"));
00089
00090 if (m_dataAwareObject->isSortingEnabled()) {
00091 plugSharedAction("data_sort_az", this, SLOT(sortAscending()));
00092 plugSharedAction("data_sort_za", this, SLOT(sortDescending()));
00093 }
00094
00095 m_actionClient->plugSharedAction(sharedAction("edit_insert_empty_row"));
00096
00097 setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
00098 setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
00100
00101 plugSharedAction("data_go_to_first_record", this, SLOT(slotGoToFirstRow()));
00102 plugSharedAction("data_go_to_previous_record", this, SLOT(slotGoToPreviusRow()));
00103 plugSharedAction("data_go_to_next_record", this, SLOT(slotGoToNextRow()));
00104 plugSharedAction("data_go_to_last_record", this, SLOT(slotGoToLastRow()));
00105 plugSharedAction("data_go_to_new_record", this, SLOT(slotGoToNewRow()));
00106
00108 setAvailable("data_go_to_first_record", true);
00109 setAvailable("data_go_to_previous_record", true);
00110 setAvailable("data_go_to_next_record", true);
00111 setAvailable("data_go_to_last_record", true);
00112 setAvailable("data_go_to_new_record", true);
00113
00114 plugSharedAction("edit_copy", this, SLOT(copySelection()));
00115 m_actionClient->plugSharedAction(sharedAction("edit_copy"));
00116
00117 plugSharedAction("edit_cut", this, SLOT(cutSelection()));
00118 m_actionClient->plugSharedAction(sharedAction("edit_cut"));
00119
00120 plugSharedAction("edit_paste", this, SLOT(paste()));
00121 m_actionClient->plugSharedAction(sharedAction("edit_paste"));
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00134
00135
00136
00137
00139 }
00140
00141 void KexiDataAwareView::slotUpdateRowActions(int row)
00142 {
00143 const bool ro = m_dataAwareObject->isReadOnly();
00144
00145 const bool deleting = m_dataAwareObject->isDeleteEnabled();
00146 const bool emptyInserting = m_dataAwareObject->isEmptyRowInsertingEnabled();
00147 const bool editing = m_dataAwareObject->rowEditing();
00148 const bool sorting = m_dataAwareObject->isSortingEnabled();
00149 const int rows = m_dataAwareObject->rows();
00150
00151 setAvailable("edit_cut", !ro);
00152 setAvailable("edit_paste", !ro);
00153 setAvailable("edit_delete", !ro);
00154 setAvailable("edit_delete_row", !ro && !(deleting && row==rows));
00155 setAvailable("edit_insert_empty_row", !ro && emptyInserting);
00156 setAvailable("edit_clear_table", !ro && deleting && rows>0);
00157 setAvailable("data_save_row", editing);
00158 setAvailable("data_cancel_row_changes", editing);
00159 setAvailable("data_sort_az", sorting);
00160 setAvailable("data_sort_za", sorting);
00161 }
00162
00163 QWidget* KexiDataAwareView::mainWidget()
00164 {
00165 return m_internalView;
00166 }
00167
00168 QSize KexiDataAwareView::minimumSizeHint() const
00169 {
00170 return m_internalView ? m_internalView->minimumSizeHint() : QSize(0,0);
00171 }
00172
00173 QSize KexiDataAwareView::sizeHint() const
00174 {
00175 return m_internalView ? m_internalView->sizeHint() : QSize(0,0);
00176 }
00177
00178 void KexiDataAwareView::updateActions(bool activated)
00179 {
00180 setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
00181 setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
00182 KexiViewBase::updateActions(activated);
00183 }
00184
00185 void KexiDataAwareView::reloadActions()
00186 {
00187
00188
00189
00190
00191
00192
00193
00194 m_dataAwareObject->contextMenu()->clear();
00195
00196 plugSharedAction("edit_cut", m_dataAwareObject->contextMenu());
00197 plugSharedAction("edit_copy", m_dataAwareObject->contextMenu());
00198 plugSharedAction("edit_paste", m_dataAwareObject->contextMenu());
00199
00200 bool separatorNeeded = true;
00201
00202 unplugSharedAction("edit_clear_table");
00203 plugSharedAction("edit_clear_table", this, SLOT(deleteAllRows()));
00204
00205 if (m_dataAwareObject->isEmptyRowInsertingEnabled()) {
00206 unplugSharedAction("edit_insert_empty_row");
00207 plugSharedAction("edit_insert_empty_row", m_internalView, SLOT(insertEmptyRow()));
00208 if (separatorNeeded)
00209 m_dataAwareObject->contextMenu()->insertSeparator();
00210 plugSharedAction("edit_insert_empty_row", m_dataAwareObject->contextMenu());
00211 }
00212 else {
00213 unplugSharedAction("edit_insert_empty_row");
00214 unplugSharedAction("edit_insert_empty_row", m_dataAwareObject->contextMenu());
00215 }
00216
00217 if (m_dataAwareObject->isDeleteEnabled()) {
00218 if (separatorNeeded)
00219 m_dataAwareObject->contextMenu()->insertSeparator();
00220 plugSharedAction("edit_delete", m_dataAwareObject->contextMenu());
00221 plugSharedAction("edit_delete_row", m_dataAwareObject->contextMenu());
00222 }
00223 else {
00224 unplugSharedAction("edit_delete_row", m_dataAwareObject->contextMenu());
00225 unplugSharedAction("edit_delete_row", m_dataAwareObject->contextMenu());
00226 }
00227
00228
00229
00230
00231 setAvailable("data_sort_az", m_dataAwareObject->isSortingEnabled());
00232 setAvailable("data_sort_za", m_dataAwareObject->isSortingEnabled());
00233
00234 slotCellSelected( m_dataAwareObject->currentColumn(), m_dataAwareObject->currentRow() );
00235 }
00236
00237 void KexiDataAwareView::slotCellSelected(int , int row)
00238 {
00239 slotUpdateRowActions(row);
00240 }
00241
00242 void KexiDataAwareView::deleteAllRows()
00243 {
00244 m_dataAwareObject->deleteAllRows(true, true);
00245 }
00246
00247 void KexiDataAwareView::deleteCurrentRow()
00248 {
00249 m_dataAwareObject->deleteCurrentRow();
00250 }
00251
00252 void KexiDataAwareView::deleteAndStartEditCurrentCell()
00253 {
00254 m_dataAwareObject->deleteAndStartEditCurrentCell();
00255 }
00256
00257 void KexiDataAwareView::startEditOrToggleValue()
00258 {
00259 m_dataAwareObject->startEditOrToggleValue();
00260 }
00261
00262 bool KexiDataAwareView::acceptRowEdit()
00263 {
00264 return m_dataAwareObject->acceptRowEdit();
00265 }
00266
00267 void KexiDataAwareView::slotClosing(bool& cancel)
00268 {
00269 if (!acceptRowEdit())
00270 cancel = true;
00271 }
00272
00273 void KexiDataAwareView::cancelRowEdit()
00274 {
00275 m_dataAwareObject->cancelRowEdit();
00276 }
00277
00278 void KexiDataAwareView::sortAscending()
00279 {
00280 m_dataAwareObject->sortAscending();
00281 }
00282
00283 void KexiDataAwareView::sortDescending()
00284 {
00285 m_dataAwareObject->sortDescending();
00286 }
00287
00288 void KexiDataAwareView::copySelection()
00289 {
00290 m_dataAwareObject->copySelection();
00291 }
00292
00293 void KexiDataAwareView::cutSelection()
00294 {
00295 m_dataAwareObject->cutSelection();
00296 }
00297
00298 void KexiDataAwareView::paste()
00299 {
00300 m_dataAwareObject->paste();
00301 }
00302
00303 void KexiDataAwareView::slotGoToFirstRow() { m_dataAwareObject->selectFirstRow(); }
00304 void KexiDataAwareView::slotGoToPreviusRow() { m_dataAwareObject->selectPrevRow(); }
00305 void KexiDataAwareView::slotGoToNextRow() { m_dataAwareObject->selectNextRow(); }
00306 void KexiDataAwareView::slotGoToLastRow() { m_dataAwareObject->selectLastRow(); }
00307 void KexiDataAwareView::slotGoToNewRow() { m_dataAwareObject->addNewRecordRequested(); }
00308
00309 bool KexiDataAwareView::setupFindAndReplace(QStringList& columnNames, QStringList& columnCaptions,
00310 QString& currentColumnName)
00311 {
00312 if (!dataAwareObject() || !dataAwareObject()->data())
00313 return false;
00314 KexiTableViewColumn::List columns( dataAwareObject()->data()->columns );
00315 for (KexiTableViewColumn::ListIterator it(columns); it.current(); ++it) {
00316 if (!it.current()->visible())
00317 continue;
00318 columnNames.append( it.current()->field()->name() );
00319 columnCaptions.append( it.current()->captionAliasOrName() );
00320 }
00321
00322
00323 const int currentColumnNumber = dataAwareObject()->currentColumn();
00324 if (currentColumnNumber!=-1) {
00325 KexiTableViewColumn *col = columns.at( currentColumnNumber );
00326 if (col && col->field())
00327 currentColumnName = col->field()->name();
00328 }
00329 return true;
00330 }
00331
00332 tristate KexiDataAwareView::find(const QVariant& valueToFind,
00333 const KexiSearchAndReplaceViewInterface::Options& options, bool next)
00334 {
00335 if (!dataAwareObject() || !dataAwareObject()->data())
00336 return cancelled;
00337
00338
00339
00340
00341 return dataAwareObject()->find( valueToFind, options, next );
00342
00344
00345
00346
00348
00349
00351
00352
00353 }
00354
00355 tristate KexiDataAwareView::findNextAndReplace(const QVariant& valueToFind,
00356 const QVariant& replacement,
00357 const KexiSearchAndReplaceViewInterface::Options& options, bool replaceAll)
00358 {
00359 if (!dataAwareObject() || !dataAwareObject()->data())
00360 return cancelled;
00361
00362 return dataAwareObject()->findNextAndReplace(valueToFind, replacement, options, replaceAll);
00363 }
00364
00365
00366
00367
00369
00370
00371
00372
00374
00375
00376
00377
00380
00381
00382
00383 #include "kexidataawareview.moc"