kspread
BindingManager.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "BindingManager.h"
00021
00022 #include "BindingStorage.h"
00023 #include "CellStorage.h"
00024 #include "Map.h"
00025 #include "Region.h"
00026 #include "Sheet.h"
00027
00028 #include <QAbstractItemModel>
00029
00030 using namespace KSpread;
00031
00032 class BindingManager::Private
00033 {
00034 public:
00035 const Map* map;
00036 };
00037
00038 BindingManager::BindingManager(const Map* map)
00039 : d(new Private)
00040 {
00041 d->map = map;
00042 }
00043
00044 BindingManager::~BindingManager()
00045 {
00046 delete d;
00047 }
00048
00049 const QAbstractItemModel* BindingManager::createModel(const QString& regionName)
00050 {
00051 const Region region(regionName, d->map);
00052 if (!region.isValid() || !region.isContiguous() || !region.firstSheet()) {
00053 return 0;
00054 }
00055 Binding binding(region);
00056 region.firstSheet()->cellStorage()->setBinding(region, binding);
00057 return binding.model();
00058 }
00059
00060 bool BindingManager::removeModel(const QAbstractItemModel* model)
00061 {
00062 QList< QPair<QRectF, Binding> > bindings;
00063 const QRect rect(QPoint(1, 1), QPoint(KS_colMax, KS_rowMax));
00064 const QList<Sheet*> sheets = d->map->sheetList();
00065 for (int i = 0; i < sheets.count(); ++i) {
00066 Sheet* const sheet = sheets[i];
00067 bindings = sheet->cellStorage()->bindingStorage()->intersectingPairs(Region(rect, sheet));
00068 for (int j = 0; j < bindings.count(); ++j) {
00069 if (bindings[j].second.model() == model) {
00070 const Region region(bindings[j].first.toRect(), sheet);
00071 sheet->cellStorage()->removeBinding(region, bindings[j].second);
00072 return true;
00073 }
00074 }
00075 }
00076 return false;
00077 }
00078
00079 bool BindingManager::isCellRegionValid(const QString& regionName) const
00080 {
00081 const Region region(regionName, d->map);
00082 return (region.isValid() && region.isContiguous() && region.firstSheet());
00083 }
00084
00085 void BindingManager::regionChanged(const Region& region)
00086 {
00087 Sheet* sheet;
00088 QList< QPair<QRectF, Binding> > bindings;
00089 Region::ConstIterator end(region.constEnd());
00090 for (Region::ConstIterator it = region.constBegin(); it != end; ++it)
00091 {
00092 sheet = (*it)->sheet();
00093 bindings = sheet->cellStorage()->bindingStorage()->intersectingPairs(Region((*it)->rect(), sheet));
00094 for (int j = 0; j < bindings.count(); ++j)
00095 bindings[j].second.update(region);
00096 }
00097 }
00098
00099 void BindingManager::updateAllBindings()
00100 {
00101 QList< QPair<QRectF, Binding> > bindings;
00102 const QRect rect(QPoint(1, 1), QPoint(KS_colMax, KS_rowMax));
00103 const QList<Sheet*> sheets = d->map->sheetList();
00104 for (int i = 0; i < sheets.count(); ++i)
00105 {
00106 bindings = sheets[i]->cellStorage()->bindingStorage()->intersectingPairs(Region(rect, sheets[i]));
00107 for (int j = 0; j < bindings.count(); ++j)
00108 bindings[j].second.update(Region(bindings[j].first.toRect(), sheets[i]));
00109 }
00110 }
00111
00112 #include "BindingManager.moc"
|