~ubuntu-branches/ubuntu/karmic/kst/karmic

« back to all changes in this revision

Viewing changes to kst/kst/kstviewmanager_i.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-06-30 19:11:30 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630191130-acumuar75bz4puty
Tags: 1.2.1-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                       kstviewmanger_i.cpp  -  Part of KST
 
3
                             -------------------
 
4
    begin                :
 
5
    copyright            : (C) 2003 The University of British Columbia
 
6
    email                :
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
#include <assert.h>
 
18
 
 
19
// include files for Qt
 
20
#include <qptrstack.h>
 
21
 
 
22
// include files for KDE
 
23
#include "ksdebug.h"
 
24
#include <klistview.h>
 
25
#include <kmessagebox.h>
 
26
#include <kstandarddirs.h>
 
27
 
 
28
// application specific includes
 
29
#include "kstdatacollection.h"
 
30
#include "kstobject.h"
 
31
#include "kstviewmanager_i.h"
 
32
#include "kstdoc.h"
 
33
#include "kstviewwindow.h"
 
34
 
 
35
 
 
36
#define RTTI_OBJ_WINDOW          4301
 
37
#define RTTI_OBJ_2D_PLOT         4302
 
38
#define RTTI_OBJ_PLOT_GROUP      4303
 
39
#define RTTI_OBJ_VIEW_OBJECT     4304
 
40
 
 
41
 
 
42
KstViewObjectItem::KstViewObjectItem(QListView *parent, KstTopLevelViewPtr x, KstViewManagerI *vm, int localUseCount)
 
43
: QObject(), QListViewItem(parent), _rtti(RTTI_OBJ_WINDOW), _name(x->tagName()), _vm(vm) {
 
44
  assert(x);
 
45
  _inUse = false;
 
46
  setText(0, x->name());
 
47
  setText(1, x->type());
 
48
  update(KstViewObjectPtr(x), true, localUseCount);
 
49
}
 
50
 
 
51
 
 
52
KstViewObjectItem::KstViewObjectItem(QListViewItem *parent, KstViewObjectPtr x, KstViewManagerI *vm, int localUseCount)
 
53
: QObject(), QListViewItem(parent), _rtti(RTTI_OBJ_VIEW_OBJECT), _name(x->tagName()), _vm(vm) {
 
54
  assert(x);
 
55
  _inUse = false;
 
56
  setText(0, x->tagName());
 
57
  setText(1, x->type());
 
58
  update(KstViewObjectPtr(x), true, localUseCount);
 
59
}
 
60
 
 
61
KstViewObjectItem::~KstViewObjectItem() {
 
62
}
 
63
 
 
64
void KstViewObjectItem::update(KstViewObjectPtr x, bool recursive, int localUseCount) {
 
65
  QPtrStack<QListViewItem> trash;
 
66
  
 
67
  // garbage collect first
 
68
  for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
 
69
    bool found = false;
 
70
    KstViewObjectItem *oi = static_cast<KstViewObjectItem*>(i);
 
71
    if (i->rtti() == RTTI_OBJ_VIEW_OBJECT) {
 
72
      for (KstViewObjectList::ConstIterator obj = x->children().begin(); obj != x->children().end(); ++obj) {
 
73
        if (x->tagName() == oi->tagName()) {
 
74
          found = true;
 
75
          break;
 
76
        }
 
77
      }
 
78
    }
 
79
    if (!found) {
 
80
      trash.push(i);
 
81
    }
 
82
  }
 
83
  
 
84
  trash.setAutoDelete(true);
 
85
  _vm->blockSignals(true);
 
86
  trash.clear();
 
87
  _vm->blockSignals(false);
 
88
  
 
89
  for (KstViewObjectList::ConstIterator obj = x->children().begin(); obj != x->children().end(); ++obj) {
 
90
    bool found = false;
 
91
    for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
 
92
      KstViewObjectItem *oi = static_cast<KstViewObjectItem*>(i);
 
93
      if (oi->tagName() == (*obj)->tagName()) {
 
94
        oi->update(*obj);
 
95
        found = true;
 
96
        break;
 
97
      }
 
98
    }
 
99
    if (!found) {
 
100
      KstViewObjectItem *i = new KstViewObjectItem(this, *obj, _vm);
 
101
    }
 
102
  } 
 
103
}
 
104
 
 
105
 
 
106
void KstViewObjectItem::updateButtons() {
 
107
  _vm->Edit->setEnabled(_rtti != RTTI_OBJ_WINDOW);
 
108
  _vm->Delete->setEnabled(true);
 
109
}
 
110
 
 
111
 
 
112
KstViewManagerI::KstViewManagerI(KstDoc *in_doc, QWidget* parent, const char* name, bool modal, WFlags fl)
 
113
: KstViewManager(parent, name, modal, fl) {
 
114
  doc = in_doc;
 
115
 
 
116
  connect(Close, SIGNAL(clicked()), this, SLOT(reject()));
 
117
  connect(Edit, SIGNAL(clicked()), this, SLOT(edit_I()));
 
118
  connect(Delete, SIGNAL(clicked()), this, SLOT(delete_I()));
 
119
  connect(ViewView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(edit_I()));
 
120
  connect(ViewView, SIGNAL(currentChanged(QListViewItem *)), this, SLOT(currentChanged(QListViewItem *)));
 
121
  connect(ViewView, SIGNAL(selectionChanged(QListViewItem *)), this, SLOT(currentChanged(QListViewItem *)));
 
122
  connect(ViewView, SIGNAL(contextMenuRequested(QListViewItem*, const QPoint&, int)), this, SLOT(contextMenu(QListViewItem*, const QPoint&, int)));
 
123
}
 
