Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ManiVault variant map for serialization #552

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ThomasKroes
Copy link
Contributor

@ThomasKroes ThomasKroes commented Mar 19, 2024

PR features

  • Adds mv::VariantMap for use in serialization functions (to have ultimate control over how data is serialized)
  • Use it in WidgetAction::fromVariantMap(...) and WidgetAction::toVariantMap()
  • Write a script to replace QVariantMap to mv::VariantMap when needed and some additional replacements
  • Add suffix the ManiVault version printed in the console

Note for plugin developers

Below is a PowerShell script to perform all the necessary replacements in serialization API calls:
# Check if the directory argument is provided
if ($args.Length -lt 1) {
    Write-Host "Usage: replace_mv_variant.ps1 <directory>"
    exit 1
}

# Get the directory from the command-line arguments
$directory = $args[0]

# Validate the directory
if (-not (Test-Path -Path $directory -PathType Container)) {
    Write-Host "Error: Directory '$directory' does not exist."
    exit 1
}

# Define an array of regular expression patterns with corresponding replacement patterns
$patterns = @(
    @{Pattern = "(?:virtual\s*)?(void\s*fromVariantMap\(const\s*)(QVariantMap)(&\s*variantMap\)\s*(?:override)?)"; Replacement = '$1mv::VariantMap$3'},
    @{Pattern = "(?:virtual\s*)?(QVariantMap)(\s*toVariantMap\(\)\s*const\s*(?:override)?)"; Replacement = 'mv::VariantMap$2'},
	@{Pattern = "(void\s*\w+::fromVariantMap\s*\(\s*const\s*)(QVariantMap)(&\s*variantMap\))"; Replacement = '$1mv::VariantMap$3'},
	@{Pattern = "(QVariantMap)(\s*\w+::toVariantMap\(\)\s*const)"; Replacement = 'mv::VariantMap$2'},
	@{Pattern = "(QVariantMap)(\s*variantMap\s*=\s*\w+::toVariantMap\(\))"; Replacement = 'auto$2'}
)

# Get a list of files in the directory and its subdirectories
Get-ChildItem -Path $directory -File -Recurse | ForEach-Object {
	Write-Host "Processing file: $($_.Name)"
	
	# Read the content of each file
    $content = Get-Content $_.FullName
		
	# Perform each replacement using regular expressions and match groups
	foreach ($pattern in $patterns) {
        $newContent = $content -replace $pattern.Pattern, $pattern.Replacement
        $content 	= $newContent
    }
	
	# Write the modified content back to the file
    $content | Set-Content $_.FullName
}

To run the script:
.\replace_mv_variant_map.ps1 .\DevBundle\allmain\source\ImageViewerPlugin\src\

Use this class in serialization routines
@ThomasKroes ThomasKroes added the enhancement New feature or request label Mar 19, 2024
@ThomasKroes ThomasKroes self-assigned this Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant