Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » GridCtrl and diff Edit()'s per row, same column
GridCtrl and diff Edit()'s per row, same column [message #21761] Thu, 04 June 2009 14:36 Go to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
I am making my first real application in U++ and it is to manage apiaries (yards of bee hives) and bee hives. Each bee hive can have different components installed, each component can have different questions that must be answered during a routine inspection. These questions can be of different answer types:

  1. String
  2. Number
  3. Percentage
  4. Yes/No


I have everything up and working to allow the addition of apiaries, bee hives, components, assigning components to bee hives and assigning questions to components. It then will generate a QTF report for them to print and take to the apiary for their visit. The report looks something like:

Hive Id: 1
Feeder:   Filled With: ________ Refilled: Yes/No
Honey Super: Frames Filled: _____# Harvested: _______#


etc... So, with filled with, they will write in a string "water", they will circule Yes or No with Refilled, they will enter a number "7" in the Frames Filled field... etc...

Now, my GUI design was going to have a list of hives in the same order as on their printed sheet that they select, then in a grid control it would have the questions in 1 column and the place they give their answer in a second column (of course in the order it was printed on their sheet). The problem is I will need something like:

Feeder: Filled With        | EditString
Feeder: Refilled           | OptionButton
Honey Super: Frames Filled | EditInt
Honey Super: Harvested     | EditInt


... etc ... The components and questions are not standard but totally user definable. Depending on climate, equipment styles and even bee keeping methods these components/questions could be 100% different from one beekeeper to another.

Any thoughts on making this work with GridCtrl or should I be looking at some other method to get the feedback back from the sheet into the computer?

Thanks,

Jeremy
Re: GridCtrl and diff Edit()'s per row, same column [message #21765 is a reply to message #21761] Thu, 04 June 2009 15:34 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

What you need is ability to set cell's indyvidual control
grid.SetCtrl(r, c, Ctrl&)
. Yesterday I almost finished adding this feature and I'll probably commit this tonight.
Re: GridCtrl and diff Edit()'s per row, same column [message #21767 is a reply to message #21761] Thu, 04 June 2009 16:11 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
I don't use GridCtrl, but this is the technique for ArrayCtrl (deopending on your needs GridCtrl might be overkill anyway):
#include <CtrlLib/CtrlLib.h>
using namespace Upp;

class CtrlLibTest : public TopWindow {
	struct Question : public Moveable<Question> {
		void Set(String question, int _type, Value _default_value = Value()) {
			type = _type;
			text = question;
			default_value = _default_value;
		}
		dword type;
		String text;
		Value default_value;
	};
private:
	ArrayCtrl 			list;
	Vector<Question> 	questions;
	Array<Ctrl>			ctrls;
	Button				finish;
	Button				close;
public:
	typedef CtrlLibTest CLASSNAME;
	CtrlLibTest();
		
	void SetQuestions();
	void FillList();
	void GetAnswers();
	String FormatAnswer(int type, const Value &v);
};


CtrlLibTest::CtrlLibTest()
{
	Title("Question/Answer program");
	SetRect(Size(300,300));
	
	list.ColumnWidths("186 93").HSizePosZ().VSizePosZ(0, 32);
	finish.Ok().SetLabel("Finish").LeftPosZ(4, 64).BottomPosZ(4, 24) <<= THISBACK(GetAnswers);
	close.Cancel().SetLabel("Cancel").RightPosZ(4, 64).BottomPosZ(4, 24) <<= Rejector(IDCANCEL);
	*this << list << finish << close;
	
	list.AddIndex(); // Question id
	list.AddColumn("Question");
	list.AddColumn("Answer");
	
	SetQuestions();
	FillList();
}

void CtrlLibTest::SetQuestions()
{
	questions.Add().Set("Feeder: Filled With", STRING_V);
	questions.Add().Set("Feeder: Refilled", BOOL_V);
	questions.Add().Set("Honey Super: Frames Filled", INT_V);
	questions.Add().Set("Honey Super: Harvested", INT_V);
}

void CtrlLibTest::FillList()
{
	ctrls.Clear();
	for (int i = 0; i < questions.GetCount(); i++) {
		list.Add(i, questions[i].text, questions[i].default_value);
		switch (questions[i].type) {
			case INT_V:
				ctrls.Create<EditInt>();
				break;
			case STRING_V:
				ctrls.Create<EditString>();
				break;
			case BOOL_V:
				ctrls.Create<Option>();
				break;			
			case DOUBLE_V:
				ctrls.Create<EditDouble>();
				break;
			default:
				NEVER();
				continue;
		}
		list.SetCtrl(i, 1, ctrls.Top());
	}
}

