)
In a NSPopupButton I have to store different items. These can often change depending on other actions:
NSArray* array = [NSArray arrayWithArray:mynewobject];
// Obviously I do not know which items will be found by mynewobject
//[_myPopupButton removeAllItems]; // ...But I want to mantain itemAtIndex:0!!
// ..and then:
for (NSDictionary *dict in array)
{
[_myPopupButton addItemWithTitle:[[dict objectForKey:miciomicio] lastPathComponent]];
}
My intention is to delete old items and then add the new ones. Is possible to do this while maintaining item at index 0?
...It would be nice!
NSMenuItem *firstItem = [_myPopupButton itemAtIndex:0];
[_myPopupButton removeAllItems];
[[_myPopupButton menu] addItem:firstItem];
Related
How i should add and remove series from qchart?
The main mess is that QChart some how store QAxis and QSeries, QSeries themselves refer to QAxis.Above that all that objects are heavy connected.
So instead of pseudo code like this:
void someclass::set_series(QLineSeries*someQLineSeries){
somechart->removeAllSeries();
somechart->removeAllAxis();
somechart->addSeries(someQLineSeries);
}
I should use that:
(zlineseries additionaly store 2 pointers to its axis)
void zhplotview::attach_dt_series(ZLineSeries *series)
if(chart)
{
qDebug()<<"NOT DELETED CHART";
if(viewer)
{
qDebug()<<"NOT DELETED VIEWER";
qDebug()<<"Okay. Try to clear old links and create chart again";
//let chart have 1 series
auto slist=chart->series();
ZLineSeries *old_series=dynamic_cast<ZLineSeries*>(slist.at(0));
old_series->detachAxis(old_series->axis_x);
old_series->detachAxis(old_series->axis_y);
chart->removeAxis(old_series->axis_x);
chart->removeAxis(old_series->axis_y);
vbl->removeWidget(viewer);
chart->removeSeries(old_series);
disconnect(viewer);
disconnect(chart);
delete chart;
delete viewer;
}
else
{
qDebug()<<"chart is 0, but viewer not";
return;
}
}
chart=new QChart();
chart->addSeries(series);
chart->addAxis(series->axis_x,Qt::AlignBottom);
chart->addAxis(series->axis_y,Qt::AlignLeft);
series->attachAxis(series->axis_x);
series->attachAxis(series->axis_y);
viewer=new QZChartView(chart,this);
vbl->addWidget(viewer);
I know it's three years later, but I use a little workaround for this, maybe it's interesting for someone.
On every delta I generate a new chart, and just replace the old one. In order to be fast enough, I keep some data pre-calculated in stack.
I want to show in a QTreeWidget, hierarchically, some data extracted from a DB.
I thought that a way to do this is converting the data to show in QTreeWidgetItems.
But in that way, i have to create the objects (QTreeWidgetItems) in runtime. And this is the problem. I don't know how to do it.
How can I do this? Or is there a better way to show it?
Example of what I want:
EDIT:
The data that will be retrieved and shown hierarchically is:
Universities, areas, carreers and the total amount of each one.
EDIT 2:
For if you need i will add more information:
QTreeWidgetItem *itm = new QTreeWidgetItem(ui->treeWidget);
itm->setText(0, "University 1");
QTreeWidgetItem *itm2 = new QTreeWidgetItem(itm);
itm2->setText(0,"Area 1 ");
QTreeWidgetItem * itm3 = new QTreeWidgetItem(itm2);
itm3->setText(0,"Lawyer");
QTreeWidgetItem *itm4 = new QTreeWidgetItem(ui->treeWidget);
itm4->setText(0, "University 2");
QTreeWidgetItem *itm5 = new QTreeWidgetItem(itm4);
itm5->setText(0, "Area 2");
QTreeWidgetItem *itm6 = new QTreeWidgetItem(itm5);
itm6->setText(0, "Systems engineering");
The code above is like i want but hardcoded. I need to do this with dynamic information retrieved from a DB. I can carry the records to memory, this is not the problem. The problem is how to show this records in differents QTreeWidgetItem, given that the number of "objects" (records of the DB) can be more or less in different time.
EDIT3 - SOLVED:
I think that I have to create dynamically the objects.
I don't know that I can do some like this:
for(int i = 0; i < 10; i++){
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
item->setText(0, QString::number(i));
}
I have a table view populated with data of Vehicle objects stored in a QList<Vehicle> cars; On this cars list i have to make some actions: search, add, edit, delete; After every action of search, i store the founded objects in another list to populate the table view only with this objects, keeping the original list intact. The original list gets modified only on add, edit or delete. Here comes the problem: i search for an object that i want to edit, it is shown in the table view, i select it and press the edit button; i am using QModelIndexList to get the index of the row. The index of the row will give me the position from the "founded" list, and i need to modify the object in the original list. Below is my implementation.
Is there any other way to this thing without the temporary list? How can i modify the original object using Iterator, instead that for loop?
void MainWindow::on_actionEdit_triggered()
{
QMessageBox msgBox;
QModelIndexList id = ui->tableView->selectionModel()->selectedIndexes();
if(id.isEmpty()){
msgBox.setWindowTitle("Message");
msgBox.setText("Please select a row");
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
} else{
int row = id.at(0).row();
QUuid carId = temp.at(row).getVehicleID(); // temp -> the "the founded" list
for(int i = 0; i < cars.size(); i++){
Vehicle& current = cars[i];
Vehicle& currentTemp = temp[row];
if(carId == current.getVehicleID() && carId == currentTemp.getVehicleID()){
addDialog = new AddEditDialog(this);
addDialog->loadVehicleToEdit(current);
addDialog->exec();
if(addDialog->getIsEdited()){
current = addDialog->getVehicleToAdd();
currentTemp = addDialog->getVehicleToAdd();
currentTemp.setVehicleId(carId);
current.setVehicleId(carId);
}
}
}
}
//create header
createHeader(model);
//set data to the table view
populate(temp);
}
May be you use proxy model and you need to call mapToSource?
By default Sitecore workbox displays the Item name, and sort the item list by Item name.
In one of my previous posts regarding this I managed to change the item name to a custom field.
Now I need to sort workbox by this field. How can I do this?
Assuming that you already have your own implementation of the WorkboxForm as described in the post you linked in your question, you need to change the code of the DisplayState method.
The DataUri[] items inflow parameter of this method gives you the list of all items which are in given state of the workflows. You need to retrieve all the Sitecore items from this parameter and sort them:
DataUri[] items = new DataUri[0];
List<Item> sitecoreItems = items
.Select(uri => Context.ContentDatabase.Items[uri])
.OrderBy(item => item["YourCustomField"])
.ToList();
And use the new list for selecting the current page items. This solution is not optimized for the performance - you need to get every item in given state from database so you can access the custom field.
After studying Sitecore workbox modifications, I came across with following solution.
Step 1 - Modify the GetItems method as follows,
private DataUri[] GetItems(WorkflowState state, IWorkflow workflow)
{
if (workflow != null)
{
var items = workflow.GetItems(state.StateID);
Array.Sort(items, new Comparison<DataUri>(CompareDataUri));
return items;
}
return new DataUri[] { };
}
Here comes the "CompareDataUri" method,
private int CompareDataUri(DataUri x, DataUri y)
{
//Custom method written to compare two values - Dhanuka
Item itemX = Sitecore.Context.ContentDatabase.GetItem(x);
Item itemY = Sitecore.Context.ContentDatabase.GetItem(y);
string m_sortField = "__Updated";
bool m_descSort = false;
var res = 0;
res = string.Compare(itemX[m_sortField], itemY[m_sortField]);
if (m_descSort)
{
if (res > 0)
return -1;
if (res < 0)
return 1;
}
return res;
}
This approach is optimized for performance.
How do I create a CCMenuItem list dynamically?
//Returns me an array with my items
Items *items = [ItemParser loadItemsForLevel:selectedLevel fromSuperLevel:selectedSuperLevel];
For an item I have a string with the name of the item that I'd like to display in my CCMenu. The number of items could vary but I want to display only 6 items at a time
and how do I remove it? I'm cleaning up from the CCLayer but I'd like to do it also from the menu list
Anyone?
Cocos2D does not provide a method to do this.
You may create your own initializer based on the original one found in "CCMenu.m".
The original looks like this (I removed code that does not add items here for clarity). Create your own init method based on the original and add a variable amount of items instead. If you like you may also set it up as a category to CCMenu.
-(id) initWithItems: (CCMenuItem*) item vaList: (va_list) args
{
if( (self=[super init]) ) {
// ... code cut for clarity
if (item) {
[self addChild: item z:z];
CCMenuItem *i = va_arg(args, CCMenuItem*);
while(i) {
z++;
[self addChild: i z:z];
i = va_arg(args, CCMenuItem*);
}
}
// ... code cut for clarity
}
return self;
}
Update:
When your menu items change then rebuild the whole menu.