QVariant SceneTreeItem::data(int role) const
{
	QVariant v;

	switch(role)
	{
	case Qt::DecorationRole:
		v = ItemIcon();
		break;
	case Qt::DisplayRole:
		v = ItemName();
		break;
	case EIDR_Type:
		v = ItemType();
		break;
	case EIDR_Data:
		v = ItemData();
		break;
    case Qt::BackgroundColorRole:
        v = ItemBackgroundColor();
        break;
	default:
		break;
	}

	if(v.isNull())
	{
		v = QStandardItem::data(role);
	}

	return v;
}
Example #2
0
void
TableItem::setData(int role,
                   const QVariant &value)
{
    bool found = false;

    role = (role == Qt::EditRole ? Qt::DisplayRole : role);
    for (int i = 0; i < values.count(); ++i) {
        if (values.at(i).role == role) {
            if (values[i].value == value) {
                return;
            }

            values[i].value = value;
            found = true;
            break;
        }
    }
    if (!found) {
        values.append( ItemData(role, value) );
    }
    if ( TableModel * model = (view ? qobject_cast<TableModel*>( view->model() ) : 0) ) {
        model->itemChanged(this);
    }
}
Example #3
0
void
setConfigItem(ConfigMap& configItems, const String& itemName,
	const String& value, EOverwritePreviousFlag overwritePrevious)
{
	ConfigMap::iterator it = configItems.find(itemName);
	if (it == configItems.end())
	{
		configItems[itemName].push_back(ItemData("", value));
	}
	else if (overwritePrevious == E_OVERWRITE_PREVIOUS)
	{
		ItemDataArray& values = configItems[itemName];
		values.clear();
		values.push_back(ItemData("", value));
	}
	// else overwritePrevious == E_PRESERVE_PREVIOUS, and do nothing
}
Example #4
0
void DefaultMenuModel::insertSeparator(std::size_t index)
{
	if (index <= myItems.size())
	{
		myItems.insert(myItems.begin() + index, ItemData("", false, false, true));
		notify();
	}
}
Example #5
0
/**
 * \brief zwraca strukture ItemData zawierającą dane o przedmiocie
 * \details wyszukuje itema o danym GID (do jednej teksturki może być
 * przypisana tylko jedna specyfikacja)
 * \param gid gid przedmiotu
 * \return jeśli znaleziono to ItemData z danymi, jeśli nie to ItemData
 * z wyzerowanymi polami i nazwą "undefined"
 */
const ItemData& ItemManager::getData(size_t gid) const
{
    std::vector<ItemData>::const_iterator it =
        std::find(itemsinfo.begin(), itemsinfo.end(), ItemData(WEAPON,L"",L"",0,0,0,0,0,0,gid));
    if(it != itemsinfo.end())
        return *it;
    return undef;
}
Example #6
0
void DefaultMenuModel::insertItem(std::size_t index, std::string text, bool enabled, bool checked)
{
	if (index <= myItems.size())
	{
		myItems.insert(myItems.begin() + index, ItemData(text, enabled, checked, false));
		notify();
	}
}
Example #7
0
/* 
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CExPolicy_ServerSession::GetExtraInfoL(const RMessage2& aMessage)
{        
	TInt Err(KErrNone);
	
	TExtraInfoItem Dattta;
	Server().GetExtraInfoL(Dattta);
	
	TPckgBuf<TExtraInfoItem> ItemData(Dattta);
	aMessage.WriteL(0,ItemData);
    aMessage.Complete(Err);		
}
	// This method deletes all items from the listview
	void DeleteAllItems()
	{
		CItemData *pid;
		
		for (int i = 0; i < _numRows; i++) {
			pid = ItemData(i);
			if (pid)
				delete pid;
		}
		ListView_DeleteAllItems(_hList);
		_numRows = 0;
	}
Example #9
0
ItemData LibraryFile::getItemData( qint32 index )
{
	QMutexLocker locker( &mutex );

	if( isIdle() )
	{
		QDataStream in( this );
		in.setByteOrder( QDataStream::LittleEndian );
		TibiaFile::seek( sizeof( quint16 ) + sizeof( m_count ) + sizeof( m_version ) + index * sizeof( quint32 ) );
		quint32 offset;
		in >> offset;
		if( offset == 0x00000000 ) // Blank item
			return ItemData();

		TibiaFile::seek( offset );

		QString error;
		quint32 address = 0;
		ItemData itemData;
		if( ExternalFile::readItem( in, itemData, m_datFormat, this, index, address, error ) )
		{
			m_spriteHash.insert( index, address );
			return itemData;
		}
		else
			emit documentError( fileName(), error, -1 );
	}

	if( m_internalItems.contains( index ) )
		return m_internalItems.value( index );

	if( m_items.value( index ) )
		return m_items.value( index )->getItemData();

	return ItemData();
}
Example #10
0
/** Maps to what groups the source row belongs by returning the data of those groups.
  *
  * @returns a list of data for the rows the argument belongs to. In common cases this list will
  * contain only one entry. An empty list means that the source item will be placed in the root of
  * this proxyModel. There is no support for hiding source items.
  *
  * Group data can be pre-loaded in the return value so it's added to the cache maintained by this
  * class. This is required if you want to have data that is not present in the source model.
  */
