.reference

git-svn-id: svn://ultimatepp.org/upp/trunk@14457 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2020-05-12 13:30:53 +00:00
parent 7162858a7c
commit 69b774a57e
6 changed files with 144 additions and 25 deletions

View file

@ -5,9 +5,12 @@ using namespace Upp;
struct MyApp : TopWindow { struct MyApp : TopWindow {
Rect rect; Rect rect;
int hline, vline; int hline, vline;
Point line1, line2;
typedef MyApp CLASSNAME; typedef MyApp CLASSNAME;
DropList op;
void Round(Rect& r) void Round(Rect& r)
{ {
int cx = r.GetWidth(); int cx = r.GetWidth();
@ -19,42 +22,49 @@ struct MyApp : TopWindow {
{ {
Size sz = GetSize(); Size sz = GetSize();
w.DrawRect(sz, SColorPaper()); w.DrawRect(sz, SColorPaper());
DrawFrame(w, rect, Black()); DrawFrame(w, rect, SBlack());
w.DrawRect(0, hline, sz.cx, 1, SRed); w.DrawRect(0, hline, sz.cx, 1, SRed());
w.DrawRect(vline, 0, 1, sz.cy, SBlue); w.DrawRect(vline, 0, 1, sz.cy, SBlue());
if(line1 != line2)
w.DrawLine(line1, line2, DPI(2), SMagenta());
} }
virtual void LeftDown(Point p, dword keyflags) { virtual void LeftDown(Point p, dword keyflags) {
RectTracker tr(*this); RectTracker tr(*this);
Size sz = GetSize(); Size sz = GetSize();
if((keyflags & K_CTRL) && (keyflags & K_ALT)) { switch((int)~op) {
case 0:
rect = tr.Track(rect, ALIGN_RIGHT, ALIGN_BOTTOM);
break;
case 1:
rect = tr.Track(rect, ALIGN_LEFT, ALIGN_TOP);
break;
case 2:
tr.Dashed().Animation();
rect = tr.Track(rect, ALIGN_CENTER, ALIGN_CENTER);
break;
case 3:
tr.Solid();
vline = tr.TrackVertLine(0, 0, sz.cy, vline);
break;
case 4:
tr.Solid();
hline = tr.TrackHorzLine(0, 0, sz.cx, hline);
break;
case 5:
line1 = p;
line2 = tr.TrackLine(p.x, p.y);
break;
case 6:
tr.Dashed(); tr.Dashed();
tr.MinSize(Size(-10000, -10000)); // allow negative size tr.MinSize(Size(-10000, -10000)); // allow negative size
tr.Width(DPI(4)); tr.Width(DPI(4));
tr.SetColor(Yellow()); tr.SetColor(Yellow());
tr.round = THISBACK(Round);
rect = tr.Track(rect, ALIGN_RIGHT, ALIGN_BOTTOM); rect = tr.Track(rect, ALIGN_RIGHT, ALIGN_BOTTOM);
rect.Normalize(); rect.Normalize();
} break;
else };
if(keyflags & K_ALT) {
tr.Dashed().Animation();
tr.round = THISBACK(Round);
rect = tr.Track(rect, ALIGN_CENTER, ALIGN_CENTER);
}
else
if(keyflags & K_SHIFT) {
tr.Solid();
hline = tr.TrackHorzLine(0, 0, sz.cx, hline);
}
else
if(keyflags & K_CTRL) {
tr.Solid();
vline = tr.TrackVertLine(0, 0, sz.cy, vline);
}
else {
tr.Normal();
rect = tr.Track(rect, ALIGN_RIGHT, ALIGN_BOTTOM);
}
Refresh(); Refresh();
} }
@ -63,6 +73,19 @@ struct MyApp : TopWindow {
hline = 150; hline = 150;
vline = 150; vline = 150;
Sizeable().Zoomable(); Sizeable().Zoomable();
line1 = line2 = Point(10, 10);
Add(op.LeftPosZ(10, 200).TopPosZ(10));
op.Add(0, "Bottom right corner of rectangle");
op.Add(1, "Top left corner of rectangle");
op.Add(2, "Move rectangle");
op.Add(3, "Vertical line");
op.Add(4, "Horizontal line");
op.Add(5, "Free line");
op.Add(6, "Resize rectangle, special features");
op <<= 0;
} }
}; };

View file

@ -0,0 +1,16 @@
description "Demonstrates how to handle multiple database connections\377";
uses
Core,
MySql,
plugin/sqlite3;
file
mysql_schema.sch,
sqlite3_schema.sch,
multidb.h,
main.cpp;
mainconfig
"" = "";

View file

@ -0,0 +1,55 @@
#include <MySql/MySql.h>
using namespace Upp;
#define SCHEMADIALECT <MySql/MySqlSchema.h>
#define MODEL <SQL_MultiDB/mysql_schema.sch>
#include <Sql/sch_source.h> // creates the code for mapping schema structures to database rows
#include <Sql/sch_schema.h> // creates the code to generate sql scripts that upload schema to DB
#undef SCHEMADIALECT
namespace DB2 {
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
#define MODEL <SQL_MultiDB/sqlite3_schema.sch>
#include <Sql/sch_source.h>
#include <Sql/sch_schema.h>
#undef SCHEMADIALECT
}
CONSOLE_APP_MAIN
{
Sqlite3Session sqlite3;
MySqlSession mysql;
// edit the connection parameters if necessary
if(mysql.Connect("root", "Passw0rd", "test")) {
Cout() << "Connected\n";
SQL = mysql;
SqlSchema sch(MY_SQL);
All_Tables(sch);
// create the table if necessary
SqlPerformScript(sch.Upgrade());
SqlPerformScript(sch.Attributes());
SQL.ClearError();
try {
// insert some random data
SQL & Insert(TEST_TABLE)(VALUE, Uuid::Create().ToString());
// fetch some data
Sql sql;
sql * Select(ID, VALUE).From(TEST_TABLE)
.OrderBy(Descending(ID))
.Limit(5);
while(sql.Fetch())
Cout() << AsString(sql[0]) << ": " << AsString(sql[VALUE]) << "\n";
}
catch(SqlExc &ex) {
Cerr() << "ERROR: " << ex << "\n";
SetExitCode(1);
}
}
else {
Cerr() <<"ERROR: Unable to connect to database\n";
SetExitCode(1);
}
}

View file

@ -0,0 +1,16 @@
#ifndef _SQL_MultiDB_multidb_h_
#define _SQL_MultiDB_multidb_h_
#define SCHEMADIALECT <MySql/MySqlSchema.h>
#define MODEL <SQL_MultiDB/mysql_schema.sch>
#include <Sql/sch_header.h>
#undef SCHEMADIALECT
namespace DB2 {
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
#define MODEL <SQL_MultiDB/sqlite3_schema.sch>
#include <Sql/sch_header.h>
#undef SCHEMADIALECT
};
#endif

View file

@ -0,0 +1,4 @@
TABLE_(TEST_TABLE)
INT_ (ID) PRIMARY_KEY AUTO_INCREMENT
STRING_ (VALUE, 32)
END_TABLE

View file

@ -0,0 +1,5 @@
TABLE(TEST_TABLE) // Note that column names definition is simply shared between schemas
INT (ID) PRIMARY_KEY AUTO_INCREMENT
STRING (VALUE, 32)
STRING_ (NAME, 200)
END_TABLE