BaseTreeDock::BaseTreeDock(QString window_title, QString object_name, bool requires_refresh, QWidget *parent, Qt::WindowFlags flags) : BaseDock(parent, flags) , m_collapsed(true) { setWindowTitle(window_title); setObjectName(object_name); setFeatures(QDockWidget::AllDockWidgetFeatures); setAllowedAreas(Qt::AllDockWidgetAreas); m_arr_in = QIcon(":img/arrow-in.png"); m_arr_out = QIcon(":img/arrow-out.png"); QWidget *w = new QWidget(); QVBoxLayout *l = new QVBoxLayout(); w->setLayout(l); m_tree_view = new QTreeWidget(this); m_tree_view->setEditTriggers(QAbstractItemView::NoEditTriggers); m_tree_view->setDropIndicatorShown(false); m_tree_view->setProperty("showSortIndicator",QVariant(true)); m_tree_view->setSelectionMode(QAbstractItemView::ExtendedSelection); QHBoxLayout *s = new QHBoxLayout(); QLabel *lbl_search = new QLabel(tr("Search"),this); s->addWidget(lbl_search); m_le_search = new QLineEdit(this); m_le_search->setObjectName("le_search"); s->addWidget(m_le_search); m_btn_toggle_tree = new QPushButton(this); m_btn_toggle_tree->setIcon(m_arr_out); s->addWidget(m_btn_toggle_tree); QPushButton *btn_clear_search = new QPushButton(this); QIcon icn_cross(":img/cross.png"); btn_clear_search->setIcon(icn_cross); s->addWidget(btn_clear_search); l->addLayout(s); QPushButton *btn = new QPushButton(tr("Clear Filter"),this); w->layout()->addWidget(m_tree_view); w->layout()->addWidget(btn); setWidget(w); connect(btn, SIGNAL(clicked()),this,SLOT(clear_filter())); connect(m_le_search, SIGNAL(textChanged(QString)), this, SLOT(search_changed(QString))); connect(btn_clear_search, SIGNAL(clicked()),this,SLOT(clear_search())); connect(m_btn_toggle_tree, SIGNAL(clicked()), this, SLOT(toggle_tree())); connect(m_tree_view, SIGNAL(itemSelectionChanged()), this, SLOT(selection_changed())); m_requires_refresh = requires_refresh; if(DT){ connect(DT,SIGNAL(units_refreshed()),this,SLOT(refresh())); } }
ThoughtsDock::ThoughtsDock(QWidget *parent, Qt::WindowFlags flags) : BaseDock(parent, flags) { setWindowTitle(tr("Thoughts")); setObjectName("dock_thoughts"); setFeatures(QDockWidget::AllDockWidgetFeatures); setAllowedAreas(Qt::AllDockWidgetAreas); QWidget *w = new QWidget(); QVBoxLayout *l = new QVBoxLayout(); w->setLayout(l); // THOUGHTS TABLE tw_thoughts = new QTableWidget(this); tw_thoughts->setColumnCount(3); tw_thoughts->setEditTriggers(QTableWidget::NoEditTriggers); tw_thoughts->setWordWrap(true); tw_thoughts->setShowGrid(false); tw_thoughts->setGridStyle(Qt::NoPen); tw_thoughts->setAlternatingRowColors(true); tw_thoughts->setSelectionMode(QAbstractItemView::ExtendedSelection); tw_thoughts->setSelectionBehavior(QAbstractItemView::SelectRows); tw_thoughts->setHorizontalHeaderLabels(QStringList() << "Thought" << "Count" << "Description"); tw_thoughts->verticalHeader()->hide(); tw_thoughts->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Interactive); tw_thoughts->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Interactive); tw_thoughts->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Interactive); tw_thoughts->setColumnWidth(0,100); tw_thoughts->setColumnWidth(1,50); tw_thoughts->horizontalHeader()->setStretchLastSection(true); QHBoxLayout *s = new QHBoxLayout(); QLabel *lbl_search = new QLabel("Search",this); s->addWidget(lbl_search); QLineEdit *le_search = new QLineEdit(this); le_search->setObjectName("le_search"); s->addWidget(le_search); QPushButton *btn_clear_search = new QPushButton(this); QIcon icn(":img/cross.png"); btn_clear_search->setIcon(icn); s->addWidget(btn_clear_search); l->addLayout(s); QPushButton *btn = new QPushButton("Clear Filter",this); w->layout()->addWidget(tw_thoughts); w->layout()->addWidget(btn); setWidget(w); connect(tw_thoughts,SIGNAL(itemSelectionChanged()),this,SLOT(selection_changed())); connect(btn, SIGNAL(clicked()),this,SLOT(clear_filter())); connect(le_search, SIGNAL(textChanged(QString)),this, SLOT(search_changed(QString))); connect(btn_clear_search, SIGNAL(clicked()),this,SLOT(clear_search())); }
int set_params(dt_lib_module_t *self, const void *params, int size) { dt_lib_location_t *lib = (dt_lib_location_t *)self->data; const size_t size_fixed = sizeof(struct params_fixed_t); if(size < size_fixed) return 1; const struct params_fixed_t *params_fixed = (struct params_fixed_t *)params; const char *name = (char *)(params + size_fixed); const size_t size_name = strlen(name) + 1; if(size_fixed + size_name > size) return 1; const size_t size_points = size - (size_fixed + size_name); if(size_points % 2 * sizeof(float) != 0) return 1; _lib_location_result_t *location = (_lib_location_result_t *)malloc(sizeof(_lib_location_result_t)); location->relevance = params_fixed->relevance; location->type = params_fixed->type; location->lon = params_fixed->lon; location->lat = params_fixed->lat; location->bbox_lon1 = params_fixed->bbox_lon1; location->bbox_lat1 = params_fixed->bbox_lat1; location->bbox_lon2 = params_fixed->bbox_lon2; location->bbox_lat2 = params_fixed->bbox_lat2; location->marker_type = params_fixed->marker_type; location->name = g_strdup(name); location->marker_points = NULL; for(const float *points = (float *)(params + size_fixed + size_name); (void *)points < params + size; points += 2) { dt_geo_map_display_point_t *p = (dt_geo_map_display_point_t *)malloc(sizeof(dt_geo_map_display_point_t)); p->lat = points[0]; p->lon = points[1]; location->marker_points = g_list_append(location->marker_points, p); } clear_search(lib); lib->places = g_list_append(lib->places, location); gtk_entry_set_text(lib->search, ""); _lib_location_search_finish(self); return 0; }
static gboolean _lib_location_search(gpointer user_data) { GMarkupParseContext *ctx = NULL; CURL *curl = NULL; CURLcode res; GError *err = NULL; dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_location_t *lib = (dt_lib_location_t *)self->data; gchar *query = NULL, *text = NULL; /* get escaped search text */ text = g_uri_escape_string(gtk_entry_get_text(lib->search), NULL, FALSE); if(!(text && *text)) goto bail_out; /* clean up previous results before adding new */ clear_search(lib); /* build the query url */ query = dt_util_dstrcat(query, "http://nominatim.openstreetmap.org/search/%s?format=xml&limit=%d&polygon_text=1", text, LIMIT_RESULT); /* load url */ curl = curl_easy_init(); if(!curl) goto bail_out; curl_easy_setopt(curl, CURLOPT_URL, query); // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_WRITEDATA, lib); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _lib_location_curl_write_data); curl_easy_setopt(curl, CURLOPT_USERAGENT, (char *)darktable_package_string); res = curl_easy_perform(curl); if(res != 0) goto bail_out; if(!lib->response) goto bail_out; /* parse xml response and populate the result list */ ctx = g_markup_parse_context_new(&_lib_location_parser, 0, lib, NULL); g_markup_parse_context_parse(ctx, lib->response, lib->response_size, &err); if(err) goto bail_out; /* add the places into the result list */ GList *item = lib->places; if(!item) goto bail_out; // while(item) // { // _lib_location_result_t *p = (_lib_location_result_t *)item->data; // fprintf(stderr, "(%f,%f) %s\n", p->lon, p->lat, p->name); // item = g_list_next(item); // } /* cleanup an exit search job */ bail_out: if(err) { fprintf(stderr, "location search: %s\n", err->message); g_error_free(err); } if(curl) curl_easy_cleanup(curl); g_free(text); g_free(query); if(ctx) g_markup_parse_context_free(ctx); /* enable the widgets */ gtk_widget_set_sensitive(GTK_WIDGET(lib->search), TRUE); // gtk_widget_set_sensitive(lib->result, FALSE); return FALSE; }
void gui_reset(dt_lib_module_t *self) { dt_lib_location_t *lib = (dt_lib_location_t *)self->data; gtk_entry_set_text(lib->search, ""); clear_search(lib); }
void BaseTreeDock::closeEvent(QCloseEvent *event){ clear_search(); clear_filter(); event->accept(); }