QList<RowData>
QtGroupingProxy::belongsTo( const QModelIndex &idx )
{
    //qDebug() << __FILE__ << __FUNCTION__;
    QList<RowData> rowDataList;

    //get all the data for this index from the model
    ItemData itemData = sourceModel()->itemData( idx );
    QMapIterator<int, QVariant> i( itemData );
    while( i.hasNext() )
    {
        i.next();
        int role = i.key();
        QVariant variant = i.value();
        // qDebug() << "role " << role << " : (" << variant.typeName() << ") : "<< variant;
        if( variant.type() == QVariant::List )
        {
            //a list of variants get's expanded to multiple rows
            QVariantList list = variant.toList();
            for( int i = 0; i < list.length(); i++ )
            {
                //take an existing row data or create a new one
                RowData rowData = (rowDataList.count() > i) ?  rowDataList.takeAt( i )
                                       : RowData();

                //we only gather data for the first column
                ItemData indexData = rowData.contains( 0 ) ? rowData.take( 0 ) : ItemData();
                indexData.insert( role, list.value( i ) );
                rowData.insert( 0, indexData );
                //for the grouped column the data should not be gathered from the children
                //this will allow filtering on the content of this column with a
                //QSortFilterProxyModel
                rowData.insert( m_groupedColumn, indexData );
                rowDataList.insert( i, rowData );
            }
        }
        else if( !variant.isNull() )
        {
            //it's just a normal item. Copy all the data and break this loop.
            RowData rowData;
            rowData.insert( 0, itemData );
            rowDataList << rowData;
            break;
        }
    }

    return rowDataList;
}
Example #11
0
void loadConfigFile(const String& filename, ConfigMap& rval)
{
	std::ifstream file(filename.c_str());
	if (!file)
	{
		OW_THROW(ConfigException, Format("Unable to read config"
					" file: %1", filename).c_str());
	}
	
	String line;
	int lineNum = 0;
	while (file)
	{
		lineNum++;
		line = String::getLine(file);
		if (!line.empty())
		{
			// If comment line, ignore
			if (line[0] == '#' || line[0] == ';')
			{
				continue;
			}
			size_t idx = line.indexOf('=');
			if (idx != String::npos)
			{
				if (idx + 1 < line.length())
				{
					String itemValue = line.substring(idx + 1).trim();
					if (!itemValue.empty())
					{
						String item = line.substring(0, idx).trim();
						rval[item].push_back(ItemData(filename, itemValue));
					}
				}
			}
			else
			{
				OW_THROW(ConfigException, Format("Error in config file:"
					" %1 at line %2.\n  Line is %3", filename, lineNum,
					line).c_str());
			}
		}
	}
}
Example #12
0
void LLDBTooltip::OnItemExpanding(wxTreeEvent& event)
{
    CHECK_ITEM_RET(event.GetItem());
    LLDBVariableClientData* data = ItemData(event.GetItem());

    wxTreeItemIdValue cookie;
    wxTreeItemId child = m_treeCtrl->GetFirstChild(event.GetItem(), cookie);
    if(m_treeCtrl->GetItemText(child) == "<dummy>") {

        // dummy item, remove it
        m_treeCtrl->DeleteChildren(event.GetItem());
        m_plugin->GetLLDB()->RequestVariableChildren(data->GetVariable()->GetLldbId());

        // Store the treeitemid parent in cache
        m_itemsPendingExpansion.insert(std::make_pair(data->GetVariable()->GetLldbId(), event.GetItem()));

    } else {
        event.Skip();
    }
}
Example #13
0
void InventoryItem::SaveItem()
{
    //_log( ITEM__TRACE, "Saving item %u.", itemID() );

    SaveAttributes();

    m_factory.db().SaveItem(
        itemID(),
        ItemData(
            itemName().c_str(),
            typeID(),
            ownerID(),
            locationID(),
            flag(),
            contraband(),
            singleton(),
            quantity(),
            position(),
            customInfo().c_str()
        )
    );
}
/*
 * Display a menu for choosing among a number of options
 */
