Showing with 50 additions and 10 deletions.
  1. +4 −1 src/libkst/datavector.cpp
  2. +11 −0 src/libkst/vector.cpp
  3. +4 −0 src/libkst/vector.h
  4. +15 −9 src/libkstapp/vectormodel.cpp
  5. +2 −0 src/libkstapp/vectormodel.h
  6. +13 −0 src/libkstapp/viewvectordialog.cpp
  7. +1 −0 src/libkstapp/viewvectordialog.h
5 changes: 4 additions & 1 deletion src/libkst/datavector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ int DataVector::reqStartFrame() const {

/** Save vector information */
void DataVector::save(QXmlStreamWriter &s) {
if (dataSource()) {
if (saveData()) { // The vector has been modified manually => use basic saving
Kst::Vector::save(s);
}
else if (dataSource()) {
s.writeStartElement("datavector");
saveFilename(s);
s.writeAttribute("field", _field);
Expand Down
11 changes: 11 additions & 0 deletions src/libkst/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ void Vector::blank() {
updateScalars();
}

void Vector::setValue(int index, double value)
{
_v[index] = value;
internalUpdate();
}


bool Vector::resize(int sz, bool init) {
if (sz > 0) {
Expand Down Expand Up @@ -595,6 +601,11 @@ bool Vector::saveable() const {
return _saveable;
}

void Vector::setSaveable(bool saveable)
{
_saveable = saveable;
}


bool Vector::editable() const {
return _editable;
Expand Down
4 changes: 4 additions & 0 deletions src/libkst/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class KSTCORE_EXPORT Vector : public Primitive
/** Make the vector truly empty. All values set to NOPOINT (NaN). */
void blank();

/** Set the value at a give index. */
void setValue(int index, double value);

/* Generally you don't need to call this */
void updateScalars();

Expand All @@ -146,6 +149,7 @@ class KSTCORE_EXPORT Vector : public Primitive
bool isScalarList() const { return _isScalarList; }

bool saveable() const;
void setSaveable(bool saveable);

bool editable() const;
void setEditable(bool editable);
Expand Down
24 changes: 15 additions & 9 deletions src/libkstapp/vectormodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ QVariant VectorModel::headerData(int section, Qt::Orientation orientation, int r

Qt::ItemFlags VectorModel::flags(const QModelIndex& index) const {
Qt::ItemFlags f = QAbstractItemModel::flags(index);
if (!_vectorList.isEmpty() || !index.isValid()) {
if (_vectorList.isEmpty() || !index.isValid()) {
return f;
}

// if (_vector->editable() && index.row() >= 0 && index.row() < _vector->length()) {
// f |= Qt::ItemIsEditable;
// }
if (_vectorList.at(index.column())->editable() && index.row() >= 0 && index.row() < _vectorList.at(index.column())->length()) {
f |= Qt::ItemIsEditable;
}

return f;
}
Expand All @@ -143,7 +143,7 @@ bool VectorModel::setData(const QModelIndex& index, const QVariant& value, int r
return QAbstractItemModel::setData(index, value, role);
}

if (!_vectorList.isEmpty() || !index.isValid() || !_vectorList.at(index.column())->editable() || index.row() < 0 || index.row() >= rowCount()) {
if (_vectorList.isEmpty() || !index.isValid() || !_vectorList.at(index.column())->editable() || index.row() < 0 || index.row() >= rowCount()) {
return false;
}

Expand All @@ -153,9 +153,10 @@ bool VectorModel::setData(const QModelIndex& index, const QVariant& value, int r
return false;
}

qDebug() << "UGLY!! Add setData API to KstVector!";
double *d = const_cast<double*>(_vectorList.at(index.column())->value());
d[index.row()] = v;
// qDebug() << "UGLY!! Add setData API to KstVector!";
// double *d = const_cast<double*>(_vectorList.at(index.column())->value());
// d[index.row()] = v;
vectorAtIndex(index.column())->setValue(index.row(), v);
return true;
}

Expand All @@ -167,7 +168,12 @@ void VectorModel::resetIfChanged() {
}

void VectorModel::setDigitNumber(int column, int nbDigits) {
_digitNbList[column] = nbDigits;
_digitNbList[column] = nbDigits;
}

VectorPtr VectorModel::vectorAtIndex(int index)
{
return _vectorList.at(index);
}

}
Expand Down
2 changes: 2 additions & 0 deletions src/libkstapp/vectormodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class VectorModel : public QAbstractTableModel
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
void resetIfChanged();
void setDigitNumber(int column, int nbDigits);
VectorPtr vectorAtIndex(int index);

private:
VectorList _vectorList;
QList<int> _digitNbList;
Expand Down
13 changes: 13 additions & 0 deletions src/libkstapp/viewvectordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void ViewVectorDialog::contextMenu(const QPoint& position) {
QMenu menu;
QPoint cursor = QCursor::pos();
QAction* removeAction = menu.addAction(tr("Remove"));
QAction* makeEditableAction = menu.addAction(tr("Make editable"));
// Add submenu to select nb of digits
QMenu* submenu = new QMenu(tr("Significant digits"));
QAction* digitNb0Action = submenu->addAction(tr("Show as int"));
Expand All @@ -120,6 +121,9 @@ void ViewVectorDialog::contextMenu(const QPoint& position) {
if (selectedItem == removeAction) {
removeSelected();
return;
} else if (selectedItem == makeEditableAction) {
makeEditable();
return;
} else if (selectedItem == digitNb0Action) {
digits = 0;
} else if (selectedItem == digitNb3Action) {
Expand Down Expand Up @@ -211,6 +215,15 @@ QList<int> ViewVectorDialog::selectedColumns() {
return columns;
}

void ViewVectorDialog::makeEditable() {
int column;
foreach (column, selectedColumns()) {
// VectorPtr vector = kst_cast<Vector>(_doc->objectStore()->retrieveObject(objectName));
_model->vectorAtIndex(column)->setEditable(true);
_model->vectorAtIndex(column)->setSaveData(true);
_model->vectorAtIndex(column)->setSaveable(true);
}
}

}

Expand Down
1 change: 1 addition & 0 deletions src/libkstapp/viewvectordialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private Q_SLOTS:
void reset();
void showVectorList();
void hideVectorList();
void makeEditable();

private:
QList<int> selectedColumns();
Expand Down