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 diff
     1.1 --- a/MainWindow.cs	Fri Feb 05 20:57:44 2010 +0000
     1.2 +++ b/MainWindow.cs	Sat Feb 13 10:34:41 2010 +0000
     1.3 @@ -90,11 +90,9 @@
     1.4  		
     1.5  		private void SetUpToolbar()
     1.6  		{
     1.7 -			List<QAction> actions = new List<QAction>(){
     1.8 -				layout.actionCreateArmy,
     1.9 -				layout.actionOpenArmy,
    1.10 -				layout.actionSaveArmy};
    1.11 -			layout.toolBar.AddActions(actions);
    1.12 +			layout.toolBar.AddAction(layout.actionCreateArmy);
    1.13 +			layout.toolBar.AddAction(layout.actionOpenArmy);
    1.14 +			layout.toolBar.AddAction(layout.actionSaveArmy);
    1.15  			layout.toolBar.AddSeparator();
    1.16  			layout.toolBar.AddAction(layout.actionUndo);
    1.17  			layout.toolBar.AddAction(layout.actionRedo);
    1.18 @@ -148,6 +146,8 @@
    1.19  
    1.20  		private void HandleCommandStackCommandStackUpdated()
    1.21  		{
    1.22 +			layout.actionUndo.Enabled = CommandStack.CanUndo();
    1.23 +			layout.actionRedo.Enabled = CommandStack.CanRedo();
    1.24  			layout.actionSaveArmy.Enabled = CommandStack.IsDirty();
    1.25  		}
    1.26  
    1.27 @@ -285,6 +285,7 @@
    1.28  				Unit unit = (Unit)unitObj;
    1.29  				//TODO set error panel
    1.30  				//sbErrorPanel.Text = "";
    1.31 +				//TODO add unit to tree
    1.32  			}
    1.33  		}
    1.34  
    1.35 @@ -297,7 +298,7 @@
    1.36  				//sbErrorPanel.Text = "";
    1.37  
    1.38  				//TODO check if window is open, and close it if it is
    1.39 -				
    1.40 +				//TODO remove unit from tree
    1.41  			}
    1.42  		}
    1.43  		
    1.44 @@ -336,6 +337,7 @@
    1.45  			layout.actionSaveArmyAs.Enabled = false;
    1.46  			layout.actionCloseArmy.Enabled = false;
    1.47  			layout.menuExportArmyAs.Enabled = false;
    1.48 +			layout.armyTree.SetModel(new QStandardItemModel());
    1.49  			DisableCategoryButtons();
    1.50  		}
    1.51  
    1.52 @@ -352,6 +354,47 @@
    1.53  			layout.actionSaveArmyAs.Enabled = true;
    1.54  			layout.actionCloseArmy.Enabled = true;
    1.55  			layout.menuExportArmyAs.Enabled = true;
    1.56 +			FillArmyTree(newArmy);
    1.57 +		}
    1.58 +
    1.59 +		private void FillArmyTree (Army army)
    1.60 +		{
    1.61 +			QStandardItemModel treeModel = new QStandardItemModel();
    1.62 +			List<string> headers = new List<string>();
    1.63 +			headers.Add(army.Name);
    1.64 +			treeModel.SetHorizontalHeaderLabels(headers);
    1.65 +			
    1.66 +			foreach (var category in army.Categories)
    1.67 +			{
    1.68 +				QStandardItem item = CreateTreeItem(category);				
    1.69 +				treeModel.AppendRow(item);
    1.70 +				CreateUnitNodes(category, item);
    1.71 +			}
    1.72 +			
    1.73 +			layout.armyTree.SetModel(treeModel);
    1.74 +		}
    1.75 +		
    1.76 +		private QStandardItem CreateTreeItem(WarFoundryObject obj)
    1.77 +		{
    1.78 +			QVariant wrappedObject = QVariant.FromValue<WarFoundryObject>(obj);
    1.79 +			QStandardItem item = new QStandardItem(obj.Name);
    1.80 +			item.SetData(wrappedObject);
    1.81 +			return item;
    1.82 +		}
    1.83 +
    1.84 +		private void CreateUnitNodes(ArmyCategory category, QStandardItem categoryItem)
    1.85 +		{
    1.86 +			foreach (Unit unit in category.GetUnits())
    1.87 +			{
    1.88 +				CreateTreeSubItem(unit, categoryItem);
    1.89 +			}
    1.90 +		}
    1.91 +		
    1.92 +		private QStandardItem CreateTreeSubItem(WarFoundryObject obj, QStandardItem rootItem)
    1.93 +		{
    1.94 +			QStandardItem item = CreateTreeItem(obj);
    1.95 +			rootItem.AppendRow(item);
    1.96 +			return item;
    1.97  		}
    1.98  
    1.99  		void SetCategoryButtons (Category[] categories)
     2.1 --- a/qt-gui/MainWindowLayout.cs	Fri Feb 05 20:57:44 2010 +0000
     2.2 +++ b/qt-gui/MainWindowLayout.cs	Sat Feb 13 10:34:41 2010 +0000
     2.3 @@ -1,8 +1,8 @@
     2.4  /********************************************************************************
     2.5  ** Form generated from reading ui file 'MainWindowLayout.ui'
     2.6  **
     2.7 -** Created: Fri Feb 5 20:56:11 2010
     2.8 -**      by: Qt User Interface Compiler for C# version 4.6.0
     2.9 +** Created: Sat Feb 13 10:32:31 2010
    2.10 +**      by: Qt User Interface Compiler for C# version 4.5.3
    2.11  **
    2.12  ** WARNING! All changes made in this file will be lost when recompiling ui file!
    2.13  ********************************************************************************/
    2.14 @@ -103,7 +103,7 @@
    2.15      MainWindowLayout.SetCentralWidget(mainContent);
    2.16      menubar = new QMenuBar(MainWindowLayout);
    2.17      menubar.ObjectName = "menubar";
    2.18 -    menubar.Geometry = new QRect(0, 0, 696, 20);
    2.19 +    menubar.Geometry = new QRect(0, 0, 696, 23);
    2.20      menuFile = new QMenu(menubar);
    2.21      menuFile.ObjectName = "menuFile";
    2.22      menuExportArmyAs = new QMenu(menuFile);
     3.1 --- a/qt-gui/MainWindowLayout.ui	Fri Feb 05 20:57:44 2010 +0000
     3.2 +++ b/qt-gui/MainWindowLayout.ui	Sat Feb 13 10:34:41 2010 +0000
     3.3 @@ -27,7 +27,14 @@
     3.4        <property name="handleWidth">
     3.5         <number>6</number>
     3.6        </property>
     3.7 -      <widget class="QTreeView" name="armyTree"/>
     3.8 +      <widget class="QTreeView" name="armyTree">
     3.9 +       <attribute name="headerVisible">
    3.10 +        <bool>false</bool>
    3.11 +       </attribute>
    3.12 +       <attribute name="headerVisible">
    3.13 +        <bool>false</bool>
    3.14 +       </attribute>
    3.15 +      </widget>
    3.16        <widget class="QTabWidget" name="unitTabs">
    3.17         <property name="minimumSize">
    3.18          <size>
    3.19 @@ -59,7 +66,7 @@
    3.20       <x>0</x>
    3.21       <y>0</y>
    3.22       <width>696</width>
    3.23 -     <height>20</height>
    3.24 +     <height>23</height>
    3.25      </rect>
    3.26     </property>
    3.27     <widget class="QMenu" name="menuFile">