Commit d1b3f08d by maarten

When updating a value, all linked child elements are renamed too.

git-svn-id: svn+ssh://gitlab/srv/svn-repos/pdb-redo/trunk@407 a1961a4f-ab94-4bcc-80e8-33b5a54de466
parent 9a7aeed6
...@@ -1137,6 +1137,8 @@ class Category ...@@ -1137,6 +1137,8 @@ class Category
const Validator& getValidator() const; const Validator& getValidator() const;
const ValidateCategory* getCatValidator() const { return mCatValidator; } const ValidateCategory* getCatValidator() const { return mCatValidator; }
Datablock& db() { return mDb; }
void setValidator(Validator* v); void setValidator(Validator* v);
iset fields() const; iset fields() const;
......
...@@ -113,6 +113,7 @@ struct ValidateCategory ...@@ -113,6 +113,7 @@ struct ValidateCategory
struct ValidateLink struct ValidateLink
{ {
int mLinkGroupId;
std::string mParentCategory; std::string mParentCategory;
std::vector<std::string> mParentKeys; std::vector<std::string> mParentKeys;
std::string mChildCategory; std::string mChildCategory;
......
...@@ -2041,29 +2041,48 @@ void Row::assign(size_t column, const string& value, bool emplacing) ...@@ -2041,29 +2041,48 @@ void Row::assign(size_t column, const string& value, bool emplacing)
if (reinsert) if (reinsert)
cat->mIndex->insert(mData); cat->mIndex->insert(mData);
#pragma warning("doen!") // see if we need to update any child categories that depend on this value
// // see if we need to update any child categories that depend on this value auto iv = col.mValidator;
// auto iv = col.mValidator; if (not emplacing and iv != nullptr)
// if (not emplacing and iv != nullptr and not iv->mChildren.empty()) {
// { auto& validator = cat->getValidator();
// for (auto child: iv->mChildren) auto& db = cat->db();
// {
// if (child->mCategory == nullptr) for (auto linked: validator.getLinksForParent(cat->mName))
// continue; {
// auto childCat = db.get(linked->mChildCategory);
// auto childCat = db.get(child->mCategory->mName); if (childCat == nullptr)
// if (childCat == nullptr) continue;
// continue;
// if (find(linked->mParentKeys.begin(), linked->mParentKeys.end(), iv->mTag) == linked->mParentKeys.end())
//#if DEBUG continue;
//cerr << "fixing linked item " << child->mCategory->mName << '.' << child->mTag << endl;
//#endif Condition cond;
// string childTag;
// auto rows = childCat->find(Key(child->mTag) == oldStrValue);
// for (auto& cr: rows) for (size_t ix = 0; ix < linked->mParentKeys.size(); ++ix)
// cr.assign(child->mTag, value, false); {
// } string pk = linked->mParentKeys[ix];
// } string ck = linked->mChildKeys[ix];
if (pk == iv->mTag)
{
childTag = ck;
cond = move(cond) && (Key(ck) == oldStrValue);
}
else
{
const char* value = (*this)[pk].c_str();
cond = move(cond) && (Key(ck) == value);
}
}
auto rows = childCat->find(move(cond));
for (auto& cr: rows)
cr.assign(childTag, value, false);
}
}
} }
void Row::swap(size_t cix, ItemRow* a, ItemRow* b) void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
......
...@@ -919,7 +919,7 @@ void DictParser::linkItems() ...@@ -919,7 +919,7 @@ void DictParser::linkItems()
for (auto& kv: linkIndex) for (auto& kv: linkIndex)
{ {
ValidateLink link; ValidateLink link;
std::tie(link.mParentCategory, link.mChildCategory, std::ignore) = kv.first; std::tie(link.mParentCategory, link.mChildCategory, link.mLinkGroupId) = kv.first;
std::tie(link.mParentKeys, link.mChildKeys) = linkKeys[kv.second]; std::tie(link.mParentKeys, link.mChildKeys) = linkKeys[kv.second];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment