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 "FieldDefLookupManager.h" 62 Wt::Signal<> & Wtx::Dbo::FieldDefLookupManager::TableLineEdit::pickered()
71 :
public Wt::WLineEdit
86 m_fieldDef ( fieldDef )
89 changed ().connect(
this, &TabLinEdi::on_changed );
90 focussed ().connect(
this, &TabLinEdi::on_focussed );
91 doubleClicked ().connect(
this, &TabLinEdi::on_doubleClicked );
114 void loadModel(
int id,
const std::string & filter )
116 if( !m_loaded && fieldDef() && fieldDef()-> provider() )
119 std::cout << __FILE__ <<
":" << __LINE__
120 <<
" Loading Model id: " <<
id 121 <<
" sid:" << m_sourceID
122 <<
" tid:" << m_targetID
127 m_model = fieldDef()-> provider()-> model( m_sourceID,
id, filter );
140 void on_doubleClicked()
142 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << std::endl;
149 std::cout << __FILE__ <<
":" << __LINE__
152 <<
" " << m_valueText
164 setValueText( m_valueText );
184 auto value = Wt::WLineEdit::valueText().toUTF8();
207 std::cout << __FILE__ <<
":" << __LINE__ <<
" no provider!" << std::endl;
211 m_targetID = provider()-> find_id( value );
213 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << __FUNCTION__ <<
"(): " << m_targetID << std::endl;
217 auto dialog = addChild( std::make_unique<Wt::WDialog>(
"item pickers") );
218 dialog-> rejectWhenEscapePressed(
true);
220 auto cw = dialog-> contents()-> addNew<Wt::WContainerWidget>();
221 auto lw = std::make_unique<Wt::WVBoxLayout>();
223 auto u_search = std::make_unique<Wt::WLineEdit>(value);
224 auto search = u_search.get();
225 search-> setDisabled(
true);
226 lw-> addWidget( std::move( u_search ) );
228 if( fieldDef()-> getTableView )
231 std::cout << __FILE__ <<
":" << __LINE__
234 <<
" " << search-> valueText().toUTF8()
239 auto u_table = fieldDef()-> getTableView( m_sourceID, m_targetID, search-> valueText().toUTF8(), m_session );
240 auto table = u_table.get();
248 table-> doubleClicked().connect( dialog, &Wt::WDialog::accept );
249 lw-> addWidget( std::move( u_table ), 1 );
251 auto u_select = std::make_unique<Wt::WPushButton>(
"select");
252 u_select-> clicked().connect( dialog, &Wt::WDialog::accept );
253 lw-> addWidget( std::move( u_select ) );
255 dialog-> finished().connect( [=]( Wt::DialogCode code )
261 if( dialog-> result() != Wt::DialogCode::Accepted )
268 if( table-> selectedIndexes().size() != 1 )
271 auto index = *table-> selectedIndexes().begin();
273 m_targetID = Wt::asNumber( index.data() );
275 std::cout << __FILE__ <<
":" << __LINE__
276 <<
" " << index.row()
277 <<
" " << index.column()
282 setValueText( provider()-> get_string( m_targetID ) );
299 std::make_unique<Wt::WText>
301 Wt::WString(
"FieldDefLookupTable.cpp:{1} 'getTableView' not returning view '{2}'")
315 std::make_unique<Wt::WText>
317 Wt::WString(
"FieldDefLookupTable.cpp:{1} 'getTableView' not set '{2}'")
324 auto u_cancel = std::make_unique<Wt::WPushButton>(
"cancel");
325 u_cancel-> clicked().connect( dialog, &Wt::WDialog::reject );
326 lw-> addWidget( std::move( u_cancel ) );
328 cw-> setLayout( std::move(lw) );
334 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << std::endl;
336 setValueText( provider()-> get_string( m_targetID ) );
337 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << std::endl;
339 setToolTip( provider()-> get_toolTip( m_targetID ) );
343 std::cout << __FILE__ <<
":" << __LINE__
344 <<
"\n targetID: " << m_targetID
345 <<
"\n valueText: " << m_valueText
351 auto dialog = addChild( std::make_unique<Wt::WDialog>() );
352 dialog-> rejectWhenEscapePressed();
353 dialog-> contents()-> addNew<Wt::WText>(
"cannot put in false data");
362 Wt::WString valueText()
const 364 auto retVal = Wt::WString(
"[null]");
366 if( m_targetID != -1 )
367 retVal = Wt::WString(
"{1}: {2}]").arg( m_table ).arg( m_targetID );
370 std::cout << __FILE__ <<
":" << __LINE__ <<
"::" << __FUNCTION__ <<
"()" 371 <<
"\n m_loaded: " << m_loaded
372 <<
"\n m_field: " << m_field
373 <<
"\n m_table: " << m_table
374 <<
"\n m_sourceID: " << m_sourceID
375 <<
"\n m_targetID: " << m_targetID
376 <<
"\n retVal: " << retVal
385 void setValueText(
const Wt::WString & value )
387 m_valueText = value.toUTF8();
390 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << __FUNCTION__
391 <<
" " << m_valueText
401 if( m_valueText ==
"[null]" )
406 if( m_valueText.find(
":") != std::string::npos )
409 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << __FUNCTION__ <<
" " << m_valueText << std::endl;
412 auto v = Wtx::Core::split( m_valueText,
':' );
414 m_targetID = std::stoi(v.at(1));
415 loadModel( m_targetID,
"" );
417 if( fieldDef()-> provider() )
419 m_valueText = fieldDef()-> provider()-> get_string( m_targetID );
420 m_toolTip = fieldDef()-> provider()-> get_toolTip( m_targetID );
427 Wt::WLineEdit::setValueText( m_valueText );
428 Wt::WLineEdit::setToolTip( m_toolTip );
433 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << __FUNCTION__
434 <<
"\n loaded: " << m_loaded
435 <<
"\n sourceID: " << m_sourceID
436 <<
"\n targetID: " << m_targetID
437 <<
"\n table: " << m_table
438 <<
"\n value: " << value
439 <<
"\n valueText:" << m_valueText
440 <<
"\n valueText:" << Wt::WLineEdit::valueText()
442 <<
"\n toolTip: " << m_toolTip
453 bool m_loaded =
false;
458 std::string m_valueText;
459 std::string m_toolTip;
461 std::shared_ptr<Wt::WAbstractItemModel> m_model =
nullptr;
500 std::unique_ptr<Wt::WWidget> Wtx::Dbo::FieldDefLookupManager::createEditWidget(
int sid,
Wtx::Dbo::Session & session )
const 510 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << fieldName() <<
": " <<
"Model provider not set" << std::endl;
516 retVal-> m_table =
"[" + targetTable;
517 retVal-> m_field = fieldName();
Flags
Field Definition Flags.
FieldDefLookupManager(TableDef &td, const char *fn, int w=-1, int h=-1, Flags f=Flags::None, std::string lb="", std::string ph="", std::string inf="", std::string tt="", int ht=-1)
ctor