int
dialog_menu(const char *title, const char *cprompt, int height, int width,
	    int menu_height, int item_no, char **items)
{
    int i, j, x, y, cur_x, cur_y, box_x, box_y;
    int key = 0, fkey;
    int button = 0;
    int choice = dlg_default_item(items, MENUBOX_TAGS);
    int result = DLG_EXIT_UNKNOWN;
    int scrollamt = 0;
    int max_choice, min_width;
    int found;
    int use_width, name_width, text_width;
    WINDOW *dialog, *menu;
    char *prompt = strclone(cprompt);
    const char **buttons = dlg_ok_labels();

    tab_correct_str(prompt);
    if (menu_height == 0) {
	min_width = calc_listw(item_no, items, MENUBOX_TAGS) + 10;
	/* calculate height without items (4) */
	auto_size(title, prompt, &height, &width, 4, MAX(26, min_width));
	calc_listh(&height, &menu_height, item_no);
    } else {
	auto_size(title, prompt, &height, &width, 4 + menu_height, 26);
    }
    print_size(height, width);
    ctl_size(height, width);

    /* Find out maximal number of displayable items at once. */
    max_choice = MIN(menu_height,
		     RowHeight(item_no));
    if (dialog_vars.input_menu)
	max_choice /= INPUT_ROWS;

    x = box_x_ordinate(width);
    y = box_y_ordinate(height);

    dialog = new_window(height, width, y, x);

    mouse_setbase(x, y);

    draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
    draw_bottom_box(dialog);
    draw_title(dialog, title);

    wattrset(dialog, dialog_attr);
    print_autowrap(dialog, prompt, height, width);

    menu_width = width - 6;
    getyx(dialog, cur_y, cur_x);
    box_y = cur_y + 1;
    box_x = (width - menu_width) / 2 - 1;

    /* create new window for the menu */
    menu = sub_window(dialog, menu_height, menu_width,
		      y + box_y + 1,
		      x + box_x + 1);

    /* draw a box around the menu items */
    draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
	     menubox_border_attr, menubox_attr);

    name_width = 0;
    text_width = 0;

    /* Find length of longest item to center menu  *
     * only if --menu was given, using --inputmenu *
     * won't be centered.                         */
    for (i = 0; i < item_no; i++) {
	name_width = MAX(name_width, dlg_count_columns(ItemName(i)));
	text_width = MAX(text_width, dlg_count_columns(ItemText(i)));
    }

    /* If the name+text is wider than the list is allowed, then truncate
     * one or both of them.  If the name is no wider than 1/4 of the list,
     * leave it intact.
     */
    use_width = (menu_width - GUTTER);
    if (text_width + name_width > use_width) {
	int need = 0.25 * use_width;
	if (name_width > need) {
	    int want = use_width * ((double) name_width) / (text_width + name_width);
	    name_width = (want > need) ? want : need;
	}
	text_width = use_width - name_width;
    }

    tag_x = (dialog_vars.input_menu
	     ? 0
	     : (use_width - text_width - name_width) / 2);
    item_x = name_width + tag_x + GUTTER;

    if (choice - scrollamt >= max_choice) {
	scrollamt = choice - (max_choice - 1);
	choice = max_choice - 1;
    }

    /* Print the menu */
    for (i = 0; i < max_choice; i++)
	print_item(menu, ItemData(i + scrollamt), i, i == choice);
    (void) wnoutrefresh(menu);

    /* register the new window, along with its borders */
    mouse_mkbigregion(box_y + 1, box_x, menu_height + 2, menu_width + 2,
		      KEY_MAX, 1, 1, 1 /* by lines */ );

    dlg_draw_arrows(dialog, scrollamt,
		    scrollamt + max_choice < item_no,
		    box_x + tag_x + 1,
		    box_y,
		    box_y + menu_height + 1);

    dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);

    wtimeout(dialog, WTIMEOUT_VAL);

    while (result == DLG_EXIT_UNKNOWN) {
	key = mouse_wgetch(dialog, &fkey);

	if (!fkey) {
	    fkey = TRUE;
	    switch (key) {
	    case '\n':
	    case '\r':
		key = KEY_ENTER;
		break;
	    case '-':
		key = KEY_UP;
		break;
	    case '+':
		key = KEY_DOWN;
		break;
	    case ' ':
	    case TAB:
		key = KEY_RIGHT;
		break;
	    case ESC:
		result = DLG_EXIT_ESC;
		continue;
	    default:
		fkey = FALSE;
		break;
	    }
	}

	found = FALSE;
	if (fkey) {
	    /*
	     * Allow a mouse-click on a box to switch selection to that box.
	     * Handling a button click is a little more complicated, since we
	     * push a KEY_ENTER back onto the input stream so we'll put the
	     * cursor at the right place before handling the "keypress".
	     */
	    if (key >= (M_EVENT + KEY_MAX)) {
		key -= (M_EVENT + KEY_MAX);
		i = RowToItem(key);
		found = TRUE;
	    } else if (key >= M_EVENT
		       && dlg_ok_buttoncode(key - M_EVENT) >= 0) {
		button = (key - M_EVENT);
		ungetch('\n');
		continue;
	    }
	} else {
	    /*
	     * Check if key pressed matches first character of any item tag in
	     * list.  If there is more than one match, we will cycle through
	     * each one as the same key is pressed repeatedly.
	     */
	    for (j = scrollamt + choice + 1; j < item_no; j++) {
		if (dlg_match_char(dlg_last_getc(), ItemName(j))) {
		    found = TRUE;
		    i = j - scrollamt;
		    break;
		}
	    }
	    if (!found) {
		for (j = 0; j <= scrollamt + choice; j++) {
		    if (dlg_match_char(dlg_last_getc(), ItemName(j))) {
			found = TRUE;
			i = j - scrollamt;
			break;
		    }
		}
	    }
	    if (found)
		dlg_flush_getc();

	    /*
	     * A single digit (1-9) positions the selection to that line in the
	     * current screen.
	     */
	    if (!found
		&& (key <= '9')
		&& (key > '0')
		&& (key - '1' < max_choice)) {
		found = TRUE;
		i = key - '1';
	    }
	}

	if (!found && fkey) {
	    found = TRUE;
	    switch (key) {
	    case KEY_HOME:
		i = -scrollamt;
		break;
	    case KEY_LL:
	    case KEY_END:
		i = item_no - 1 - scrollamt;
		break;
	    case M_EVENT + KEY_PPAGE:
	    case KEY_PPAGE:
		if (choice)
		    i = 0;
		else if (scrollamt != 0)
		    i = -MIN(scrollamt, max_choice);
		else
		    continue;
		break;
	    case M_EVENT + KEY_NPAGE:
	    case KEY_NPAGE:
		i = MIN(choice + max_choice, item_no - scrollamt - 1);
		break;
	    case KEY_UP:
		i = choice - 1;
		if (choice == 0 && scrollamt == 0)
		    continue;
		break;
	    case KEY_DOWN:
		i = choice + 1;
		if (scrollamt + choice >= item_no - 1)
		    continue;
		break;
	    default:
		found = FALSE;
		break;
	    }
	}

	if (found) {
	    if (i != choice) {
		getyx(dialog, cur_y, cur_x);
		if (i < 0 || i >= max_choice) {
#if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR < 5
		    /*
		     * Using wscrl to assist ncurses scrolling is not needed
		     * in version 5.x
		     */
		    if (i == -1) {
			if (menu_height > 1) {
			    /* De-highlight current first item */
			    print_item(menu, ItemData(scrollamt), 0, FALSE);
			    scrollok(menu, TRUE);
			    wscrl(menu, -RowHeight(1));
			    scrollok(menu, FALSE);
			}
			scrollamt--;
			print_item(menu, ItemData(scrollamt), 0, TRUE);
		    } else if (i == max_choice) {
			if (menu_height > 1) {
			    /* De-highlight current last item before scrolling up */
			    print_item(menu,
				       ItemData(scrollamt + max_choice - 1),
				       max_choice - 1, FALSE);
			    scrollok(menu, TRUE);
			    wscrl(menu, RowHeight(1));
			    scrollok(menu, FALSE);
			}
			scrollamt++;
			print_item(menu,
				   ItemData(scrollamt + max_choice - 1),
				   max_choice - 1, TRUE);
		    } else
#endif
		    {
			if (i < 0) {
			    scrollamt += i;
			    choice = 0;
			} else {
			    choice = max_choice - 1;
			    scrollamt += (i - max_choice + 1);
			}
			for (i = 0; i < max_choice; i++) {
			    print_item(menu,
				       ItemData(scrollamt + i),
				       i, i == choice);
			}
		    }
		    /* Clean bottom lines */
		    if (dialog_vars.input_menu) {
			int spare_lines, x_count;
			spare_lines = menu_height % INPUT_ROWS;
			wattrset(menu, menubox_attr);
			for (; spare_lines; spare_lines--) {
			    wmove(menu, menu_height - spare_lines, 0);
			    for (x_count = 0; x_count < menu_width;
				 x_count++) {
				waddch(menu, ' ');
			    }
			}
		    }
		    (void) wnoutrefresh(menu);
		    dlg_draw_arrows(dialog, scrollamt,
				    scrollamt + choice < item_no - 1,
				    box_x + tag_x + 1,
				    box_y,
				    box_y + menu_height + 1);
		} else {
		    /* De-highlight current item */
		    print_item(menu,
			       ItemData(scrollamt + choice),
			       choice, FALSE);
		    /* Highlight new item */
		    choice = i;
		    print_item(menu,
			       ItemData(scrollamt + choice),
			       choice, TRUE);
		    (void) wnoutrefresh(menu);
		    (void) wmove(dialog, cur_y, cur_x);
		    wrefresh(dialog);
		}
	    }
	    continue;		/* wait for another key press */
	}

	if (fkey) {
	    switch (key) {
	    case KEY_BTAB:
	    case KEY_LEFT:
		button = dlg_prev_button(buttons, button);
		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
				 FALSE, width);
		break;
	    case KEY_RIGHT:
		button = dlg_next_button(buttons, button);
		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
				 FALSE, width);
		break;
	    case KEY_ENTER:
		del_window(dialog);
		result = handle_button(dlg_ok_buttoncode(button),
				       items,
				       scrollamt + choice);

		if (dialog_vars.input_menu && result == DLG_EXIT_EXTRA) {
		    char *tmp;
		    tmp = input_menu_edit(menu, ItemData(scrollamt + choice),
					  choice);

		    dialog_vars.input_result[0] = '\0';
		    dlg_add_result("RENAMED ");
		    dlg_add_result(ItemName(scrollamt + choice));
		    dlg_add_result(" ");
		    dlg_add_result(tmp);
		    free(tmp);

		    dlg_draw_buttons(dialog, height - 2, 0,
				     buttons, button, FALSE, width);
		}
		break;
	    default:
		flash();
		break;
	    }
	}
    }

    mouse_free_regions();
    del_window(dialog);
    free(prompt);
    return result;
}
/*
 * Display a dialog box with a list of options that can be turned on or off
 * The `flag' parameter is used to select between radiolist and checklist.
 */
