3.3 Wrappers for QwtArray<T>

PyQwt has a partial interface to the following C++ QwtArray templates:

  1. QwtArrayDouble for QwtArray<double>
  2. QwtArrayInt for QwtArray<int>
  3. QwtArrayLong for QwtArray<long>
  4. QwtArrayQwtDoublePoint for QwtArray<QwtDoublePoint>

Those classes have at least 3 constructors - taking QwtArrayDouble as an example:

  1. array = QwtArrayDouble()
  2. array = QwtArrayDouble(int)
  3. array = QwtArrayDouble(otherArray)

QwtArrayDouble, QwtArrayInt, and QwtArrayLong have also a constructor which takes a sequence of items convertable to a C++ double, a C++ int and a C++ long:

All those classes have 16 member functions - taking QwtArrayDouble as example:

  1. array = array.assign(otherArray)
  2. item = array.at(index)
  3. index = array.bsearch(item)
  4. index = contains(item)
  5. array = otherArray.copy()
  6. result = array.count()
  7. array.detach()
  8. array = array.duplicate(otherArray)
  9. bool = array.fill(item, index=-1)
  10. index = array.find(item, index=0)
  11. bool = array.isEmpty()
  12. bool = array.isNull()
  13. bool = array.resize(index)
  14. result = array.size()
  15. array.sort()
  16. bool = array.truncate(index)

Iterators are not yet implemented. However, the implementation of the Python slots __getitem__, __len__ and __setitem__ let you use those classes almost as a sequence. For instance:

>>> import Qwt4 as Qwt
>>> import numpy as NP
>>> a = Qwt.QwtArrayDouble(NP.arange(10, 20, 4))
>>> for i in a:                                  # thanks to __getitem__
...  print i
...
10.0
14.0
18.0
>>> for i in range(len(a)):                      # thanks to __len__
...  print a[i]                                  # thanks to __getitem__
...
10.0
14.0
18.0
>>> for i in range(len(a)):                      # thanks to __len__
...  a[i] = 10+3*i                               # thanks to __setitem__
...
>>> for i in a:                                  # thanks to __getitem__
...  print i
...
10.0
13.0
16.0
>>>