46 #include <Wt/WDialog.h> 47 #include <Wt/WPushButton.h> 48 #include <Wt/WContainerWidget.h> 49 #include <Wt/WAbstractItemModel.h> 50 #include <Wt/WLineEdit.h> 52 #include <Wt/WVBoxLayout.h> 53 #include <Wt/WTableView.h> 54 #include <Wt/WModelIndex.h> 56 #include <Wtx/Core/Core.h> 57 #include <Wtx/Util/Util.h> 59 #include "FieldDefLookupWidget.h" 61 Wt::Signal<> & Wtx::Dbo::FieldDefLookupWidget::TableLineEdit::pickered()
82 m_fieldDef ( fieldDef )
85 changed() .connect(
this, &TabLinEdi::on_changed );
86 focussed() .connect(
this, &TabLinEdi::on_focussed );
109 void loadModel(
int id,
const std::string & filter )
111 if( !m_loaded && fieldDef() && fieldDef()-> provider() )
114 std::cout << __FILE__ <<
":" << __LINE__
115 <<
" Loading Model id: " <<
id 116 <<
" sid:" << m_sourceID
117 <<
" tid:" << m_targetID
122 m_model = fieldDef()-> provider()-> model( m_sourceID,
id, filter );
138 std::cout << __FILE__ <<
":" << __LINE__
141 <<
" " << m_valueText
153 setValueText( m_valueText );
173 auto value = Wt::WLineEdit::valueText().toUTF8();
196 std::cout << __FILE__ <<
":" << __LINE__ <<
" no provider!" << std::endl;
200 m_targetID = provider()-> find_id( value );
204 auto dialog = addChild( std::make_unique<Wt::WDialog>(
"item pickers") );
205 dialog-> rejectWhenEscapePressed(
true);
207 auto cw = dialog-> contents()-> addNew<Wt::WContainerWidget>();
208 auto lw = std::make_unique<Wt::WVBoxLayout>();
210 auto u_search = std::make_unique<Wt::WLineEdit>(value);
211 auto search = u_search.get();
212 search-> setDisabled(
true);
213 lw-> addWidget( std::move( u_search ) );
215 if( fieldDef()-> getTableView )
218 std::cout << __FILE__ <<
":" << __LINE__
221 <<
" " << search-> valueText().toUTF8()
226 auto u_table = fieldDef()-> getTableView( m_sourceID, m_targetID, search-> valueText().toUTF8(), m_session );
227 auto table = u_table.get();
235 table-> doubleClicked().connect( dialog, &Wt::WDialog::accept );
236 lw-> addWidget( std::move( u_table ), 1 );
238 auto u_select = std::make_unique<Wt::WPushButton>(
"select");
239 u_select-> clicked().connect( dialog, &Wt::WDialog::accept );
240 lw-> addWidget( std::move( u_select ) );
242 dialog-> finished().connect( [=]( Wt::DialogCode code )
248 if( dialog-> result() != Wt::DialogCode::Accepted )
255 if( table-> selectedIndexes().size() != 1 )
258 auto index = *table-> selectedIndexes().begin();
260 m_targetID = Wt::asNumber( index.data() );
262 std::cout << __FILE__ <<
":" << __LINE__
263 <<
" " << index.row()
264 <<
" " << index.column()
269 setValueText( provider()-> get_string( m_targetID ) );
272 Wt::WFormWidget::blurred().emit();
287 std::make_unique<Wt::WText>
289 Wt::WString(
"FieldDefLookupTable.cpp:{1} 'getTableView' not returning view '{2}'")
303 std::make_unique<Wt::WText>
305 Wt::WString(
"FieldDefLookupTable.cpp:{1} 'getTableView' not set '{2}'")
312 auto u_cancel = std::make_unique<Wt::WPushButton>(
"cancel");
313 u_cancel-> clicked().connect( dialog, &Wt::WDialog::reject );
314 lw-> addWidget( std::move( u_cancel ) );
316 cw-> setLayout( std::move(lw) );
322 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << std::endl;
324 setValueText( provider()-> get_string( m_targetID ) );
325 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << std::endl;
327 setToolTip( provider()-> get_toolTip( m_targetID ) );
331 std::cout << __FILE__ <<
":" << __LINE__
332 <<
"\n targetID: " << m_targetID
333 <<
"\n valueText: " << m_valueText
339 auto dialog = addChild( std::make_unique<Wt::WDialog>() );
340 dialog-> rejectWhenEscapePressed();
341 dialog-> contents()-> addNew<Wt::WText>(
"cannot put in false data");
350 Wt::WString valueText()
const 352 auto retVal = Wt::WString(
"[null]");
354 if( m_targetID != -1 )
355 retVal = Wt::WString(
"{1}: {2}]").arg( m_table ).arg( m_targetID );
358 std::cout << __FILE__ <<
":" << __LINE__ <<
"::" << __FUNCTION__ <<
"()" 359 <<
"\n m_loaded: " << m_loaded
360 <<
"\n m_field: " << m_field
361 <<
"\n m_table: " << m_table
362 <<
"\n m_sourceID: " << m_sourceID
363 <<
"\n m_targetID: " << m_targetID
364 <<
"\n retVal: " << retVal
373 void setValueText(
const Wt::WString & value )
375 m_valueText = value.toUTF8();
378 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << __FUNCTION__
379 <<
" " << m_valueText
389 if( m_valueText ==
"[null]" )
394 if( m_valueText.find(
":") != std::string::npos )
397 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << __FUNCTION__ <<
" " << m_valueText << std::endl;
400 auto v = Wtx::Core::split( m_valueText,
':' );
402 m_targetID = std::stoi(v.at(1));
403 loadModel( m_targetID,
"" );
405 if( fieldDef()-> provider() )
407 m_valueText = fieldDef()-> provider()-> get_string( m_targetID );
408 m_toolTip = fieldDef()-> provider()-> get_toolTip( m_targetID );
415 Wt::WLineEdit::setValueText( m_valueText );
416 Wt::WLineEdit::setToolTip( m_toolTip );
421 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << __FUNCTION__
422 <<
"\n loaded: " << m_loaded
423 <<
"\n sourceID: " << m_sourceID
424 <<
"\n targetID: " << m_targetID
425 <<
"\n table: " << m_table
426 <<
"\n value: " << value
427 <<
"\n valueText:" << m_valueText
428 <<
"\n valueText:" << Wt::WLineEdit::valueText()
430 <<
"\n toolTip: " << m_toolTip
441 bool m_loaded =
false;
446 std::string m_valueText;
447 std::string m_toolTip;
449 std::shared_ptr<Wt::WAbstractItemModel> m_model =
nullptr;
488 std::unique_ptr<Wt::WWidget> Wtx::Dbo::FieldDefLookupWidget::createEditWidget(
int sid,
Wtx::Dbo::Session & session )
const 498 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << fieldName() <<
": " <<
"Model provider not set" << std::endl;
504 retVal-> m_table =
"[" + targetTable;
505 retVal-> m_field = fieldName();
Flags
Field Definition Flags.