int
dialog_checklist(const char *title, const char *cprompt, int height, int width,
		 int list_height, int item_no, char **items, int flag,
		 int separate_output)
{
    int i, j, key2, found, x, y, cur_x, cur_y, box_x, box_y;
    int key = 0, fkey;
    int button = 0;
    int choice = 0;
    int scrollamt = 0;
    int max_choice, *status;
    int use_width, name_width, text_width;
    int result = DLG_EXIT_UNKNOWN;
    WINDOW *dialog, *list;
    char *prompt = strclone(cprompt);
    const char **buttons = dlg_ok_labels();

    tab_correct_str(prompt);
    if (list_height == 0) {
	use_width = calc_listw(item_no, items, CHECKBOX_TAGS) + 10;
	/* calculate height without items (4) */
	auto_size(title, prompt, &height, &width, 4, MAX(26, use_width));
	calc_listh(&height, &list_height, item_no);
    } else {
	auto_size(title, prompt, &height, &width, 4 + list_height, 26);
    }
    print_size(height, width);
    ctl_size(height, width);

    checkflag = flag;

    /* Allocate space for storing item on/off status */
    status = malloc(sizeof(int) * item_no);
    assert_ptr(status, "dialog_checklist");

    /* Initializes status */
    for (i = 0; i < item_no; i++)
	status[i] = !dlg_strcmp(ItemStatus(i), "on");

    max_choice = MIN(list_height, item_no);

    x = box_x_ordinate(width);
    y = box_y_ordinate(height);

    dialog = new_window(height, width, y, x);

    mouse_setbase(x, y);

    draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
    draw_bottom_box(dialog);
    draw_title(dialog, title);

    wattrset(dialog, dialog_attr);
    print_autowrap(dialog, prompt, height, width);

    list_width = width - 6;
    getyx(dialog, cur_y, cur_x);
    box_y = cur_y + 1;
    box_x = (width - list_width) / 2 - 1;

    /* create new window for the list */
    list = sub_window(dialog, list_height, list_width,
		      y + box_y + 1, x + box_x + 1);

    /* draw a box around the list items */
    draw_box(dialog, box_y, box_x,
	     list_height + 2 * MARGIN,
	     list_width + 2 * MARGIN,
	     menubox_border_attr, menubox_attr);

    text_width = 0;
    name_width = 0;
    /* Find length of longest item to center checklist */
    for (i = 0; i < item_no; i++) {
	text_width = MAX(text_width, (int) strlen(ItemText(i)));
	name_width = MAX(name_width, (int) strlen(ItemName(i)));
    }

    /* If the name+text is wider than the list is allowed, then truncate
     * one or both of them.  If the name is no wider than 1/4 of the list,
     * leave it intact.
     */
    use_width = (list_width - 6);
    if (text_width + name_width > use_width) {
	int need = 0.25 * use_width;
	if (name_width > need) {
	    int want = use_width * ((double) name_width) / (text_width + name_width);
	    name_width = (want > need) ? want : need;
	}
	text_width = use_width - name_width;
    }

    check_x = (use_width - (text_width + name_width)) / 2;
    item_x = name_width + check_x + 6;

    /* Print the list */
    for (i = 0; i < max_choice; i++)
	print_item(list,
		   ItemData(i),
		   status[i], i, i == choice);
    (void) wnoutrefresh(list);

    /* register the new window, along with its borders */
    mouse_mkbigregion(box_y + 1, box_x, list_height, list_width + 2,
		      KEY_MAX, 1, 1, 1 /* by lines */ );

    dlg_draw_arrows(dialog, scrollamt,
		    scrollamt + max_choice < item_no - 1,
		    box_x + check_x + 5,
		    box_y,
		    box_y + list_height + 1);

    dlg_draw_buttons(dialog, height - 2, 0, buttons, 0, FALSE, width);

    wtimeout(dialog, WTIMEOUT_VAL);

    while (result == DLG_EXIT_UNKNOWN) {
	key = mouse_wgetch(dialog, &fkey);

	if (fkey && (key >= (M_EVENT + KEY_MAX))) {
	    getyx(dialog, cur_y, cur_x);
	    /* De-highlight current item */
	    print_item(list,
		       ItemData(scrollamt + choice),
		       status[scrollamt + choice], choice, FALSE);
	    /* Highlight new item */
	    choice = (key - (M_EVENT + KEY_MAX));
	    print_item(list,
		       ItemData(scrollamt + choice),
		       status[scrollamt + choice], choice, TRUE);
	    (void) wnoutrefresh(list);
	    (void) wmove(dialog, cur_y, cur_x);

	    key = ' ';		/* force the selected item to toggle */
	    fkey = FALSE;
	}

	/*
	 * A space toggles the item status.  We handle either a checklist
	 * (any number of items can be selected) or radio list (zero or one
	 * items can be selected).
	 */
	if (key == ' ') {
	    getyx(dialog, cur_y, cur_x);
	    if (flag == FLAG_CHECK) {	/* checklist? */
		status[scrollamt + choice] = !status[scrollamt + choice];
		print_item(list,
			   ItemData(scrollamt + choice),
			   status[scrollamt + choice], choice, TRUE);
	    } else {		/* radiolist */
		if (!status[scrollamt + choice]) {
		    for (i = 0; i < item_no; i++)
			status[i] = FALSE;
		    status[scrollamt + choice] = TRUE;
		    for (i = 0; i < max_choice; i++)
			print_item(list,
				   ItemData(scrollamt + i),
				   status[scrollamt + i], i, i == choice);
		}
	    }
	    (void) wnoutrefresh(list);
	    (void) wmove(dialog, cur_y, cur_x);
	    wrefresh(dialog);
	    continue;		/* wait for another key press */
	} else if (key == ESC) {
	    result = DLG_EXIT_ESC;
	    continue;
	}

	if (!fkey) {
	    fkey = TRUE;
	    switch (key) {
	    case '\n':
	    case '\r':
		key = KEY_ENTER;
		break;
	    case '-':
		key = KEY_UP;
		break;
	    case '+':
		key = KEY_DOWN;
		break;
	    case TAB:
		key = KEY_RIGHT;
		break;
	    default:
		fkey = FALSE;
		break;
	    }
	}

	/*
	 * Check if key pressed matches first character of any item tag in
	 * list.  If there is more than one match, we will cycle through
	 * each one as the same key is pressed repeatedly.
	 */
	found = FALSE;
	if (!fkey) {
	    for (j = scrollamt + choice + 1; j < item_no; j++) {
		if (dlg_match_char(dlg_last_getc(), ItemName(j))) {
		    found = TRUE;
		    i = j - scrollamt;
		    break;
		}
	    }
	    if (!found) {
		for (j = 0; j <= scrollamt + choice; j++) {
		    if (dlg_match_char(dlg_last_getc(), ItemName(j))) {
			found = TRUE;
			i = j - scrollamt;
			break;
		    }
		}
	    }
	    if (found)
		dlg_flush_getc();
	}

	/*
	 * A single digit (1-9) positions the selection to that line in the
	 * current screen.
	 */
	if (!found
	    && (key <= '9')
	    && (key > '0')
	    && (key - '1' < max_choice)) {
	    found = TRUE;
	    i = key - '1';
	}

	if (!found) {
	    if (fkey) {
		found = TRUE;
		switch (key) {
		case KEY_HOME:
		    i = -scrollamt;
		    break;
		case KEY_LL:
		case KEY_END:
		    i = item_no - 1 - scrollamt;
		    break;
		case M_EVENT + KEY_PPAGE:
		case KEY_PPAGE:
		    if (choice)
			i = 0;
		    else if (scrollamt != 0)
			i = -MIN(scrollamt, max_choice);
		    else
			continue;
		    break;
		case M_EVENT + KEY_NPAGE:
		case KEY_NPAGE:
		    i = MIN(choice + max_choice, item_no - scrollamt - 1);
		    break;
		case KEY_UP:
		    i = choice - 1;
		    if (choice == 0 && scrollamt == 0)
			continue;
		    break;
		case KEY_DOWN:
		    i = choice + 1;
		    if (scrollamt + choice >= item_no - 1)
			continue;
		    break;
		default:
		    found = FALSE;
		    break;
		}
	    }
	}

	if (found) {
	    if (i != choice) {
		getyx(dialog, cur_y, cur_x);
		if (i < 0 || i >= max_choice) {
#if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR < 5
		    /*
		     * Using wscrl to assist ncurses scrolling is not needed
		     * in version 5.x
		     */
		    if (i == -1) {
			if (list_height > 1) {
			    /* De-highlight current first item */
			    print_item(list,
				       ItemData(scrollamt),
				       status[scrollamt], 0, FALSE);
			    scrollok(list, TRUE);
			    wscrl(list, -1);
			    scrollok(list, FALSE);
			}
			scrollamt--;
			print_item(list,
				   ItemData(scrollamt),
				   status[scrollamt], 0, TRUE);
		    } else if (i == max_choice) {
			if (list_height > 1) {
			    /* De-highlight current last item before scrolling up */
			    print_item(list,
				       ItemData(scrollamt + max_choice - 1),
				       status[scrollamt + max_choice - 1],
				       max_choice - 1, FALSE);
			    scrollok(list, TRUE);
			    wscrl(list, 1);
			    scrollok(list, FALSE);
			}
			scrollamt++;
			print_item(list,
				   ItemData(scrollamt + max_choice - 1),
				   status[scrollamt + max_choice - 1],
				   max_choice - 1, TRUE);
		    } else
#endif
		    {
			if (i < 0) {
			    scrollamt += i;
			    choice = 0;
			} else {
			    choice = max_choice - 1;
			    scrollamt += (i - max_choice + 1);
			}
			for (i = 0; i < max_choice; i++) {
			    print_item(list,
				       ItemData(scrollamt + i),
				       status[scrollamt + i], i, i == choice);
			}
		    }
		    (void) wnoutrefresh(list);
		    dlg_draw_arrows(dialog, scrollamt,
				    scrollamt + choice < item_no - 1,
				    box_x + check_x + 5,
				    box_y,
				    box_y + list_height + 1);
		} else {
		    /* De-highlight current item */
		    print_item(list,
			       ItemData(scrollamt + choice),
			       status[scrollamt + choice], choice, FALSE);
		    /* Highlight new item */
		    choice = i;
		    print_item(list,
			       ItemData(scrollamt + choice),
			       status[scrollamt + choice], choice, TRUE);
		    (void) wnoutrefresh(list);
		    (void) wmove(dialog, cur_y, cur_x);
		    wrefresh(dialog);
		}
	    }
	    continue;		/* wait for another key press */
	}

	if (fkey) {
	    switch (key) {
	    case KEY_ENTER:
		result = dlg_ok_buttoncode(button);
		break;
	    case KEY_BTAB:
	    case KEY_LEFT:
		button = dlg_prev_button(buttons, button);
		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
				 FALSE, width);
		break;
	    case KEY_RIGHT:
		button = dlg_next_button(buttons, button);
		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
				 FALSE, width);
		break;
	    default:
		if (key >= M_EVENT) {
		    if ((key2 = dlg_ok_buttoncode(key - M_EVENT)) >= 0) {
			result = key2;
			break;
		    }
		    beep();
		}
	    }
	} else {
	    beep();
	}
    }

    del_window(dialog);
    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
	for (i = 0; i < item_no; i++) {
	    if (status[i]) {
		if (flag == FLAG_CHECK) {
		    if (separate_output) {
			dlg_add_result(ItemName(i));
			dlg_add_result("\n");
		    } else {
			dlg_add_result("\"");
			dlg_add_result(ItemName(i));
			dlg_add_result("\" ");
		    }
		} else {
		    dlg_add_result(ItemName(i));
		}
	    }
	}
	break;
    case DLG_EXIT_HELP:
	dlg_add_result("HELP ");
	if (USE_ITEM_HELP(ItemHelp(scrollamt + choice))) {
	    dlg_add_result(ItemHelp(scrollamt + choice));
	    result = DLG_EXIT_OK;	/* this is inconsistent */
	} else {
	    dlg_add_result(ItemName(scrollamt + choice));
	}
	break;
    }
    mouse_free_regions();
    free(status);
    free(prompt);
    return result;
}
#include "std/LogInterface.h"

