I have selected row, and I need to add some data right below it. Row is selected with OrderTable selectedOrderTable = orderTableId.getSelectionModel().getSelectedItem(); and new one is added with data.add(new OrderTable( ... )) It's adding OK to table, just at bottom of it, and I need to add it right below selected row selectedOrderTable.
Just call the add method taking an index:
int index = orderTableId.getSelectionModel().getSelectedIndex();
data.add(index + 1, new OrderTable(...));
Related
I have a problem, i want to return the selected Rows values, and the columns separately, i found a method to return both of them using the function cell(row, column), but i want to get them separately
Here is my code :
QTableWidgetItem *c = new QTableWidgetItem();
QMap<QString,int> lists;
for(i=0;i<range.rowCount();++i){
for(int j=0;j<range.columnCount();++j){
c=item(i,j);// here i can return the Rows, Columns Data
QMessageBox::information(this,"",c->text());
}
}
As you can see this code is working, but i just want to return the Rows and the Columns separately so i can put them in my QMap<QString,int> list.
And the purpose of all this is to try to draw a piechart from the selected rows and columns
So Any help please
Here is what I understood from the comments, feel free to correct me and I'll update my answer if necessary.
COL1 | COL2
NAME | VALUE
So when you select a cell, you actually care about the whole row, a.k.a the name of the row and the value associated. If this is the case, it would make more sense to only allow the user to select whole rows, instead of cells. setSelectionBehavior(QAbstractItemView::SelectRows); should do the trick.
Provided that the name of the dataset is always in column 1, and the value in column 2, you should update your code with the snippet:
QTableWidgetItem *c; //Deleted memory leak in your code.
QMap<QString,double> myMap; //Don't name it a list if it is explicitly a map.
for(i=0;i<range.rowCount();++i){
QString dataName = item(i,0)->text();
int dataValue;
for(int j=1;j<range.columnCount();++j){
c=item(i,j);// here i can return the Rows, Columns Data
dataValue += c->text().toDouble();
//If you always have 2 columns only, dataValue will be the value you are looking for.
//If you can have more than 2 columns, dataValue will be the sum of all the cells located after the column 0, on the same row.
//Change this depending on how you want to treat those values.
QMessageBox::information(this,dataName,c->text());
}
myMap[dataName]=dataValue;
}
EDIT for QPieSeries, following this example:
QPieSeries *series = new QPieSeries();
QMap<QString,double>::iterator it = myMap.begin();
QMap<QString,double>::iterator end = myMap.end();
for(; it!=end; ++it){
series->append(it->key(), it->value());
}
QPieSlice *slice = series->slices().at(1);
slice->setExploded();
slice->setLabelVisible();
slice->setPen(QPen(Qt::darkGreen, 2));
slice->setBrush(Qt::green);
QChart *chart = new QChart();
chart->addSeries(series);
chart->setTitle("My Data");
chart->legend()->hide();
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
/*change with your window here*/
yourWindow.setCentralWidget(chartView);
I need to select a particular row in a table with selenium web driver, I have close to 5000 rows, Navigating through each row would be difficult. Any better approach if we have?
You need to click on a checkbox to select the row right?
I'll assume thats what you meant:
The only way I know how is to check each row, select the filter (i.e. a customer number) and once you find it, click on the selection checkbox.
Mostly of the tables are similar so here is an example:
This is your table:
= = = = = = =
=================================================================================================
= = = = = = =
=================================================================================================
= = = = = = =
=================================================================================================
Lets say that in the first row, is where the checkbox is, and that in the second row is the location of the filter.
meaning the data you will use in order to know that this is the row you need....
you will need to inspect the table element in order to find its ID, once you have that info you can use a similar method as the below:
Where you will use your webdriver, data filter, tableID and the number of the column where your data filter is located.
The method will return the row you need to click, then you can simply use the row[columnNumberLocation].Click() in order to select it.
public IWebElement returnRow(IWebDriver webDriver, string filter ,string tableName, int i)
{
IWebElement tableElement = webDriver.FindElement(By.Id(tableName));
IWebElement tbodyElement = tableElement.FindElement(By.TagName("TBODY"));
List<IWebElement> rows = new List<IWebElement>(tbodyElement.FindElements(By.TagName("tr")));
foreach (var row in rows)
{
List<IWebElement> cells = new List<IWebElement>(row.FindElements(By.TagName("td")));
if (cells.Count > 0)
{
string s = cells[i].Text;
if (s.Equals(filter))
{
return row;
}
}
}
return null;
}
It depends on what is your requirement of selecting that particular row.
I assume you need to select that according to the row index.
So it's all about the your x-path to locate the element.
ex: I need to get row number 2000
WebElement element = driver.findElement(By.xpath("//tr[2000]"));
I created a QSqlTableModel, set a filter and used a QTableView to show a table of my filtered data. This works as expected...
model = new QSqlTableModel;
model->setTable("XXX");
model->select();
model->setFilter(filter);
table = new QTableView;
table->setModel(model);
However, when I try to compute the sum of all visible values of a column in the table view...
float sum = 0.0f;
for(int i=0;i<model->rowCount();i++)
sum += model->record(i).value("amount").toFloat();
... I get the sum of ALL entries in the table model, NOT only of those items visible in the TableView (where the filter is applied).
How can I make my sum()-function to compute the sum of only those values which are visible in the TableView?
Thank you for your answers!
model = new QSqlTableModel;
model->setTable("XXX");
model->setFilter(filter);
*model->select();//select after set filter*
table = new QTableView;
table->setModel(model);
I have a form where i have some text boxes and a Gridview(with Columns in it).the values entered in textboxes should be added as a row in gridview when pressing a ADD button..below is the code in the click event of ADD button..It add as a single column not as a row..Please help me with this.
BindingList<string> Grid_data = new BindingList<string>();
Grid_data.Add(txtMaterial.Text.ToString());
Grid_data.Add(txtPlastic.Text.ToString());
Grid_data.Add(txtCoatingtype.Text.ToString());
Grid_data.Add(txtManufacturer.Text.ToString());
Grid_data.Add(txtManuDate.Text.ToString());
Grid_data.Add(txtLineSize.Text.ToString());
Grid_data.Add(txtFootage.Text.ToString());
DGMaterial.DataSource = Grid_data;
GV_Material.PopulateColumns();
To begin with, when you write : Grid_data.Add(someString) it adds a new element to the binding list not to the row. You have to understand that each element of the BindingList represents a row, not a value for a cell.
What you should do is the following :
BindingList<List<string>> gridData = new BindingList<List<string>>();
gridData.add(new List<string>() {"someString", "anotherString"}); // Your inputs here
DGMaterial.DataSource = gridData ;
GV_Material.PopulateColumns();
Hope that helps !
My page has a chart that is set up to display data that is coming from a SqlDataSource.
There is a TreeView which contains a list of datapoints that I want to be able to add to the chart as different series. The user selects which item they wish to add by clicking a checkbox in the treeview for that node and then clicks an update button to refresh the chart.
Each node's value is set to a column name in the table.
If there is only one point selected on the treeview the data comes across as a series on the chart with no problem when the update button is clicked.
If multiple items in the treeview are selected an ASP.NET error page appears when clicking the button stating that a column name 'XXXX' was not found where 'XXXX' is the node.Value of the highest item in the tree that was checked.
For example an error saying that "Column with name 'X1' was not found" would show up when using the following selection:
If just 'X1' is checked the data shows up on the chart.
public void UpdateChart(Object sender, EventArgs e)
{
if (TagTreeView.CheckedNodes.Count > 0)
{
foreach (TreeNode node in TagTreeView.CheckedNodes)
{
// Add a series to the chart
Series series = new Series();
series=Chart1.Series.Add("Series"+node.Value);
series.ChartArea = "ChartArea1";
series.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), charts[1], true);
// create a datasource, add it to the page,
SqlDataSource sqlDataSource = new SqlDataSource();
sqlDataSource.ID = "SQLDataSource"+node.Value;
sqlDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["HistoricalDataConnectionString"].ConnectionString;
if (node.Depth > 1)
{
if (node.Parent.Text.Contains("AAA"))
{
MessageBox.Show(node.Value);
sqlDataSource.SelectCommand = "SELECT (Date + CONVERT(datetime,Time)) As TimeStamp, " + node.Value + " FROM AAA ORDER BY TimeStamp";
}
this.Page.Controls.Add(sqlDataSource);
Chart1.DataSourceID = "SQLDataSource"+node.Value;
Chart1.Series["Series" + node.Value].XValueMember = "TimeStamp";
Chart1.Series["Series" + node.Value].YValueMembers = node.Value;
Chart1.DataBind();
}
}
}
}
Is there a way to take each selected item in the TreeView and use the node.value to build a query to add an additional series to the chart? I have done a little bit of work to see if putting the SqlDatasource and Series objects into an array and looping through that but it doesn't seem to be taking me anywhere.
To get this to work correctly all of the datapoints that will be added to the chart need to be included in the select statement for the sqlDataSource:
sqlDataSource.SelectCommand = "SELECT (Date + CONVERT(datetime,Time)) As TimeStamp, X1, X2, X3 FROM AAA ORDER BY TimeStamp";