[Kst] branches/work/kst/portto4/kst/src/libkstapp
Barth Netterfield
netterfield at astro.utoronto.ca
Tue Jun 15 03:11:30 CEST 2010
SVN commit 1138020 by netterfield:
Improve the performance of the vector selector in the data wizard by
optimizing the '*' special case.
Improve the performance of the data manager by not regenerating the object
list N times.
M +4 -5 datamanager.cpp
M +6 -0 datawizard.cpp
M +22 -22 sessionmodel.cpp
M +4 -3 sessionmodel.h
--- branches/work/kst/portto4/kst/src/libkstapp/datamanager.cpp #1138019:1138020
@@ -157,13 +157,12 @@
// ought to delete all of our actions before we exit)
}
-
void DataManager::showContextMenu(const QPoint &position) {
QList<QAction *> actions;
if (_session->indexAt(position).isValid()) {
SessionModel *model = static_cast<SessionModel*>(_session->model());
if (!model->parent(_session->indexAt(position)).isValid()) {
- _currentObject = model->generateObjectList().at(_session->indexAt(position).row());
+ _currentObject = model->objectList()->at(_session->indexAt(position).row());
if (_currentObject) {
QAction *action = new QAction(_currentObject->Name(), this);
action->setEnabled(false);
@@ -254,7 +253,7 @@
actions.append(action);
}
} else {
- DataObjectPtr dataObject = kst_cast<DataObject>(model->generateObjectList().at(_session->indexAt(position).parent().row()));
+ DataObjectPtr dataObject = kst_cast<DataObject>(model->objectList()->at(_session->indexAt(position).parent().row()));
if (dataObject) {
if (dataObject->outputVectors().count() > _session->indexAt(position).row()) {
_currentObject = dataObject->outputVectors().values()[_session->indexAt(position).row()];
@@ -306,7 +305,7 @@
if (!qml.parent().isValid()) { // don't edit slave objects
SessionModel *model = static_cast<SessionModel*>(_session->model());
- _currentObject = model->generateObjectList().at(qml.row());
+ _currentObject = model->objectList()->at(qml.row());
showEditDialog();
}
@@ -318,7 +317,7 @@
bool DataManager::event(QEvent * event) {
- if (event->type() == QEvent::WindowActivate) {
+ if ((event->type() == QEvent::WindowActivate) || (event->type() == QEvent::Show)) {
_doc->session()->triggerReset();
}
return QDialog::event(event);
--- branches/work/kst/portto4/kst/src/libkstapp/datawizard.cpp #1138019:1138020
@@ -229,6 +229,12 @@
void DataWizardPageVectors::filterVectors(const QString& filter) {
_vectors->clearSelection();
+
+ if (filter=="*") { // optimization
+ _vectors->selectAll();
+ return;
+ }
+
QRegExp re(filter, Qt::CaseSensitive, QRegExp::Wildcard);
QStringList selected;
for (int i = 0; i < _vectors->count(); i++) {
--- branches/work/kst/portto4/kst/src/libkstapp/sessionmodel.cpp #1138019:1138020
@@ -26,6 +26,7 @@
SessionModel::SessionModel(ObjectStore *store)
: QAbstractItemModel(), _store(store) {
+ generateObjectList();
}
@@ -40,40 +41,39 @@
void SessionModel::triggerReset() {
+ generateObjectList();
reset();
}
-const ObjectList<Object> SessionModel::generateObjectList() const {
- ObjectList<Object> ol;
+void SessionModel::generateObjectList() {
ObjectList<Primitive> pol = _store->getObjects<Primitive>();
ObjectList<Relation> rol = _store->getObjects<Relation>();
ObjectList<DataObject> dol = _store->getObjects<DataObject>();
+ _objectList.clear();
foreach(Primitive* P, pol) {
if (!P->provider()) {
- ol.append(P);
+ _objectList.append(P);
}
}
foreach(Relation* relation, rol) {
- ol.append(relation);
+ _objectList.append(relation);
}
foreach(DataObject* dataObject, dol) {
- ol.append(dataObject);
+ _objectList.append(dataObject);
}
- return ol;
}
int SessionModel::rowCount(const QModelIndex& parent) const {
Q_ASSERT(_store);
- ObjectList<Object> dol = generateObjectList();
-
+ //ObjectList<Object> dol = generateObjectList();
int rc = 0;
if (!parent.isValid()) {
- rc = dol.count(); /* + generated primitives */
+ rc = _objectList.count(); /* + generated primitives */
return rc;
}
@@ -81,7 +81,7 @@
return rc;
}
- DataObject *pdo = kst_cast<DataObject>(dol.at(parent.row()));
+ DataObject *pdo = kst_cast<DataObject>(_objectList.at(parent.row()));
if (pdo) {
pdo->readLock();
rc = pdo->outputVectors().count();
@@ -96,7 +96,6 @@
if (!index.isValid()) {
return QVariant();
}
-
if (role == Qt::UserRole) {
if (index.parent().isValid()) {
Q_ASSERT(!index.parent().parent().isValid());
@@ -112,7 +111,7 @@
}
} else {
Q_ASSERT(_store);
- DataObjectPtr p = kst_cast<DataObject>(generateObjectList().at(index.row()));
+ DataObjectPtr p = kst_cast<DataObject>(_objectList.at(index.row()));
return qVariantFromValue(p.data());
}
}
@@ -128,18 +127,18 @@
}
Q_ASSERT(_store);
- ObjectList<Object> objectList = generateObjectList();
+ //ObjectList<Object> objectList = generateObjectList();
const int row = index.row();
- if (row >= objectList.count()) {
+ if (row >= _objectList.count()) {
return QVariant();
}
- if (DataObjectPtr p = kst_cast<DataObject>(objectList.at(row))) {
+ if (DataObjectPtr p = kst_cast<DataObject>(_objectList.at(row))) {
return dataObjectData(p, index);
- } else if (RelationPtr p = kst_cast<Relation>(objectList.at(row))) {
+ } else if (RelationPtr p = kst_cast<Relation>(_objectList.at(row))) {
return relationData(p, index);
- } else if (PrimitivePtr p=kst_cast<Primitive>(objectList.at(row))) {
+ } else if (PrimitivePtr p=kst_cast<Primitive>(_objectList.at(row))) {
return primitiveData(p, index);
} else {
return QVariant();
@@ -285,20 +284,20 @@
}
Q_ASSERT(_store);
- ObjectList<Object> dol = generateObjectList();
+ //ObjectList<Object> dol = generateObjectList();
if (!parent.isValid()) {
- const int cnt = dol.count();
+ const int cnt = _objectList.count();
if (row >= cnt) {
return QModelIndex();
}
return createIndex(row, col);
}
- const int cnt = dol.count();
+ const int cnt = _objectList.count();
DataObject *p = 0;
if (parent.row() >= 0 && parent.row() < cnt) {
- p = kst_cast<DataObject>(dol.at(parent.row()));
+ p = kst_cast<DataObject>(_objectList.at(parent.row()));
}
if (!p) {
return QModelIndex();
@@ -316,13 +315,14 @@
QModelIndex SessionModel::parent(const QModelIndex& index) const {
// If it is a primitive and has a provider, return the index of that provider
+
DataObject *dop = static_cast<DataObject*>(index.internalPointer());
if (!dop) {
return QModelIndex();
}
Q_ASSERT(_store);
- const int cnt = generateObjectList().indexOf(dop);
+ const int cnt = _objectList.indexOf(dop);
if (cnt < 0) {
return QModelIndex();
}
--- branches/work/kst/portto4/kst/src/libkstapp/sessionmodel.h #1138019:1138020
@@ -34,16 +34,17 @@
QModelIndex index(int row, int col, const QModelIndex& parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex& index) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
- const ObjectList<Object> generateObjectList() const;
-
+ void generateObjectList();
void triggerReset();
-
+ ObjectList<Object> *objectList() {return &_objectList;}
private:
QVariant dataObjectOutputData(DataObjectPtr parent, const QModelIndex& index) const;
QVariant primitiveData(PrimitivePtr parent, const QModelIndex& index) const;
QVariant dataObjectData(DataObjectPtr dataObject, const QModelIndex& index) const;
QVariant relationData(RelationPtr relation, const QModelIndex& index) const;
+ ObjectList<Object> _objectList;
+
ObjectStore *_store;
};
More information about the Kst
mailing list