diff --git a/uppsrc/CtrlLib/CtrlUtil.cpp b/uppsrc/CtrlLib/CtrlUtil.cpp index e859ebbff..1aca37b8b 100644 --- a/uppsrc/CtrlLib/CtrlUtil.cpp +++ b/uppsrc/CtrlLib/CtrlUtil.cpp @@ -301,6 +301,36 @@ void IdCtrls::Set(const ValueMap& m) item[i].ctrl->SetData(m[item[i].id]); } +bool IdCtrls::Accept() +{ + for(int i = 0; i < item.GetCount(); i++) + if(!item[i].ctrl->Accept()) return false; + return true; +} + +void IdCtrls::ClearModify() { + for(int i = 0; i < item.GetCount(); i++) + item[i].ctrl->ClearModify(); +} + +bool IdCtrls::IsModified() { + for(int i = 0; i < item.GetCount(); i++) + if(item[i].ctrl->IsModified()) return true; + return false; +} + +void IdCtrls::Enable(bool b) +{ + for(int i = 0; i < item.GetCount(); i++) + item[i].ctrl->Enable(b); +} + +void IdCtrls::SetNull() +{ + for(int i = 0; i < item.GetCount(); i++) + item[i].ctrl->SetData(Null); +} + void Set(ArrayCtrl& array, int ii, IdCtrls& m) { for(int i = 0; i < m.GetCount(); i++) @@ -313,6 +343,20 @@ void Get(ArrayCtrl& array, int ii, IdCtrls& m) m[i] <<= array.Get(ii, m(i)); } +Event<> IdCtrls::operator<<(Event<> action) +{ + for(int i = 0; i < item.GetCount(); i++) + item[i].ctrl->WhenAction << action; + return action; +} + +Event<> IdCtrls::operator^=(Event<> action) +{ + for(int i = 0; i < item.GetCount(); i++) + item[i].ctrl->WhenAction = action; + return action; +} + String sProfile(const MemoryProfile& mem) { return AsString(mem); diff --git a/uppsrc/CtrlLib/CtrlUtil.h b/uppsrc/CtrlLib/CtrlUtil.h index e35d86f0e..f56527a7c 100644 --- a/uppsrc/CtrlLib/CtrlUtil.h +++ b/uppsrc/CtrlLib/CtrlUtil.h @@ -444,6 +444,7 @@ void CtrlRetriever::Put(Ctrl& ctrl, T& val) } class IdCtrls { +protected: struct Item { Id id; Ctrl *ctrl; @@ -453,16 +454,28 @@ class IdCtrls { public: void Reset() { item.Clear(); } - void Add(Id id, Ctrl& ctrl); - IdCtrls& operator()(Id id, Ctrl& ctrl) { Add(id, ctrl); return *this; } - int GetCount() const { return item.GetCount(); } - Ctrl& operator[](int i) { return *item[i].ctrl; } - const Ctrl& operator[](int i) const { return *item[i].ctrl; } - Id GetKey(int i) const { return item[i].id; } - Id operator()(int i) const { return item[i].id; } + void Add(Id id, Ctrl& ctrl); + IdCtrls& operator()(Id id, Ctrl& ctrl) { Add(id, ctrl); return *this; } + int GetCount() const { return item.GetCount(); } + Ctrl& operator[](int i) { return *item[i].ctrl; } + const Ctrl& operator[](int i) const { return *item[i].ctrl; } + Id GetKey(int i) const { return item[i].id; } + Id operator()(int i) const { return item[i].id; } - ValueMap Get() const; - void Set(const ValueMap& m); + bool Accept(); + void ClearModify(); + bool IsModified(); + void Enable(bool b = true); + void Disable() { Enable(false); } + void SetNull(); + + Event<> operator<<(Event<> action); + Event<> operator^=(Event<> action); + + ValueMap Get() const; + void Set(const ValueMap& m); + ValueMap operator~() const { return Get(); } + const ValueMap& operator<<=(const ValueMap& m) { Set(m); return m; } }; class FileSelButton : public FileSel diff --git a/uppsrc/CtrlLib/src.tpp/IdCtrls$en-us.tpp b/uppsrc/CtrlLib/src.tpp/IdCtrls$en-us.tpp index 45b68a4ec..b64d1424b 100644 --- a/uppsrc/CtrlLib/src.tpp/IdCtrls$en-us.tpp +++ b/uppsrc/CtrlLib/src.tpp/IdCtrls$en-us.tpp @@ -47,6 +47,44 @@ onst]&] _[@(0.0.255) const]&] [s2;%% Returns the identifier of entry [%-*@3 i].&] [s3;%% &] +[s4; &] +[s5;:Upp`:`:IdCtrls`:`:Accept`(`): [@(0.0.255) bool]_[* Accept]()&] +[s2;%% Calls Accept of all widgets. If any widget returns false, +returns false. Otherwise returns true.&] +[s3; &] +[s4; &] +[s5;:Upp`:`:IdCtrls`:`:ClearModify`(`): [@(0.0.255) void]_[* ClearModify]()&] +[s2;%% Clear the `'modified`' flag of all widgets.&] +[s3; &] +[s4; &] +[s5;:Upp`:`:IdCtrls`:`:IsModified`(`): [@(0.0.255) bool]_[* IsModified]()&] +[s2;%% Returns true if any widget has `'modified`' flag set.&] +[s3; &] +[s2;%% Enables/disable.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:IdCtrls`:`:Enable`(bool`): [@(0.0.255) void]_[* Enable]([@(0.0.255) bool]_[*@3 b +][@(0.0.255) `= true])&] +[s2;%% Enables/disables all widgets.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:IdCtrls`:`:Disable`(`): [@(0.0.255) void]_[* Disable]()&] +[s2;%% Same as Enable(false).&] +[s3; &] +[s4; &] +[s5;:Upp`:`:IdCtrls`:`:SetNull`(`): [@(0.0.255) void]_[* SetNull]()&] +[s2;%% Sets Null (using SetData) to all widgets.&] +[s3; &] +[s4; &] +[s5;:Upp`:`:IdCtrls`:`:operator`<`<`(Upp`:`:Event`<`>`): [_^Upp`:`:Event^ Event]<>_[* ope +rator<<]([_^Upp`:`:Event^ Event]<>_[*@3 action])&] +[s2;%% Adds [%-*@3 action] to WhenAction events of all widgets.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:IdCtrls`:`:operator`^`=`(Upp`:`:Event`<`>`): [_^Upp`:`:Event^ Event]<>_[* ope +rator`^`=]([_^Upp`:`:Event^ Event]<>_[*@3 action])&] +[s2;%% Sets [%-*@3 action] as WhenAction event of all widgets.&] +[s3;%% &] [s4;%% &] [s5;:IdCtrls`:`:Get`(`)const: [_^ValueMap^ ValueMap]_[* Get]()_[@(0.0.255) const]&] [s2;%% Creates a map, where keys are identifiers of entries and values @@ -57,4 +95,14 @@ are obtained from respective widgets using GetData method.&] alueMap][@(0.0.255) `&]_[*@3 m])&] [s2;%% Sets value of widgets using SetData to values in map, using keys of map to identify the target widgets.&] +[s4; &] +[s5;:Upp`:`:IdCtrls`:`:operator`~`(`)const: [_^Upp`:`:ValueMap^ ValueMap]_[* operator`~]( +)_[@(0.0.255) const]&] +[s2;%% Same as Get().&] +[s3; &] +[s4; &] +[s5;:Upp`:`:IdCtrls`:`:operator`<`<`=`(const Upp`:`:ValueMap`&`): [@(0.0.255) const]_[_^Upp`:`:ValueMap^ V +alueMap][@(0.0.255) `&]_[* operator<<`=]([@(0.0.255) const]_[_^Upp`:`:ValueMap^ ValueMap][@(0.0.255) `& +]_[*@3 m])&] +[s2;%% Same as Set([%-*@3 m]).&] [s0;%% ]] \ No newline at end of file diff --git a/uppsrc/SqlCtrl/SqlCtrl.cpp b/uppsrc/SqlCtrl/SqlCtrl.cpp index 6129fcbf0..6994c9896 100644 --- a/uppsrc/SqlCtrl/SqlCtrl.cpp +++ b/uppsrc/SqlCtrl/SqlCtrl.cpp @@ -65,12 +65,6 @@ Value SqlNOption::GetData() const return Null; } -void SqlCtrls::Add(SqlId id, Ctrl& ctrl) { - Item& m = item.Add(); - m.id = id; - m.ctrl = &ctrl; -} - void SqlCtrls::Table(Ctrl& dlg, SqlId table) { Vector col = GetSchColumns(~table); @@ -84,7 +78,7 @@ void SqlCtrls::Table(Ctrl& dlg, SqlId table) SqlSet SqlCtrls::Set() const { SqlSet set; for(int i = 0; i < item.GetCount(); i++) - set.Cat(item[i].id); + set.Cat(SqlId(item[i].id)); return set; } @@ -92,7 +86,7 @@ void SqlCtrls::Read(Sql& sql) { for(int i = 0; i < item.GetCount(); i++) { Item& m = item[i]; - m.ctrl->SetData(sql[m.id]); + m.ctrl->SetData(sql[SqlId(m.id)]); } } @@ -136,44 +130,6 @@ SqlUpdate SqlCtrls::UpdateModified(SqlId table) const { return update; } -bool SqlCtrls::Accept() -{ - for(int i = 0; i < item.GetCount(); i++) - if(!item[i].ctrl->Accept()) return false; - return true; -} - -void SqlCtrls::ClearModify() { - for(int i = 0; i < item.GetCount(); i++) - item[i].ctrl->ClearModify(); -} - -bool SqlCtrls::IsModified() { - for(int i = 0; i < item.GetCount(); i++) - if(item[i].ctrl->IsModified()) return true; - return false; -} - -void SqlCtrls::Enable(bool b) -{ - for(int i = 0; i < item.GetCount(); i++) - item[i].ctrl->Enable(b); -} - -ValueMap SqlCtrls::Get() const -{ - ValueMap m; - for(int i = 0; i < item.GetCount(); i++) - m.Add(item[i].id, item[i].ctrl->GetData()); - return m; -} - -void SqlCtrls::SetNull() -{ - for(int i = 0; i < item.GetCount(); i++) - item[i].ctrl->SetData(Null); -} - Callback SqlCtrls::operator<<=(Callback cb) { for(int i = 0; i < item.GetCount(); i++) diff --git a/uppsrc/SqlCtrl/SqlCtrl.h b/uppsrc/SqlCtrl/SqlCtrl.h index 6b4d7ecef..40e2ddc93 100644 --- a/uppsrc/SqlCtrl/SqlCtrl.h +++ b/uppsrc/SqlCtrl/SqlCtrl.h @@ -139,15 +139,8 @@ public: SqlArray(); }; -class SqlCtrls { - struct Item { - SqlId id; - Ctrl *ctrl; - }; - Array item; - +class SqlCtrls : public IdCtrls { public: - void Add(SqlId id, Ctrl& ctrl); SqlCtrls& operator()(SqlId id, Ctrl& ctrl) { Add(id, ctrl); return *this; } void Table(Ctrl& dlg, SqlId table); SqlCtrls& operator()(Ctrl& dlg, SqlId table) { Table(dlg, table); return *this; } @@ -155,15 +148,11 @@ public: operator SqlSet() const { return Set(); } void Read(Sql& sql); bool Fetch(Sql& sql); -#ifndef NOAPPSQL - bool Fetch() { return Fetch(SQL); } -#endif - bool Load(Sql& sql, SqlSelect set) { sql * set; return Fetch(sql); } -#ifndef NOAPPSQL - bool Load(SqlSelect set) { return Load(SQL, set); } -#endif + bool Load(Sql& sql, SqlSelect select) { sql * select; return Fetch(sql); } bool Load(Sql& sql, SqlId table, SqlBool where); #ifndef NOAPPSQL + bool Fetch() { return Fetch(SQL); } + bool Load(SqlSelect select) { return Load(SQL, select); } bool Load(SqlId table, SqlBool where); #endif void Insert(SqlInsert& insert) const; @@ -172,23 +161,12 @@ public: SqlInsert Insert(SqlId table) const; SqlUpdate Update(SqlId table) const; SqlUpdate UpdateModified(SqlId table) const; - bool Accept(); - void ClearModify(); - bool IsModified(); - void Enable(bool b = true); - void Disable() { Enable(false); } - void SetNull(); - Callback operator<<=(Callback cb); - int GetCount() const { return item.GetCount(); } - Ctrl& operator[](int i) { return *item[i].ctrl; } - const Ctrl& operator[](int i) const { return *item[i].ctrl; } SqlId operator()(int i) const { return item[i].id; } SqlId GetKey(int i) const { return item[i].id; } - ValueMap Get() const; - - void Reset() { item.Clear(); } +//deprecated: + Callback operator<<=(Callback cb); }; class SqlDetail : public StaticRect { diff --git a/uppsrc/SqlCtrl/src.tpp/SqlCtrls$en-us.tpp b/uppsrc/SqlCtrl/src.tpp/SqlCtrls$en-us.tpp new file mode 100644 index 000000000..12363e040 --- /dev/null +++ b/uppsrc/SqlCtrl/src.tpp/SqlCtrls$en-us.tpp @@ -0,0 +1,137 @@ +topic ""; +[2 $$0,0#00000000000000000000000000000000:Default] +[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] +[l288;2 $$2,2#27521748481378242620020725143825:desc] +[0 $$3,0#96390100711032703541132217272105:end] +[H6;0 $$4,0#05600065144404261032431302351956:begin] +[i448;a25;kKO9;2 $$5,0#37138531426314131252341829483370:item] +[l288;a4;*@5;1 $$6,6#70004532496200323422659154056402:requirement] +[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] +[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] +[b42;2 $$9,9#13035079074754324216151401829390:normal] +[{_} +[ {{10000@(113.42.0) [s0;%% [*@7;4 SqlCtrls]]}}&] +[s9; &] +[s1;:Upp`:`:SqlCtrls`:`:class: [@(0.0.255)3 class][3 _][*3 SqlCtrls][3 _:_][@(0.0.255)3 public][3 _ +][*@3;3 IdCtrls]&] +[s2;%% This class extends [^topic`:`/`/CtrlLib`/src`/IdCtrls`$en`-us^ IdCtrls] +class with SQL related operations.&] +[s0;i448;a25;kKO9;:noref:@(0.0.255) &] +[ {{10000F(128)G(128)@1 [s0;%% [* Public Method List]]}}&] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:operator`(`)`(Upp`:`:SqlId`,Upp`:`:Ctrl`&`): [_^Upp`:`:SqlCtrls^ S +qlCtrls][@(0.0.255) `&]_[* operator()]([_^Upp`:`:SqlId^ SqlId]_[*@3 id], +[_^Upp`:`:Ctrl^ Ctrl][@(0.0.255) `&]_[*@3 ctrl])&] +[s2;%% Calls IdCtrls`::Add([%-*@3 id], [%-*@3 ctrl]).&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Table`(Upp`:`:Ctrl`&`,Upp`:`:SqlId`): [@(0.0.255) void]_[* Table]( +[_^Upp`:`:Ctrl^ Ctrl][@(0.0.255) `&]_[*@3 dlg], [_^Upp`:`:SqlId^ SqlId]_[*@3 table])&] +[s2;%% Adds such widgets of [%-*@3 dlg] whose layout id (that is the +same as the id of theirs member variable) matches any column +name in [%-*@3 table], based on database schema file (.sch). Widgets +are added with uppercased layout id. Label and Button widget +are excluded (tested using dynamic`_cast)&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:operator`(`)`(Upp`:`:Ctrl`&`,Upp`:`:SqlId`): [_^Upp`:`:SqlCtrls^ S +qlCtrls][@(0.0.255) `&]_[* operator()]([_^Upp`:`:Ctrl^ Ctrl][@(0.0.255) `&]_[*@3 dlg], +[_^Upp`:`:SqlId^ SqlId]_[*@3 table])&] +[s2;%% Same as Table([%-*@3 dlg], [%-*@3 table]).&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Set`(`)const: [_^Upp`:`:SqlSet^ SqlSet]_[* Set]()_[@(0.0.255) const +]&] +[s2;%% Returns SqlSet of all ids of SqlCtrls.&] +[s3; &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:operator SqlSet`(`)const: [* operator_SqlSet]()_[@(0.0.255) const +]&] +[s2;%% Same as Set().&] +[s3; &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Read`(Upp`:`:Sql`&`): [@(0.0.255) void]_[* Read]([_^Upp`:`:Sql^ Sql +][@(0.0.255) `&]_[*@3 sql])&] +[s2;%% Assigns values of [%-*@3 sql] (which is supposed to contain +some fetched line from SQL database) into widgets, based on match +of widget ids and column names.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Fetch`(Upp`:`:Sql`&`): [@(0.0.255) bool]_[* Fetch]([_^Upp`:`:Sql^ S +ql][@(0.0.255) `&]_[*@3 sql])&] +[s2;%% Does [%-*@3 sql].Fetch(). If that is false, returns false, otherwise +performs Read(sql) and returns true. In other words, fetches +the line from SQL database and assigns corresponding values to +SqlCtrls widgets.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Load`(Upp`:`:Sql`&`,Upp`:`:SqlSelect`): [@(0.0.255) bool]_[* Load +]([_^Upp`:`:Sql^ Sql][@(0.0.255) `&]_[*@3 sql], [_^Upp`:`:SqlSelect^ SqlSelect]_[*@3 select +])&] +[s2;%% Executes [%-*@3 select] statement on [%-*@3 sql] and then calls +Fetch([%-*@3 sql]) and returns its return value.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Load`(Upp`:`:Sql`&`,Upp`:`:SqlId`,Upp`:`:SqlBool`): [@(0.0.255) b +ool]_[* Load]([_^Upp`:`:Sql^ Sql][@(0.0.255) `&]_[*@3 sql], [_^Upp`:`:SqlId^ SqlId]_[*@3 tabl +e], [_^Upp`:`:SqlBool^ SqlBool]_[*@3 where])&] +[s2;%% Similar to Load, but [%-*@3 select] statement is constructed +based on ids of widgets, given [%-*@3 table] and [%-*@3 where] expression.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Fetch`(`): [@(0.0.255) bool]_[* Fetch]()&] +[s2;%% Same as Fetch(SQL).&] +[s3; &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Load`(Upp`:`:SqlSelect`): [@(0.0.255) bool]_[* Load]([_^Upp`:`:SqlSelect^ S +qlSelect]_[*@3 select])&] +[s2;%% Same as Load(SQL, [%-*@3 select]).&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Load`(Upp`:`:SqlId`,Upp`:`:SqlBool`): [@(0.0.255) bool]_[* Load]( +[_^Upp`:`:SqlId^ SqlId]_[*@3 table], [_^Upp`:`:SqlBool^ SqlBool]_[*@3 set])&] +[s2;%% Same as Load(SQL, [%-*@3 table], [%-*@3 set]).&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Insert`(Upp`:`:SqlInsert`&`)const: [@(0.0.255) void]_[* Insert]([_^Upp`:`:SqlInsert^ S +qlInsert][@(0.0.255) `&]_[*@3 insert])_[@(0.0.255) const]&] +[s2;%% Adds all id `- widget value pairs to [%-*@3 insert].&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Update`(Upp`:`:SqlUpdate`&`)const: [@(0.0.255) void]_[* Update]([_^Upp`:`:SqlUpdate^ S +qlUpdate][@(0.0.255) `&]_[*@3 update])_[@(0.0.255) const]&] +[s2;%% Adds all id `- widget value pairs to [%-*@3 update].&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:UpdateModified`(Upp`:`:SqlUpdate`&`)const: [@(0.0.255) void]_[* U +pdateModified]([_^Upp`:`:SqlUpdate^ SqlUpdate][@(0.0.255) `&]_[*@3 update])_[@(0.0.255) c +onst]&] +[s2;%% Adds all id `- widget value pairs, where widgets have `'modified`' +flag set, to [%-*@3 update] .&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Insert`(Upp`:`:SqlId`)const: [_^Upp`:`:SqlInsert^ SqlInsert]_[* I +nsert]([_^Upp`:`:SqlId^ SqlId]_[*@3 table])_[@(0.0.255) const]&] +[s2;%% Constructs SqlInsert statement into [%-*@3 table] which contains +all id `- widget value pairs as inserted values.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:Update`(Upp`:`:SqlId`)const: [_^Upp`:`:SqlUpdate^ SqlUpdate]_[* U +pdate]([_^Upp`:`:SqlId^ SqlId]_[*@3 table])_[@(0.0.255) const]&] +[s2;%% Constructs SqlUpdate statement of [%-*@3 table] which contains +all id `- widget value pairs as updated values.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:UpdateModified`(Upp`:`:SqlId`)const: [_^Upp`:`:SqlUpdate^ SqlUp +date]_[* UpdateModified]([_^Upp`:`:SqlId^ SqlId]_[*@3 table])_[@(0.0.255) const]&] +[s2;%% Constructs SqlUpdate statement of [%-*@3 table] which contains +all id `- widget value pairs, where widgets have `'modified`' +flag set, as updated values.&] +[s3;%% &] +[s4; &] +[s5;:Upp`:`:SqlCtrls`:`:operator`(`)`(int`)const: [_^Upp`:`:SqlId^ SqlId]_[* operator()]( +[@(0.0.255) int]_[*@3 i])_[@(0.0.255) const]&] +[s5;:Upp`:`:SqlCtrls`:`:GetKey`(int`)const: [_^Upp`:`:SqlId^ SqlId]_[* GetKey]([@(0.0.255) i +nt]_[*@3 i])_[@(0.0.255) const]&] +[s2;%% Returns id of entry [%-*@3 i].&] +[s0;%% ]] \ No newline at end of file