kexi
kexiviewbase.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexiviewbase.h"
00021
00022 #include "keximainwindow.h"
00023 #include "kexidialogbase.h"
00024 #include "kexiproject.h"
00025 #include <koproperty/set.h>
00026
00027 #include <kexidb/connection.h>
00028 #include <kexidb/utils.h>
00029 #include <kexiutils/utils.h>
00030
00031 #include <kdebug.h>
00032
00033 KexiViewBase::KexiViewBase(KexiMainWindow *mainWin, QWidget *parent, const char *name)
00034 : QWidget(parent, name)
00035 , KexiActionProxy(this, mainWin)
00036 , m_mainWin(mainWin)
00037 , m_viewWidget(0)
00038 , m_parentView(0)
00039 , m_newlyAssignedID(-1)
00040 , m_viewMode(0)
00041 , m_dirty(false)
00042 {
00043 QWidget *wi=this;
00044 while ((wi = wi->parentWidget()) && !wi->inherits("KexiDialogBase"))
00045 ;
00046 m_dialog = (wi && wi->inherits("KexiDialogBase")) ? static_cast<KexiDialogBase*>(wi) : 0;
00047 if (m_dialog) {
00048
00049 if (m_dialog->supportsViewMode(m_dialog->m_creatingViewsMode))
00050 m_viewMode = m_dialog->m_creatingViewsMode;
00051 }
00052
00053 installEventFilter(this);
00054 }
00055
00056 KexiViewBase::~KexiViewBase()
00057 {
00058 }
00059
00060 KexiPart::Part* KexiViewBase::part() const
00061 {
00062 return m_dialog ? m_dialog->part() : 0;
00063 }
00064
00065 tristate KexiViewBase::beforeSwitchTo(int , bool & )
00066 {
00067 return true;
00068 }
00069
00070 tristate KexiViewBase::afterSwitchFrom(int )
00071 {
00072 return true;
00073 }
00074
00075 QSize KexiViewBase::preferredSizeHint(const QSize& otherSize)
00076 {
00077 KexiDialogBase* dlg = parentDialog();
00078 if (dlg && dlg->mdiParent()) {
00079 QRect r = dlg->mdiParent()->mdiAreaContentsRect();
00080 return otherSize.boundedTo( QSize(
00081 r.width() - 10,
00082 r.height() - dlg->mdiParent()->captionHeight() - dlg->pos().y() - 10
00083 ) );
00084 }
00085 return otherSize;
00086 }
00087
00088 void KexiViewBase::closeEvent( QCloseEvent * e )
00089 {
00090 bool cancel = false;
00091 emit closing(cancel);
00092 if (cancel) {
00093 e->ignore();
00094 return;
00095 }
00096 QWidget::closeEvent(e);
00097 }
00098
00099 KoProperty::Set *KexiViewBase::propertySet()
00100 {
00101 return 0;
00102 }
00103
00104 void KexiViewBase::propertySetSwitched()
00105 {
00106 if (parentDialog())
00107 m_mainWin->propertySetSwitched( parentDialog(), false );
00108 }
00109
00110 void KexiViewBase::propertySetReloaded(bool preservePrevSelection)
00111 {
00112 if (parentDialog())
00113 m_mainWin->propertySetSwitched( parentDialog(), true, preservePrevSelection );
00114 }
00115
00116 void KexiViewBase::setDirty(bool set)
00117 {
00118
00119
00120
00121
00122
00123
00124
00125
00126 const bool changed = (m_dirty != set);
00127 m_dirty = set;
00128 m_dirty = dirty();
00129
00130
00131 if (m_parentView) {
00132 m_parentView->setDirty(m_dirty);
00133 }
00134 else {
00135 if (changed && m_dialog)
00136 m_dialog->dirtyChanged();
00137 }
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 KexiDB::SchemaData* KexiViewBase::storeNewData(const KexiDB::SchemaData& sdata, bool & )
00150 {
00151 KexiDB::SchemaData *new_schema = new KexiDB::SchemaData();
00152 *new_schema = sdata;
00153
00154 if (!m_mainWin->project()->dbConnection()
00155 ->storeObjectSchemaData( *new_schema, true ))
00156 {
00157 delete new_schema;
00158 new_schema=0;
00159 }
00160 m_newlyAssignedID = new_schema->id();
00161 return new_schema;
00162 }
00163
00164 tristate KexiViewBase::storeData(bool dontAsk)
00165 {
00166 Q_UNUSED(dontAsk);
00167 if (!m_dialog || !m_dialog->schemaData())
00168 return false;
00169 if (!m_mainWin->project()->dbConnection()
00170 ->storeObjectSchemaData( *m_dialog->schemaData(), false ))
00171 {
00172 return false;
00173 }
00174 setDirty(false);
00175 return true;
00176 }
00177
00178 bool KexiViewBase::loadDataBlock( QString &dataString, const QString& dataID )
00179 {
00180 if (!m_dialog)
00181 return false;
00182 return m_mainWin->project()->dbConnection()->loadDataBlock(m_dialog->id(), dataString, dataID);
00183 }
00184
00185 bool KexiViewBase::storeDataBlock( const QString &dataString, const QString &dataID )
00186 {
00187 if (!m_dialog)
00188 return false;
00189 int effectiveID;
00190 if (m_newlyAssignedID>0) {
00191 effectiveID = m_newlyAssignedID;
00192 m_newlyAssignedID = -1;
00193 }
00194 else
00195 effectiveID = m_dialog->id();
00196
00197 return effectiveID>0
00198 && m_mainWin->project()->dbConnection()->storeDataBlock(effectiveID, dataString, dataID);
00199 }
00200
00201 bool KexiViewBase::removeDataBlock( const QString& dataID )
00202 {
00203 if (!m_dialog)
00204 return false;
00205 return m_mainWin->project()->dbConnection()->removeDataBlock(m_dialog->id(), dataID);
00206 }
00207
00208 bool KexiViewBase::eventFilter( QObject *o, QEvent *e )
00209 {
00210 if (e->type()==QEvent::FocusIn || e->type()==QEvent::FocusOut) {
00211
00212
00213
00214 if (KexiUtils::hasParent( this, static_cast<QWidget*>(o))) {
00215 if (e->type()==QEvent::FocusOut && focusWidget() && !KexiUtils::hasParent( this, focusWidget())) {
00216
00217 emit focus(false);
00218 } else if (e->type()==QEvent::FocusIn) {
00219 emit focus(true);
00220 }
00221 if (e->type()==QEvent::FocusOut) {
00222
00223
00224 KexiViewBase *v = KexiUtils::findParent<KexiViewBase>(o, "KexiViewBase") ;
00225
00226 if (v) {
00227 while (v->m_parentView)
00228 v = v->m_parentView;
00229 v->m_lastFocusedChildBeforeFocusOut = static_cast<QWidget*>(v->focusWidget());
00230
00231 }
00232 }
00233
00234 if (e->type()==QEvent::FocusIn && m_actionProxyParent) {
00235 m_actionProxyParent->m_focusedChild = this;
00236 }
00237
00238 }
00239 }
00240 return false;
00241 }
00242
00243 void KexiViewBase::setViewWidget(QWidget* w, bool focusProxy)
00244 {
00245 if (m_viewWidget == w)
00246 return;
00247 if (m_viewWidget) {
00248 m_viewWidget->removeEventFilter(this);
00249 }
00250 m_viewWidget = w;
00251 if (m_viewWidget) {
00252 m_viewWidget->installEventFilter(this);
00253 if (focusProxy)
00254 setFocusProxy(m_viewWidget);
00255 }
00256 }
00257
00258 void KexiViewBase::addChildView( KexiViewBase* childView )
00259 {
00260 m_children.append( childView );
00261 addActionProxyChild( childView );
00262 childView->m_parentView = this;
00263
00264
00265 childView->installEventFilter(this);
00266
00267 }
00268
00269 void KexiViewBase::setFocus()
00270 {
00271 if (!m_lastFocusedChildBeforeFocusOut.isNull()) {
00272
00273 QWidget *w = m_lastFocusedChildBeforeFocusOut;
00274 m_lastFocusedChildBeforeFocusOut = 0;
00275 w->setFocus();
00276 }
00277 else {
00278 if (hasFocus())
00279 setFocusInternal();
00280 else
00281 setFocusInternal();
00282 }
00283 m_mainWin->invalidateSharedActions(this);
00284 }
00285
00286 KAction* KexiViewBase::sharedAction( const char *action_name )
00287 {
00288 if (part()) {
00289 KActionCollection *ac;
00290 if ( (ac = part()->actionCollectionForMode( viewMode() )) ) {
00291 KAction* a = ac->action( action_name );
00292 if (a)
00293 return a;
00294 }
00295 }
00296 return KexiActionProxy::sharedAction(action_name);
00297 }
00298
00299 void KexiViewBase::setAvailable(const char* action_name, bool set)
00300 {
00301 if (part()) {
00302 KActionCollection *ac;
00303 KAction* a;
00304 if ( (ac = part()->actionCollectionForMode( viewMode() )) && (a = ac->action( action_name )) ) {
00305 a->setEnabled(set);
00306
00307 }
00308 }
00309 KexiActionProxy::setAvailable(action_name, set);
00310 }
00311
00312 void KexiViewBase::updateActions(bool activated)
00313 {
00314
00315
00316 for (QPtrListIterator<KexiViewBase> it(m_children); it.current(); ++it) {
00317 it.current()->updateActions(activated);
00318 }
00319 }
00320
00321 #include "kexiviewbase.moc"
00322
|