# HG changeset patch # User IBBoard # Date 1266057281 0 # Node ID dbe784f0802cbbfd85d6f0dec6dcc92a1c2d11fe # Parent 4a724378d66a6bebe53695c58b7b40f9fbe45bd3 Re #246: Create army tree implementation * Create model for the army tree view Re #242: Create Qt# UI for WarFoundry * Add actions directly rather than creating a list Re #247: Implement menu options in Qt# app * Implement enable/disable on undo/redo menu items diff -r 4a724378d66a -r dbe784f0802c MainWindow.cs --- a/MainWindow.cs Fri Feb 05 20:57:44 2010 +0000 +++ b/MainWindow.cs Sat Feb 13 10:34:41 2010 +0000 @@ -90,11 +90,9 @@ private void SetUpToolbar() { - List actions = new List(){ - layout.actionCreateArmy, - layout.actionOpenArmy, - layout.actionSaveArmy}; - layout.toolBar.AddActions(actions); + layout.toolBar.AddAction(layout.actionCreateArmy); + layout.toolBar.AddAction(layout.actionOpenArmy); + layout.toolBar.AddAction(layout.actionSaveArmy); layout.toolBar.AddSeparator(); layout.toolBar.AddAction(layout.actionUndo); layout.toolBar.AddAction(layout.actionRedo); @@ -148,6 +146,8 @@ private void HandleCommandStackCommandStackUpdated() { + layout.actionUndo.Enabled = CommandStack.CanUndo(); + layout.actionRedo.Enabled = CommandStack.CanRedo(); layout.actionSaveArmy.Enabled = CommandStack.IsDirty(); } @@ -285,6 +285,7 @@ Unit unit = (Unit)unitObj; //TODO set error panel //sbErrorPanel.Text = ""; + //TODO add unit to tree } } @@ -297,7 +298,7 @@ //sbErrorPanel.Text = ""; //TODO check if window is open, and close it if it is - + //TODO remove unit from tree } } @@ -336,6 +337,7 @@ layout.actionSaveArmyAs.Enabled = false; layout.actionCloseArmy.Enabled = false; layout.menuExportArmyAs.Enabled = false; + layout.armyTree.SetModel(new QStandardItemModel()); DisableCategoryButtons(); } @@ -352,6 +354,47 @@ layout.actionSaveArmyAs.Enabled = true; layout.actionCloseArmy.Enabled = true; layout.menuExportArmyAs.Enabled = true; + FillArmyTree(newArmy); + } + + private void FillArmyTree (Army army) + { + QStandardItemModel treeModel = new QStandardItemModel(); + List headers = new List(); + headers.Add(army.Name); + treeModel.SetHorizontalHeaderLabels(headers); + + foreach (var category in army.Categories) + { + QStandardItem item = CreateTreeItem(category); + treeModel.AppendRow(item); + CreateUnitNodes(category, item); + } + + layout.armyTree.SetModel(treeModel); + } + + private QStandardItem CreateTreeItem(WarFoundryObject obj) + { + QVariant wrappedObject = QVariant.FromValue(obj); + QStandardItem item = new QStandardItem(obj.Name); + item.SetData(wrappedObject); + return item; + } + + private void CreateUnitNodes(ArmyCategory category, QStandardItem categoryItem) + { + foreach (Unit unit in category.GetUnits()) + { + CreateTreeSubItem(unit, categoryItem); + } + } + + private QStandardItem CreateTreeSubItem(WarFoundryObject obj, QStandardItem rootItem) + { + QStandardItem item = CreateTreeItem(obj); + rootItem.AppendRow(item); + return item; } void SetCategoryButtons (Category[] categories) diff -r 4a724378d66a -r dbe784f0802c qt-gui/MainWindowLayout.cs --- a/qt-gui/MainWindowLayout.cs Fri Feb 05 20:57:44 2010 +0000 +++ b/qt-gui/MainWindowLayout.cs Sat Feb 13 10:34:41 2010 +0000 @@ -1,8 +1,8 @@ /******************************************************************************** ** Form generated from reading ui file 'MainWindowLayout.ui' ** -** Created: Fri Feb 5 20:56:11 2010 -** by: Qt User Interface Compiler for C# version 4.6.0 +** Created: Sat Feb 13 10:32:31 2010 +** by: Qt User Interface Compiler for C# version 4.5.3 ** ** WARNING! All changes made in this file will be lost when recompiling ui file! ********************************************************************************/ @@ -103,7 +103,7 @@ MainWindowLayout.SetCentralWidget(mainContent); menubar = new QMenuBar(MainWindowLayout); menubar.ObjectName = "menubar"; - menubar.Geometry = new QRect(0, 0, 696, 20); + menubar.Geometry = new QRect(0, 0, 696, 23); menuFile = new QMenu(menubar); menuFile.ObjectName = "menuFile"; menuExportArmyAs = new QMenu(menuFile); diff -r 4a724378d66a -r dbe784f0802c qt-gui/MainWindowLayout.ui --- a/qt-gui/MainWindowLayout.ui Fri Feb 05 20:57:44 2010 +0000 +++ b/qt-gui/MainWindowLayout.ui Sat Feb 13 10:34:41 2010 +0000 @@ -27,7 +27,14 @@ 6 - + + + false + + + false + + @@ -59,7 +66,7 @@ 0 0 696 - 20 + 23