Skip to content

Commit 981a349

Browse files
committed
Fixing MW5CORE-190
1 parent df1f108 commit 981a349

1 file changed

Lines changed: 60 additions & 76 deletions

File tree

src/Plugins/MW5.Symbology/Views/VectorStyleView.cs

Lines changed: 60 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using MW5.Plugins.Interfaces;
1919
using MW5.Plugins.Symbology.Controls.ImageCombo;
2020
using MW5.Plugins.Symbology.Helpers;
21-
using MW5.Plugins.Symbology.Model;
2221
using MW5.Plugins.Symbology.Services;
2322
using MW5.Plugins.Symbology.Views.Abstract;
2423
using MW5.Shared;
@@ -45,8 +44,8 @@ public partial class VectorStyleView : VectorStyleViewBase, IVectorStyleView
4544

4645
public VectorStyleView(IAppContext context, CategoriesPresenter categoriesPresenter)
4746
{
48-
if (context == null) throw new ArgumentNullException("context");
49-
if (categoriesPresenter == null) throw new ArgumentNullException("categoriesPresenter");
47+
if (context == null) throw new ArgumentNullException(nameof(context));
48+
if (categoriesPresenter == null) throw new ArgumentNullException(nameof(categoriesPresenter));
5049

5150
_context = context;
5251
_categoriesPresenter = categoriesPresenter;
@@ -80,15 +79,9 @@ public IEnumerable<Control> Buttons
8079
}
8180
}
8281

83-
public ButtonBase OkButton
84-
{
85-
get { return null; }
86-
}
82+
public ButtonBase OkButton => null;
8783

88-
public bool SpatialIndex
89-
{
90-
get { return chkSpatialIndex.Checked; }
91-
}
84+
public bool SpatialIndex => chkSpatialIndex.Checked;
9285

9386
public IEnumerable<ToolStripItemCollection> ToolStrips
9487
{
@@ -105,7 +98,7 @@ public void Initialize()
10598

10699
MapConfig.ForceHideLabels = true;
107100

108-
Text = "Layer properties: " + Model.Name;
101+
Text = @"Layer properties: " + Model.Name;
109102

110103
_initState = SaveState();
111104

@@ -148,7 +141,6 @@ public void RefreshLabels()
148141
chkShowLabels.Checked = options.Visible;
149142

150143
UpdateView();
151-
152144
DrawLabelsPreview();
153145
}
154146

@@ -181,7 +173,7 @@ private void AddTooltips()
181173
/// </summary>
182174
private void CancelChanges()
183175
{
184-
string state = Model.Serialize();
176+
var state = Model.Serialize();
185177

186178
if (state != _initState)
187179
{
@@ -221,10 +213,7 @@ private void DrawAppearancePreview()
221213
var pct = pictureBox1;
222214
var sdo = _featureSet.Style;
223215

224-
if (pct.Image != null)
225-
{
226-
pct.Image.Dispose();
227-
}
216+
pct.Image?.Dispose();
228217

229218
var rect = pct.ClientRectangle;
230219
var bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
@@ -243,10 +232,10 @@ private void DrawAppearancePreview()
243232
}
244233
else
245234
{
246-
int w = rect.Width - 40;
247-
int h = rect.Height - 40;
248-
int x = Convert.ToInt32((rect.Width - w) / 2.0);
249-
int y = Convert.ToInt32((rect.Height - h) / 2);
235+
var w = rect.Width - 40;
236+
var h = rect.Height - 40;
237+
var x = Convert.ToInt32((rect.Width - w) / 2.0);
238+
var y = Convert.ToInt32((rect.Height - h) / 2);
250239
sdo.DrawLine(g, x, y, w, h, true, rect.Width, rect.Height, Color.White);
251240
}
252241
break;
@@ -255,6 +244,8 @@ private void DrawAppearancePreview()
255244
break;
256245
}
257246

247+
g.Dispose();
248+
258249
pct.Image = bmp;
259250
}
260251

@@ -269,11 +260,12 @@ private void DrawChartsPreview()
269260
var charts = _featureSet.Diagrams;
270261
if (charts.Count > 0 && charts.Fields.Any())
271262
{
272-
var g = Graphics.FromImage(bmp);
273-
274-
int x = Convert.ToInt32((rect.Width - charts.IconWidth) / 2.0);
275-
int y = Convert.ToInt32((rect.Height - charts.IconHeight) / 2.0);
276-
_featureSet.Diagrams.DrawChart(g, x, y, false, Color.White);
263+
using (var g = Graphics.FromImage(bmp))
264+
{
265+
var x = Convert.ToInt32((rect.Width - charts.IconWidth) / 2.0);
266+
var y = Convert.ToInt32((rect.Height - charts.IconHeight) / 2.0);
267+
_featureSet.Diagrams.DrawChart(g, x, y, false, Color.White);
268+
}
277269
}
278270