BuildingItem::BuildingItem( const QString& name )
	: ItemTypeBase("BuildingItem"),
	m_Name(name)
{

}

const QString& BuildingItem::GetName() const
{
	return m_Name;
}

//================================================================================
const ItemData BuildingItemPrototypeRepository::on_completion = ItemData("on_completion",QVariant(QString()));
const ItemData BuildingItemPrototypeRepository::completion_size = ItemData("completion_size",QVariant(QVariant::Double));
const ItemData BuildingItemPrototypeRepository::air_capacity = ItemData("air_capacity",QVariant(QVariant::Int));
const ItemData BuildingItemPrototypeRepository::capital = ItemData("capital",QVariant(QVariant::Bool));
const ItemData BuildingItemPrototypeRepository::onmap = ItemData("onmap",QVariant(QVariant::Bool));
const ItemData BuildingItemPrototypeRepository::cost = ItemData("cost",QVariant(QVariant::Double));
const ItemData BuildingItemPrototypeRepository::time = ItemData("time",QVariant(QVariant::Int));
const ItemData BuildingItemPrototypeRepository::max_level = ItemData("max_level",QVariant(QVariant::Int));
const ItemData BuildingItemPrototypeRepository::visibility = ItemData("visibility",QVariant(QVariant::Bool));
const ItemData BuildingItemPrototypeRepository::naval_capacity = ItemData("naval_capacity",QVariant(QVariant::Int));
const ItemData BuildingItemPrototypeRepository::port = ItemData("port",QVariant(QVariant::Bool));
const ItemData BuildingItemPrototypeRepository::coastal_fort_level = ItemData("coastal_fort_level",QVariant(QVariant::Int));
const ItemData BuildingItemPrototypeRepository::orientation = ItemData("orientation",QVariant(QVariant::Bool));
const ItemData BuildingItemPrototypeRepository::fort_level = ItemData("fort_level",QVariant(QVariant::Int));
const ItemData BuildingItemPrototypeRepository::local_anti_air = ItemData("local_anti_air",QVariant(QVariant::Int));
const ItemData BuildingItemPrototypeRepository::damage_factor = ItemData("damage_factor",QVariant(QVariant::Double));
Example #17
0
/**
 * \brief ładuje dane itemów z pliku
 * \details ładuje dane itemów z pliku oraz loguje informacje do pliku
 * \param nazwa pliku XML z danymi itemów
 * \return powodzenie operacji
 */