124
 
 
125
 
 
126
KstViewManagerI::~KstViewManagerI() {
 
127
}
 
128
 
 
129
 
 
130
void KstViewManagerI::show_I() {
 
131
  show();
 
132
  raise();
 
133
  update();
 
134
}
 
135
 
 
136
 
 
137
void KstViewManagerI::updateContents() {
 
138
  update();
 
139
}
 
140
 
 
141
 
 
142
void KstViewManagerI::update() {
 
143
  KstApp *app = KstApp::inst();
 
144
    
 
145
  if (!isShown()) {
 
146
    return;
 
147
  }
 
148
 
 
149
  QListViewItem *currentItem = ViewView->selectedItem();
 
150
  QPtrStack<QListViewItem> trash;
 
151
  KMdiIterator<KMdiChildView*> *it = app->createIterator();
 
152
 
 
153
  // garbage collect first
 
154
  for (QListViewItem *i = ViewView->firstChild(); i; i = i->nextSibling()) {
 
155
    bool found = false;
 
156
    KstViewObjectItem *oi = static_cast<KstViewObjectItem*>(i);
 
157
    it->first();
 
158
    if (i->rtti() == RTTI_OBJ_WINDOW) {
 
159
      while (it->currentItem()) {      
 
160
        KstViewWindow *win = dynamic_cast<KstViewWindow*>(it->currentItem());
 
161
        if (win) {
 
162
          KstTopLevelViewPtr view = win->view();
 
163
          if (view) {
 
164
            if (view->tagName() == oi->tagName()) {
 
165
              found = true;
 
166
            }
 
167
          }
 
168
        }
 
169
        it->next();
 
170
      }
 
171
    }
 
172
    if (!found) {
 
173
      trash.push(i);
 
174
    }
 
175
  }
 
176
 
 
177
  trash.setAutoDelete(true);
 
178
  ViewView->blockSignals(true);
 
179
  trash.clear();
 
180
  ViewView->blockSignals(false);
 
181
  
 
182
  it->first();
 
183
  while (it->currentItem()) {      
 
184
    KstViewWindow *win = dynamic_cast<KstViewWindow*>(it->currentItem());
 
185
    if (win) {
 
186
      KstTopLevelViewPtr  view = win->view();
 
187
      if (view) {
 
188
        bool found = false;
 
189
 
 
190
        for (QListViewItem *i = ViewView->firstChild(); i; i = i->nextSibling()) {
 
191
          KstViewObjectItem *oi = static_cast<KstViewObjectItem*>(i);
 
192
          if (oi->rtti() == RTTI_OBJ_WINDOW && oi->tagName() == view->tagName()) {
 
193
            oi->update(KstViewObjectPtr(view));
 
194
            found = true;
 
195
            break;
 
196
          }
 
197
        }
 
198
        if (!found) {
 
199
          KstViewObjectItem *i = new KstViewObjectItem(ViewView, view, this);
 
200
        }
 
201
      }
 
202
    }
 
203
    it->next();
 
204
  }
 
205
 
 
206
  for (QListViewItem *i = ViewView->firstChild(); i; i = i->nextSibling()) {
 
207
    if (i == currentItem) {
 
208
      ViewView->setCurrentItem(i);
 
209
      ViewView->setSelected(i, true);
 
210
      break;
 
211
    }
 
212
  }
 
213
  
 
214
  if (ViewView->selectedItem()) {
 
215
    static_cast<KstViewObjectItem*>(ViewView->currentItem())->updateButtons();
 
216
  } else {
 
217
    Edit->setEnabled(false);
 
218
    Delete->setEnabled(false);
 
219
  }
 
220
  
 
221
  app->deleteIterator(it);
 
222
}
 
223
 
 
224
 
 
225
void KstViewManagerI::edit_I() {
 
226
  QListViewItem *qi;
 
227
 
 
228
  if (ViewView->selectedItems().count() > 0) {
 
229
    qi = ViewView->selectedItems().at(0);
 
230
  } else {
 
231
    KMessageBox::sorry(this, i18n("An item must be selected to edit."));
 
232
    return;
 
233
  }
 
234
}
 
235
 
 
236
 
 
237
void KstViewManagerI::delete_I() {
 
238
  QListViewItem *qi = ViewView->selectedItems().at(0);
 
239
  KstViewObjectItem *koi = static_cast<KstViewObjectItem*>(qi);
 
240
 
 
241
  if (koi->removable()) {
 
242
    update();
 
243
  } else {
 
244
  }
 
245
}
 
246
 
 
247
 
 
248
// Menu IDs:
 
249
// 100->499 reserved for plots
 
250
// 500->999 reserved for filters
 
251
 
 
252
void KstViewManagerI::contextMenu(QListViewItem *i, const QPoint& p, int col) {
 
253
  Q_UNUSED(col)
 
254
 
 
255
  if (!i) {
 
256
    return;
 
257
  }
 
258
 
 
259
  KstViewObjectItem *koi = static_cast<KstViewObjectItem*>(i);
 
260
  KPopupMenu *m = new KPopupMenu(this);
 
261
 
 
262
  m->insertTitle(koi->text(0));
 
263
  
 
264
  m->popup(p);
 
265
}
 
266
 
 
267
 
 
268
void KstViewManagerI::doUpdates() {
 
269
  emit docChanged();
 
270
}
 
271
 
 
272
 
 
273
void KstViewManagerI::currentChanged(QListViewItem *i) {
 
274
  if (i) {
 
275
    KstViewObjectItem *koi = static_cast<KstViewObjectItem*>(i);
 
276
    koi->updateButtons();
 
277
  }
 
278
}
 
279
 
 
280
#include "kstviewmanager_i.moc"
 
281
// vim: ts=2 sw=2 et