279271
pctCharts.Image = bmp;
@@ -352,7 +344,7 @@ private void InitGeneralTab()
352344

353345
txtLayerName.Text = Model.Name;
354346

355-
string filename = string.IsNullOrWhiteSpace(Model.Filename) ? "<not defined>" : Model.Filename;
347+
var filename = string.IsNullOrWhiteSpace(Model.Filename) ? "<not defined>" : Model.Filename;
356348
txtDatasourceName.Text = filename;
357349

358350
txtProjection.Text = Model.Projection.IsEmpty ? "<not defined>" : Model.Projection.Name;
@@ -362,14 +354,14 @@ private void InitGeneralTab()
362354
dynamicVisibilityControl1.Initialize(Model, _context.Map.CurrentZoom, _context.Map.CurrentScale);
363355
dynamicVisibilityControl1.ValueChanged += (s, e) => MarkStateChanged();
364356

365-
int numFeatures = _featureSet.Features.Count;
357+
var numFeatures = _featureSet.Features.Count;
366358
var type = _featureSet.GeometryType.EnumToString().ToLower();
367-
368-
string msg = string.Format("Feature count: {0}; geometry type: {1}", numFeatures, type);
359+
360+
txtBriefInfo.Text = $@"Feature count: {numFeatures}; geometry type: {type}";
369361

370362
if (_featureSet.ZValueType != ZValueType.None)
371363
{
372-
txtBriefInfo.Text = msg + "; subtype: " + _featureSet.ZValueType;
364+
txtBriefInfo.Text += @"; subtype: " + _featureSet.ZValueType;
373365
}
374366
}
375367

@@ -399,15 +391,14 @@ private void InitializeCore()
399391
InitLabelsTab();
400392

401393
InitChartsTab();
402-
394+
403395
InitInfoTextBox();
404396

405397
txtLayerExpression.Text = _featureSet.VisibilityExpression;
406398

407399
attributesControl1.Initialize(_featureSet);
408400

409401
joinControl1.Initialize(_context, _featureSet.Table);
410-
411402
joinControl1.JoinsChanged += () => attributesControl1.UpdateView();
412403

413404
_lockUpdate = false;
@@ -488,12 +479,11 @@ private void OnButtonOkClicked(object sender, EventArgs e)
488479
/// </summary>
489480
private void OnChartColorSchemeSelectedIndexChanged(object sender, EventArgs e)
490481
{
491-
if (icbChartColorScheme.ColorSchemes != null && icbChartColorScheme.SelectedIndex >= 0)
492-
{
493-
RefreshModel();
494-
DrawChartsPreview();
495-
RedrawMap();
496-
}
482+
if (icbChartColorScheme.ColorSchemes == null || icbChartColorScheme.SelectedIndex < 0) return;
483+
484+
RefreshModel();
485+
DrawChartsPreview();
486+
RedrawMap();
497487
}
498488

499489
private void OnChartsClick(object sender, EventArgs e)
@@ -506,11 +496,10 @@ private void OnChartsClick(object sender, EventArgs e)
506496
/// </summary>
507497
private void OnCommentsKeyPress(object sender, KeyPressEventArgs e)
508498
{
509-
if (e.KeyChar == (char)Keys.Enter)
510-
{
511-
Model.Description = txtComments.Text;
512-
MarkStateChanged();
513-
}
499+
if (e.KeyChar != (char)Keys.Enter) return;
500+
501+
Model.Description = txtComments.Text;
502+
MarkStateChanged();
514503
}
515504

516505
/// <summary>
@@ -527,16 +516,13 @@ private void OnCommentsValidated(object sender, EventArgs e)
527516
/// </summary>
528517
private void OnDefaultDrawingOptionsClick(object sender, EventArgs e)
529518
{
530-
if (_context.ShowDefaultStyleDialog(Model.Handle, true, this))
531-
{
532-
DrawAllPreviews();
533-
534-
Application.DoEvents();
519+
if (!_context.ShowDefaultStyleDialog(Model.Handle, true, this)) return;
535520

536-
RedrawMap();
521+
DrawAllPreviews();
522+
Application.DoEvents();
537523

538-
RefreshControls();
539-
}
524+
RedrawMap();
525+
RefreshControls();
540526
}
541527

542528
/// <summary>
@@ -552,26 +538,25 @@ private void OnFormClosing(object sender, FormClosingEventArgs e)
552538
LockLegendAndMap(false);
553539

