Bug 427532 - On changing Code -> Active Language the previous default data types are not removed
Summary: On changing Code -> Active Language the previous default data types are not r...
Status: RESOLVED FIXED
Alias: None
Product: umbrello
Classification: Applications
Component: general (show other bugs)
Version: Git
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Umbrello Development Group
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-11 07:50 UTC by Oliver Kellogg
Modified: 2021-02-11 23:37 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 2.33.80 (KDE releases 21.03.80)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Kellogg 2020-10-11 07:50:06 UTC
SUMMARY
On changing Code -> Active Language the previous default data types are not removed.

STEPS TO REPRODUCE
1. Start Umbrello.
2. In the tree view open the Views -> Logical View -> Datatypes folder. You will see the list starting with types "bool", "char", "double", "float", "int", ...
2. Select Code -> Active Language -> Pascal.
3. Again open the Datatypes folder in the tree view. You will see the list starting with "AnsiString", "bool", "Boolean", "Byte", "ByteBool", "Cardinal", "char", ...

OBSERVED RESULT
The types from the previous active language are not removed
(in the given example of C++: "bool", "char", "double", ...)

EXPECTED RESULT
The types from the previous active language shall no longer appear in the Datatypes folder.
Comment 1 Oliver Kellogg 2020-10-11 09:50:12 UTC
We cannot remove the previous default data types from the Document (UMLDoc):

Imagine having made a large C++ specific model with Active Language C++.
Accidentally you change the Active Language to non C++.
If the default types were removed from the Document then all references to those types would be left dangling.
Changing back to Active Language C++ would not fix the dangling references because new default type objects would be constructed.

Therefore, the strategy is as follows:

* Class UMLDatatype gets a new flag, isActive, initialized to true by default.
* When user changes Active Language, before the new default types are added the existing default types are queried at the Document and their isActive flag is set false. No deallocation of those types is performed.
* The function UMLPackage::containedObjects is changed as follows: If a contained object is a UMLDatatype then its isActive flag is queried. If isActive is true then it is not placed into the returned list.
* When user changes Active Language back to its original value, the default types of that language are queried at the Document and their isActive flag is restored to true. The existing UMLDatatype objects are reused (no new allocation takes place).
* The isActive flag is also saved to and loaded from the <UML:DataType> XMI element.
Comment 2 Oliver Kellogg 2020-10-11 20:57:22 UTC
Git commit 9817ffc9eeef527181ee40904e76352796f4955a by Oliver Kellogg.
Committed on 11/10/2020 at 20:54.
Pushed by okellogg into branch 'master'.

https://bugs.kde.org/show_bug.cgi?id=427532#c1
Remove default datatypes of previous Active Language:

umbrello/uml1model/datatype.{h,cpp}
- Add member variable m_isActive initialized to true by constructor.
- Add accessor functions setActive(bool active = true), isActive().
- Peripheral cleanup: Override function load1 in lieu of loadFromXMI1.

umbrello/uml1model/datatype.cpp
- In function load1, set m_isActive true if XMI attribute "isActive"
  does not exist or if its value is not "false".
- In function saveToXMI1, setAttribute "isActive" to "false" on the
  classifierElement if m_isActive is false.

umbrello/uml1model/package.{h,cpp}
- At function containedObjects add optional argument includeInactive
  of type bool defaulting to false.  If includeInactive is true then
  include datatypes with isActive() false in the returned list.

umbrello/uml1model/package.cpp
- In function removeObject do not delete a datatype from its package
  but just set its isActive flag false.

umbrello/uml1model/folder.cpp
- In function load1 avoid duplicate creation of datatype when its name
  already exists in m_objects.

umbrello/umldoc.{h,cpp}
- At function datatypes() add optional argument includeInactive of type
  bool defaulting to false.  If includeInactive is true then include
  datatypes which have isActive() == false in the returned list.
- New function removeDatatype(const QString &name) removes a datatype
  from m_datatypeRoot->containedObjects() by name.

umbrello/umldoc.cpp
- In function createDatatype,
  - at call to m_datatypeRoot->containedObjects() provide argument
    includeInactive = true;
  - if Model_Utils::findUMLObject() returns non null and the retuned
    object is a UMLDatatype then set its isActive flag to true and emit
    sigObjectCreated; do not call Object_Factory::createUMLObject().

umbrello/uml.cpp
- In function setGenerator, if m_codegen is non null on entry then query
  m_codegen->defaultDatatypes() and call m_doc->removeDatatype() for
  each name returned.

umbrello/umllistview.cpp
- In function slotObjectCreated, if object->baseType() is ot_Datatype
  then check that the isActive flag is true; else refuse to create the
  UMLListViewItem.

umbrello/main.cpp
- At function initDocument :
  - Add argument progLang of type Uml::ProgrammingLanguage::Enum.
  - If UMLApp::app()->newDocument() is called then follow it by
    UMLApp::app()->setActiveLanguage(progLang).
  - If a file shall be opened, the programming language set by the
    <XMI.extensions> <codegeneration> element in the file shall take
    precedence over the language set via command line parameter,
    therefore do not call UMLApp::app()->setActiveLanguage.
- Adjust main program to change of function initDocument.

umbrello/version.h
- Increase XMI_FILE_VERSION to "1.6.19" due to the <UML:DataType> new
  attribute "isActive".

M  +4    -4    umbrello/main.cpp
M  +5    -0    umbrello/uml.cpp
M  +29   -7    umbrello/uml1model/datatype.cpp
M  +5    -1    umbrello/uml1model/datatype.h
M  +17   -0    umbrello/uml1model/folder.cpp
M  +39   -4    umbrello/uml1model/package.cpp
M  +1    -1    umbrello/uml1model/package.h
M  +31   -5    umbrello/umldoc.cpp
M  +2    -1    umbrello/umldoc.h
M  +9    -1    umbrello/umllistview.cpp
M  +1    -1    umbrello/version.h

https://invent.kde.org/sdk/umbrello/commit/9817ffc9eeef527181ee40904e76352796f4955a