Skip to content

Commit

Permalink
Show select expressions in column headers in custom queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koefferlein committed Nov 24, 2024
1 parent 76800ea commit 33d1cdc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/db/db/dbLayoutQuery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1938,9 +1938,11 @@ struct SelectFilterPropertyIDs
SelectFilterPropertyIDs (LayoutQuery *q)
{
data = q->register_property ("data", LQ_variant);
expressions = q->register_property ("expressions", LQ_variant);
}

unsigned int data; // data -> An array of the selected values
unsigned int expressions; // data -> An array with the expressions
};

class DB_PUBLIC SelectFilterReportingState
Expand Down Expand Up @@ -2037,7 +2039,16 @@ class DB_PUBLIC SelectFilterState
}
}

virtual void reset (FilterStateBase *previous)
void get_expressions (tl::Variant &v)
{
std::vector<tl::Variant> vd;
v = tl::Variant (vd.begin (), vd.end ());
for (std::vector<tl::Expression>::const_iterator e = m_expressions.begin (); e != m_expressions.end (); ++e) {
v.push (e->text ());
}
}

virtual void reset (FilterStateBase *previous)
{
if (m_has_sorting) {

Expand Down Expand Up @@ -2082,6 +2093,9 @@ class DB_PUBLIC SelectFilterState
if (id == m_pids.data) {
get_data (v);
return true;
} else if (id == m_pids.expressions) {
get_expressions (v);
return true;
} else if (m_in_data_eval) {
return FilterStateBase::get_property (id, v);
} else {
Expand Down
23 changes: 22 additions & 1 deletion src/lay/lay/laySearchReplaceDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ SearchReplaceResults::clear ()
m_has_more = false;
}

void
SearchReplaceResults::set_data_column_headers (const tl::Variant &v)
{
m_data_column_headers = v;
if (v.is_list ()) {
m_data_columns = std::max (v.get_list ().size (), m_data_columns);
}
}

void
SearchReplaceResults::push_back (const tl::Variant &v)
{
Expand Down Expand Up @@ -168,7 +177,13 @@ SearchReplaceResults::headerData (int section, Qt::Orientation /*orientation*/,
{
if (role == Qt::DisplayRole) {
if (! m_data_result.empty ()) {
if (section == 0) {
if (m_data_column_headers.is_list ()) {
if (section < int (m_data_column_headers.get_list ().size ())) {
return QVariant (m_data_column_headers.get_list () [section].to_string ());
} else {
return QVariant (QString ());
}
} else if (section == 0) {
return QVariant (QObject::tr ("Value"));
} else {
return QVariant (QString ());
Expand Down Expand Up @@ -1774,6 +1789,7 @@ SearchReplaceDialog::query_to_model (SearchReplaceResults &model, const db::Layo
bool res = false;

int data_prop_id = lq.has_property ("data") ? int (lq.property_by_name ("data")) : -1;
int expressions_prop_id = lq.has_property ("expressions") ? int (lq.property_by_name ("expressions")) : -1;
int shape_prop_id = lq.has_property ("shape") ? int (lq.property_by_name ("shape")) : -1;
int layer_index_prop_id = lq.has_property ("layer_index") ? int (lq.property_by_name ("layer_index")) : -1;
int instance_prop_id = lq.has_property ("inst") ? int (lq.property_by_name ("inst")) : -1;
Expand All @@ -1784,6 +1800,11 @@ SearchReplaceDialog::query_to_model (SearchReplaceResults &model, const db::Layo
int parent_cell_index_prop_id = lq.has_property ("parent_cell_index") ? int (lq.property_by_name ("parent_cell_index")) : -1;
int initial_cell_index_prop_id = lq.has_property ("initial_cell_index") ? int (lq.property_by_name ("initial_cell_index")) : -1;

tl::Variant ve;
if (expressions_prop_id >= 0 && iq.get (expressions_prop_id, ve)) {
model.set_data_column_headers (ve);
}

while (! iq.at_end ()) {

if (++n > max_item_count) {
Expand Down
2 changes: 2 additions & 0 deletions src/lay/lay/laySearchReplaceDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Q_OBJECT
SearchReplaceResults ();

void clear ();
void set_data_column_headers (const tl::Variant &v);
void push_back (const tl::Variant &v);
void push_back (const QueryShapeResult &v);
void push_back (const QueryInstResult &v);
Expand Down Expand Up @@ -169,6 +170,7 @@ Q_OBJECT
std::vector<QueryInstResult> m_inst_result;
std::vector<QueryCellResult> m_cell_result;
size_t m_data_columns;
tl::Variant m_data_column_headers;
mutable int m_last_column_count;
std::map<db::cell_index_type, std::string> m_cellname_map;
std::map<unsigned int, db::LayerProperties> m_lp_map;
Expand Down
5 changes: 4 additions & 1 deletion src/tl/tl/tlExpression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4059,7 +4059,6 @@ Eval::parse (Expression &expr, const std::string &s, bool top)
expr = Expression (this, s);

tl::Extractor ex (s.c_str ());
tl::Extractor ex0 = ex;
ExpressionParserContext context (&expr, ex);

if (top) {
Expand All @@ -4074,6 +4073,8 @@ Eval::parse (Expression &expr, const std::string &s, bool top)
void
Eval::parse (Expression &expr, tl::Extractor &ex, bool top)
{
ex.skip ();

expr = Expression (this, ex.get ());

tl::Extractor ex0 = ex;
Expand All @@ -4093,6 +4094,8 @@ Eval::parse (Expression &expr, tl::Extractor &ex, bool top)
std::string
Eval::parse_expr (tl::Extractor &ex, bool top)
{
ex.skip ();

tl::Eval eval (0, true);
Expression expr (&eval, ex.get ());

Expand Down

0 comments on commit 33d1cdc

Please sign in to comment.