bool ItemManager::loadItems(std::string name)
{
    TiXmlDocument doc(name.c_str());
    if(!doc.LoadFile())
    {
        LOG(ERROR) << "Nie udało sie wczytać pliku \"" << name << "\".";
        return false;
    }
    TiXmlElement *items = doc.FirstChildElement("items");
    TiXmlElement *item = items->FirstChildElement("item");
    std::wstring nline_pattern = L"\\n";
    while(item)
    {
        unsigned int _attack,_quality,_price,_defence,_power;
        double _speed;
        std::wstring name,desc;
        int gid = (atoi(item->Attribute("gid")) );
        name = wide_string<std::wstring>(item->Attribute("name"));
        TiXmlElement* descr = item->FirstChildElement("desc");
        desc = wide_string<std::wstring>(descr->GetText());

        size_t pos = 0;
        while ((pos = desc.find(L"\\n", pos)) != std::string::npos)
        {
            desc.replace(pos-nline_pattern.length(),4,L"\n\n");
        }
        TiXmlElement* data = descr->NextSiblingElement("data");
        ITEM_TYPE typen = (ITEM_TYPE)atoi(item->Attribute("type"));
        switch(typen)
        {
        case WEAPON:
            // Bronie mogą miec
            // Atak, szybkość, obrone, moc, jakość, cene
            if(data->Attribute("attack")  == NULL || data->Attribute("speed") == NULL ||
                    data->Attribute("defence") == NULL || data->Attribute("power") == NULL ||
                    data->Attribute("quality") == NULL || data->Attribute("price") == NULL)
            {
                LOG(ERROR) << "Brakuje atrybutu itemka \"" << name <<  "\".";
                return false;
            }
            _attack = atoi(data->Attribute("attack"));
            _speed = atoi(data->Attribute("speed"));
            _power = atof(data->Attribute("power"));
            _quality = atoi(data->Attribute("quality"));
            _price = atoi(data->Attribute("price"));
            _defence = atoi(data->Attribute("defence"));
            break;
            // Zbroje mogą mieć
            // Obrone, jakość, moc, cene
        case ARMOR:
            if(data->Attribute("defence") == NULL || data->Attribute("price") == NULL ||
                    data->Attribute("quality") == NULL || data->Attribute("power") == NULL  )
            {
                LOG(ERROR) << "Brakuje atrybutu itemka \"" << name << "\".";
                return false;
            }
            _attack = _speed;
            _power = atoi(data->Attribute("power"));
            _defence = atoi(data->Attribute("defence"));
            _quality = atoi(data->Attribute("quality"));
            _price = atoi(data->Attribute("price"));
            break;
            //Potiony mogą mieć
            //Moc i cene
        case RECOVERY:
            if(data->Attribute("power") == NULL || data->Attribute("price") == NULL)
            {
                LOG(ERROR)<< "Brakuje atrybutu itemka \"" << name << "\".";
                return false;
            }
            _attack = _defence = _speed = _quality = 0;
            _speed = 0;
            _power = atoi(data->Attribute("power"));
            _price = atoi(data->Attribute("price"));
            break;

        default:
            _attack = _defence = _quality = _power = _price  = 0;
            _speed  = 0.0f;
        }
        itemsinfo.push_back(ItemData(typen, desc, name,_attack,_defence,_quality,_price,_power,_speed,gid));
        item = item->NextSiblingElement("item");
    }
    LOG(ERROR) << "Załadowano dane " << itemsinfo.size() << " itemów.";
    return true;
}
Example #18
0
inline void CListView::ItemPtr(size_t nItem, const void* pData)
{
	ItemData(nItem, reinterpret_cast<LPARAM>(pData));
}
Example #19
0
inline void* CListView::ItemPtr(size_t nItem) const
{
	return reinterpret_cast<void*>(ItemData(nItem));
}
Example #20
0
	RecordConstRef RecordArray::operator[] (unsigned int index) const
	{
		return RecordConstRef(prototype_.Get(), ItemData(index));
	}