554540
var lyr = Model;
555-
if (lyr != null)
556-
{
557-
lyr.Name = txtLayerName.Text;
558-
_tabIndex = tabControl1.SelectedIndex;
541+
if (lyr == null) return;
559542

560-
_metadata.ShowLayerPreview = chkLayerPreview.Checked;
561-
_metadata.Comments = txtComments.Text;
543+
lyr.Name = txtLayerName.Text;
544+
_tabIndex = tabControl1.SelectedIndex;
562545

563-
if (_previewLayerHandle != -1)
564-
{
565-
axMap1.Layers.RemoveWithoutClosing(_previewLayerHandle);
566-
}
546+
_metadata.ShowLayerPreview = chkLayerPreview.Checked;
547+
_metadata.Comments = txtComments.Text;
548+
549+
if (_previewLayerHandle != -1)
550+
{
551+
axMap1.Layers.RemoveWithoutClosing(_previewLayerHandle);
567552
}
568553
}
569554

570555
private void OnFormShown(object sender, EventArgs e)
571556
{
572557
Application.DoEvents();
573558

574-
MapConfig.ForceHideLabels = false; // TODO: it's ugly; thing of a better way to show preview
559+
MapConfig.ForceHideLabels = false; // TODO: it's ugly; think of a better way to show preview
575560
}
576561

577562
/// /// <summary>
@@ -623,12 +608,11 @@ private void OnLabelPreviewClick(object sender, EventArgs e)
623608
/// </summary>
624609
private void OnLayerNameKeyPress(object sender, KeyPressEventArgs e)
625610
{
626-
if (e.KeyChar == (char)Keys.Enter)
627-
{
628-
Model.Name = txtLayerName.Text;
629-
MarkStateChanged();
630-
RedrawLegend();
631-
}
611+
if (e.KeyChar != (char)Keys.Enter) return;
612+
613+
Model.Name = txtLayerName.Text;
614+
MarkStateChanged();
615+
RedrawLegend();
632616
}
633617

634618
/// <summary>
@@ -716,7 +700,7 @@ private void RefreshControls()
716700
groupChartAppearance.Enabled = _featureSet.Diagrams.Count > 0;
717701

718702
// charts
719-
bool enabled = (_featureSet.Diagrams.Count > 0 && (_featureSet.Diagrams.Fields.Any()));
703+
var enabled = _featureSet.Diagrams.Count > 0 && _featureSet.Diagrams.Fields.Any();
720704
groupChartAppearance.Enabled = enabled;
721705
btnClearCharts.Enabled = enabled;
722706
icbChartColorScheme.Enabled = enabled;
@@ -778,7 +762,7 @@ private string SaveState()
778762
_featureSet.Labels.SavingMode = PersistenceType.None;
779763
_featureSet.Diagrams.SavingMode = PersistenceType.None;
780764

781-
string state = Model.Serialize();
765+
var state = Model.Serialize();
782766

783767
_featureSet.Labels.SavingMode = mode1;
784768
_featureSet.Diagrams.SavingMode = mode2;
@@ -791,7 +775,7 @@ private string SaveState()
791775
/// </summary>
792776
private void ShowLayerPreview()
793777
{
794-
bool val = MapConfig.LoadSymbologyOnAddLayer;
778+
var val = MapConfig.LoadSymbologyOnAddLayer;
795779
MapConfig.LoadSymbologyOnAddLayer = false;
796780

797781
axMap1.ShowCoordinates = CoordinatesDisplay.None;
@@ -802,7 +786,7 @@ private void ShowLayerPreview()
802786
axMap1.MapCursor = MapCursor.None;
803787
axMap1.MouseWheelSpeed = 1.0;
804788
axMap1.ZoomBehavior = ZoomBehavior.Default;
805-
_previewLayerHandle = axMap1.Layers.Add(_featureSet, true);
789+
_previewLayerHandle = axMap1.Layers.Add(_featureSet);
806790
axMap1.ZoomToLayer(_previewLayerHandle);
807791

808792
MapConfig.LoadSymbologyOnAddLayer = val;
@@ -815,8 +799,8 @@ private void btnCopyInfo_Click(object sender, EventArgs e)
815799
var data2 = VectorInfoHelper.GetVectorLayerInfo(Model.VectorSource);
816800
temp.AddSubItem(data);
817801
temp.AddSubItem(data2);
818-
string s = temp.Serialize();
819-
802+
var s = temp.Serialize();
803+
820804
ClipboardHelper.SetText(s);
821805
}
822806
}

0 commit comments

Comments
 (0)