void CtrlLibTest::GetAnswers()
{
	if (!Accept()) return;
	// Because ArrayCtrl doesn't Accept properly:
	for (int i = 0; i < ctrls.GetCount(); i++)
		if (!ctrls[i].Accept()) return;
	
	String qtf("Here are your answers:&");
	for (int i = 0; i < list.GetCount(); i++)
		qtf << list.Get(i, 1) << "- "
			<< FormatAnswer(questions[(int)list.Get(i, 0)].type, list.Get(i, 2)) << "&";
	PromptOK(qtf);
}

String CtrlLibTest::FormatAnswer(int type, const Value &v)
{
	if (type == BOOL_V)
		return ((bool)v) ? "Yes" : "No";
	return StdConvert().Format(v);
}


GUI_APP_MAIN
{
	CtrlLibTest().Execute();
}
Re: GridCtrl and diff Edit()'s per row, same column [message #21776 is a reply to message #21767] Thu, 04 June 2009 20:44 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
mrjt wrote on Thu, 04 June 2009 10:11

I don't use GridCtrl, but this is the technique for ArrayCtrl (deopending on your needs GridCtrl might be overkill anyway):


Wow! Thank you. You put a lot of work into this. Seeing your example in action, it's exactly what I need, nothing more.

Thank you for your help!

Jeremy
Re: GridCtrl and diff Edit()'s per row, same column [message #21790 is a reply to message #21776] Fri, 05 June 2009 09:31 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
No problem, I've neede the same thing myself so it's farily easy to reproduce.
Re: GridCtrl and diff Edit()'s per row, same column [message #27462 is a reply to message #21765] Mon, 19 July 2010 09:11 Go to previous messageGo to next message
MatthiasG is currently offline  MatthiasG
Messages: 27
Registered: January 2008
Location: Germany
Promising Member
unodgs wrote on Thu, 04 June 2009 15:34

What you need is ability to set cell's indyvidual control
grid.SetCtrl(r, c, Ctrl&)
. Yesterday I almost finished adding this feature and I'll probably commit this tonight.


got this ever implemented by now? i would be really glad to see this in gridctrl

greetings,
matthias
Re: GridCtrl and diff Edit()'s per row, same column [message #27477 is a reply to message #27462] Tue, 20 July 2010 00:03 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

MatthiasG wrote on Mon, 19 July 2010 03:11

unodgs wrote on Thu, 04 June 2009 15:34

What you need is ability to set cell's indyvidual control
grid.SetCtrl(r, c, Ctrl&)
. Yesterday I almost finished adding this feature and I'll probably commit this tonight.


got this ever implemented by now? i would be really glad to see this in gridctrl

greetings,
matthias


I have just added SetCtrl. Please take a look.
Re: GridCtrl and diff Edit()'s per row, same column [message #27479 is a reply to message #27477] Tue, 20 July 2010 09:11 Go to previous messageGo to next message
MatthiasG is currently offline  MatthiasG
Messages: 27
Registered: January 2008
Location: Germany
Promising Member
unodgs wrote on Tue, 20 July 2010 00:03

MatthiasG wrote on Mon, 19 July 2010 03:11

unodgs wrote on Thu, 04 June 2009 15:34

What you need is ability to set cell's indyvidual control
grid.SetCtrl(r, c, Ctrl&)
. Yesterday I almost finished adding this feature and I'll probably commit this tonight.


got this ever implemented by now? i would be really glad to see this in gridctrl


I have just added SetCtrl. Please take a look.


Thank you very much. Seems to work great so far Smile

only one thing:
if i want to set a ctrl, row index seems to start from 0, but if i later want to do a getctrl, index starts from 1. e.g. if i do setctrl (0, 0, myctrl) i later have to do getctrl (1, 0) to get it... seems index 0 is used for header or something.
Re: GridCtrl and diff Edit()'s per row, same column [message #27490 is a reply to message #27479] Tue, 20 July 2010 21:32 Go to previous message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

MatthiasG wrote on Tue, 20 July 2010 03:11


only one thing:
if i want to set a ctrl, row index seems to start from 0, but if i later want to do a getctrl, index starts from 1. e.g. if i do setctrl (0, 0, myctrl) i later have to do getctrl (1, 0) to get it... seems index 0 is used for header or something.

Should be fixed now. Please check Smile
Previous Topic: BUG: HeaderCtrl::Serialize
Next Topic: ArrayCtrl and converters
Goto Forum:
  


Current Time: Thu Mar 28 10:31:51 CET 2024

Total time taken to generate the page: 0.01359 seconds