Example #21
0
/*
 * Display a menu for choosing among a number of options
 */
int
dialog_menu(const char *title, const char *cprompt, int height, int width,
            int menu_height, int item_no, const char **items)
{
    int i, j, x, y, cur_x, cur_y, box_x, box_y;
    int key = 0;
    int button = 0;
    int choice = dlg_default_item(items, MENUBOX_TAGS);
    int scrollamt = 0;
    int max_choice, min_width;
    int found;
    int use_width, name_width, text_width;
    WINDOW *dialog, *menu;
    char *prompt = strclone(cprompt);
    const char **buttons = dlg_ok_labels();

    tab_correct_str(prompt);
    if (menu_height == 0) {
        min_width = calc_listw(item_no, items, MENUBOX_TAGS) + 10;
        /* calculate height without items (4) */
        auto_size(title, prompt, &height, &width, 4, MAX(26, min_width));
        calc_listh(&height, &menu_height, item_no);
    } else {
        auto_size(title, prompt, &height, &width, 4 + menu_height, 26);
    }
    print_size(height, width);
    ctl_size(height, width);

    max_choice = MIN(menu_height, item_no);

    x = box_x_ordinate(width);
    y = box_y_ordinate(height);

    dialog = new_window(height, width, y, x);

    mouse_setbase(x, y);

    draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
    draw_bottom_box(dialog);
    draw_title(dialog, title);

    wattrset(dialog, dialog_attr);
    print_autowrap(dialog, prompt, height, width);

    menu_width = width - 6;
    getyx(dialog, cur_y, cur_x);
    box_y = cur_y + 1;
    box_x = (width - menu_width) / 2 - 1;

    /* create new window for the menu */
    menu = sub_window(dialog, menu_height, menu_width, y + box_y + 1,
                      x + box_x + 1);

    /* draw a box around the menu items */
    draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
             menubox_border_attr, menubox_attr);

    name_width = 0;
    text_width = 0;
    /* Find length of longest item to center menu */
    for (i = 0; i < item_no; i++) {
        name_width = MAX(name_width, (int) strlen(ItemName(i)));
        text_width = MAX(text_width, (int) strlen(ItemText(i)));
    }

    /* If the name+text is wider than the list is allowed, then truncate
     * one or both of them.  If the name is no wider than 1/4 of the list,
     * leave it intact.
     */
    use_width = (menu_width - 2);
    if (text_width + name_width > use_width) {
        int need = 0.25 * use_width;
        if (name_width > need) {
            int want = use_width * ((double) name_width) / (text_width + name_width);
            name_width = (want > need) ? want : need;
        }
        text_width = use_width - name_width;
    }

    tag_x = (use_width - text_width - name_width) / 2;
    item_x = name_width + tag_x + 2;

    if (choice - scrollamt >= max_choice) {
        scrollamt = choice - (max_choice - 1);
        choice = max_choice - 1;
    }

    /* Print the menu */
    for (i = 0; i < max_choice; i++)
        print_item(menu, ItemData(i + scrollamt), i, i == choice);
    (void) wnoutrefresh(menu);

    /* register the new window, along with its borders */
    mouse_mkbigregion(box_y, box_x, menu_height + 2, menu_width + 2,
                      item_no, item_x,	/* the threshold */
                      1 /* dirty mode */ );

    dlg_draw_arrows(dialog, scrollamt,
                    scrollamt + max_choice < item_no,
                    box_x + tag_x + 1,
                    box_y,
                    box_y + menu_height + 1);

    dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);

    wtimeout(dialog, WTIMEOUT_VAL);

    while (key != ESC) {
        key = mouse_wgetch(dialog);
        /* Check if key pressed matches first character of any
           item tag in menu */
        for (i = 0; i < max_choice; i++)
            if (toupper(key) == toupper(UCH(ItemName(scrollamt + i)[0])))
                break;

        /*
         * Check if key pressed matches first character of any item tag in
         * list.  If there is more than one match, we will cycle through
         * each one as the same key is pressed repeatedly.
         */
        found = FALSE;
        for (j = scrollamt + choice + 1; j < item_no; j++) {
            if (toupper(key) ==
                    toupper(UCH(ItemName(j)[0]))) {
                found = TRUE;
                i = j - scrollamt;
                break;
            }
        }
        if (!found) {
            for (j = 0; j <= scrollamt + choice; j++) {
                if (toupper(key) ==
                        toupper(UCH(ItemName(j)[0]))) {
                    found = TRUE;
                    i = j - scrollamt;
                    break;
                }
            }
        }

        /*
         * A single digit (1-9) positions the selection to that line in the
         * current screen.
         */
        if (!found
                && (key <= '9')
                && (key > '0')
                && (key - '1' <= max_choice)) {
            found = TRUE;
            i = key - '1';
        }

        if (!found) {
            found = TRUE;
            switch (key) {
            case KEY_HOME:
                i = -scrollamt;
                break;
            case KEY_LL:
            case KEY_END:
                i = item_no - 1 - scrollamt;
                break;
            case KEY_PPAGE:
                if (choice)
                    i = 0;
                else if (scrollamt != 0)
                    i = -MIN(scrollamt, max_choice);
                else
                    continue;
                break;
            case KEY_NPAGE:
                i = MIN(choice + max_choice, item_no - scrollamt - 1);
                break;
            case KEY_UP:
            case '-':
                i = choice - 1;
                if (choice == 0 && scrollamt == 0)
                    continue;
                break;
            case KEY_DOWN:
            case '+':
                i = choice + 1;
                if (scrollamt + choice >= item_no - 1)
                    continue;
                break;
            default:
                found = FALSE;
                break;
            }
        }

        if (found) {
            if (i != choice) {
                getyx(dialog, cur_y, cur_x);
                if (i < 0 || i >= max_choice) {
#if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR < 5
                    /*
                     * Using wscrl to assist ncurses scrolling is not needed
                     * in version 5.x
                     */
                    if (i == -1) {
                        if (menu_height > 1) {
                            /* De-highlight current first item */
                            print_item(menu, ItemData(scrollamt), 0, FALSE);
                            scrollok(menu, TRUE);
                            wscrl(menu, -1);
                            scrollok(menu, FALSE);
                        }
                        scrollamt--;
                        print_item(menu, ItemData(scrollamt), 0, TRUE);
                    } else if (i == max_choice) {
                        if (menu_height > 1) {
                            /* De-highlight current last item before scrolling up */
                            print_item(menu,
                                       ItemData(scrollamt + max_choice - 1),
                                       max_choice - 1, FALSE);
                            scrollok(menu, TRUE);
                            wscrl(menu, 1);
                            scrollok(menu, FALSE);
                        }
                        scrollamt++;
                        print_item(menu,
                                   ItemData(scrollamt + max_choice - 1),
                                   max_choice - 1, TRUE);
                    } else
#endif
                    {
                        if (i < 0) {
                            scrollamt += i;
                            choice = 0;
                        } else {
                            choice = max_choice - 1;
                            scrollamt += (i - max_choice + 1);
                        }
                        for (i = 0; i < max_choice; i++) {
                            print_item(menu,
                                       ItemData(scrollamt + i),
                                       i, i == choice);
                        }
                    }
                    (void) wnoutrefresh(menu);
                    dlg_draw_arrows(dialog, scrollamt,
                                    scrollamt + choice < item_no - 1,
                                    box_x + tag_x + 1,
                                    box_y,
                                    box_y + menu_height + 1);
                } else {
                    /* De-highlight current item */
                    print_item(menu,
                               ItemData(scrollamt + choice),
                               choice, FALSE);
                    /* Highlight new item */
                    choice = i;
                    print_item(menu,
                               ItemData(scrollamt + choice),
                               choice, TRUE);
                    (void) wnoutrefresh(menu);
                    (void) wmove(dialog, cur_y, cur_x);
                    wrefresh(dialog);
                }
            }
            continue;		/* wait for another key press */
        }

        switch (key) {
        case M_EVENT + 'O':
            del_window(dialog);
            return scrollamt + choice;
        case M_EVENT + 'C':
            del_window(dialog);
            return -2;
        case M_EVENT + 'o':	/* mouse enter... */
        case M_EVENT + 'c':	/* use the code for toggling */
            button = (key == M_EVENT + 'o');
        /* FALLTHRU */
        case ' ':
        case KEY_BTAB:
        case TAB:
        case KEY_LEFT:
        case KEY_RIGHT:
            if (!dialog_vars.nocancel)
                button = !button;
            dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
            break;
        case '\n':
            del_window(dialog);
            return (button ? -2 : (scrollamt + choice));
        }
    }

    del_window(dialog);
    return -1;			/* ESC pressed */
}
Example #22
0
void DefaultMenuModel::addItem(std::string text, bool enabled, bool checked)
{
	myItems.push_back(ItemData(text, enabled, checked, false));

	notify();
}
Example #23
0
void DefaultMenuModel::addSeparator()
{
	myItems.push_back(ItemData("", false, false, true));

	notify();
}