Mercurial > repos > IBBoard.WarFoundry.GUI.QtSharp
changeset 13:dbe784f0802c
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 13 Feb 2010 10:34:41 +0000 |
parents | 4a724378d66a |
children | 61bc9b44a695 |
files | MainWindow.cs qt-gui/MainWindowLayout.cs qt-gui/MainWindowLayout.ui |
diffstat | 3 files changed, 61 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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<QAction> actions = new List<QAction>(){ - 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<string> headers = new List<string>(); + 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<WarFoundryObject>(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)
--- 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);
--- 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 @@ <property name="handleWidth"> <number>6</number> </property> - <widget class="QTreeView" name="armyTree"/> + <widget class="QTreeView" name="armyTree"> + <attribute name="headerVisible"> + <bool>false</bool> + </attribute> + <attribute name="headerVisible"> + <bool>false</bool> + </attribute> + </widget> <widget class="QTabWidget" name="unitTabs"> <property name="minimumSize"> <size> @@ -59,7 +66,7 @@ <x>0</x> <y>0</y> <width>696</width> - <height>20</height> + <height>23</height> </rect> </property> <widget class="QMenu" name="menuFile">