我正在开发一个拖放功能,它允许我在画布上移动项目。我让它工作(有点),但我只稍微移动,但线穿过屏幕(并最终离开屏幕的可见部分)画布,所以我无法到达它。我不知道从这里去哪里。下面是我到目前为止创建的拖放代码:
def onPressToMove(self, event): #get initial location of object to be moved
winX = event.x - self.workspace.canvasx(0)
winY = event.y - self.workspace.canvasy(0)
self.dragInfo["Widget"] = self.workspace.find_closest(event.x, event.y, halo = 5)[0]
self.dragInfo["xCoord"] = winX
self.dragInfo["yCoord"] = winY
def onReleaseToMove(self, event): #reset data on release
self.dragInfo["Widget"] = None
self.dragInfo["xCoord"] = 0
self.dragInfo["yCoord"] = 0
def onMovement(self, event):
winX = event.x - self.workspace.canvasx(0)
winY = event.y - self.workspace.canvasy(0)
newX = winX - self.dragInfo["xCoord"]
newY = winY - self.dragInfo["yCoord"]
self.workspace.move(self.dragInfo["Widget"], newX, newY)
Run Code Online (Sandbox Code Playgroud)
DragInfo 是我用来存储数据的字典。最初我认为将画布坐标转换为窗口坐标会有所帮助,但它的作用与没有这些东西时相同。
我是CakePHP的新手,我有一个关系问题.
我的模型看起来像这样:
<?
class Operator extends AppModel
{
var $name = 'Operator';
var $hasOne = array('Contact','Adress','Land');
}
?>
Run Code Online (Sandbox Code Playgroud)
和我的表看起来像这样:
CREATE TABLE `operators` (
`id` varchar(45) NOT NULL,
`name` int(11) NOT NULL,
`adress_id` int(11) NOT NULL,
`land_id` int(11) NOT NULL,
`contact_id` int(11) NOT NULL,
`operator_category_id` int(11) NOT NULL,
`legal_form` varchar(45) DEFAULT NULL,
`affidavit` varchar(45) DEFAULT NULL,
`comment` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`),
KEY `operator_category_fk_idx` (`operator_category_id`),
KEY `contact_id_idx` (`contact_id`),
KEY `adress_id_idx` (`adress_id`),
KEY `land_id_idx` (`land_id`),
CONSTRAINT `adress_id` …Run Code Online (Sandbox Code Playgroud) 我有一个超过1000个输入的表单,它在下面显示警告:
警告:未知:输入变量超过1000.要在php.ini中增加限制更改max_input_vars.在第0行的未知中
我已经max_input_vars在php.ini文件中更改为超过1500 但它没有生效并显示相同的错误.
我的项目详情:
我该如何清除此警告?
我正在尝试添加相同字段的数据并希望返回我使用以下查询的结果:
$total = $this->Details->find('all', array(
'fields' => array('sum(Details.total_downtime+ Details.total_downtime)'),
'conditions' => array('Details.site_id' => $id)
));
print_r($total->toArray());
exit;
Run Code Online (Sandbox Code Playgroud)
我得到以下结果:
Array (
[0] => App\Model\Entity\Detail Object (
[displayField] => username
[_accessible:protected] => Array (
[*] => 1
[id] => 1
[site_id] => 1
[uptime] => 1
[downtime] => 1
)
[_properties:protected] => Array (
[sum(Details] => Array ( [total_downtime+ Details] => 4 )
)
[_original:protected] => Array ( )
[_hidden:protected] => Array ( )
[_virtual:protected] => Array ( )
[_className:protected] => App\Model\Entity\Detail …Run Code Online (Sandbox Code Playgroud) 该计划如下:
#include <iostream>
using namespace std;
template <typename F, typename T1, typename T2>
void flip2(F f, T1 &&t1, T2 &&t2)
{
f(t2, t1);
}
void g(int &&i, int &j)
{
cout << i << " " << j << endl;
}
int main(void)
{
int i = 1;
flip2(g, i, 42);
}
Run Code Online (Sandbox Code Playgroud)
编译器抱怨:
error: rvalue reference to type 'int' cannot bind to lvalue of type 'int'
Run Code Online (Sandbox Code Playgroud)
但据我所知,正如T2实例化那样int,那么类型t2是int&&,所以应该允许它传递给函数g的第一个参数(int &&). …
我的代码中有以下行:
#include <atomic>
std::atomic_uint32_t tmp;
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下编译错误:
命名空间'std'中的'atomic_uint32_t'未命名类型.
我包括<cstdint>但错误仍然存在.
我的GCC版本:5.4.0,Ubuntu 14.04(64位)
我试图初始化模板类this中的数组,并将指针传递给数组中的所有元素.这是我的类可能是这样的:
template<int NUM> class outer_class;
template<int N>
class inner_class {
private:
outer_class<N> *cl;
public:
inner_class(outer_class<N> *num) {
cl = num;
}
void print_num() {
cl->print_num();
}
};
template<int NUM> class outer_class {
private:
int number = NUM;
// --> here I basically want NUM times 'this' <--
std::array<inner_class<NUM>, NUM> cl = { this, this, this, this };
public:
void print_num() {
std::cout << number << std::endl;
}
void print() {
cl[NUM - 1].print_num();
}
};
int main() { …Run Code Online (Sandbox Code Playgroud) 这将在库中使用,而不是像示例一样,下面的示例使得它只是解释了问题.
我有一个BaseType模板专门化的模板类.
template<class...>
class BaseType; //Forward declare
template<typename T>
BaseType<T> { /* ...implementation 1... */ };
template<typename T, typename R>
BaseType<T,R> { /* ...implementation 2... */ };
Run Code Online (Sandbox Code Playgroud)
我现在将为shared_ptr<BaseType>模板创建一个别名.为其中一个模板版本执行此操作很好.
template<typename T>
using SlotType = std::shared_ptr<BaseType<T> >;
using EventArgSlot = SlotType<EventArgs>;
EventArgSlot slot1;
Run Code Online (Sandbox Code Playgroud)
但是我应该如何定义别名,以便它也支持这个:
using MessageIntegerSlot = SlotType<MessageArgs, int>;
MessageIntegerSlot slot2;
Run Code Online (Sandbox Code Playgroud)
只使用相同的附加模板参数添加其他别名不起作用:
template<typename T, typename R>
using SlotType = std::shared_ptr<BaseType<T,R> >;
Run Code Online (Sandbox Code Playgroud)
这可以在C++ 11/14中解决吗?
我有一个Factory设计模式的小例子,我对这部分感兴趣:
std::make_unique< A >(*this)
Run Code Online (Sandbox Code Playgroud)
......尤其如此*this.
这是否意味着该clone()方法返回一个std::unique_ptr指向工厂类成员的?并且createInstance()总是返回同一个Factory类的成员?
我只是混淆std::make_unique< A >(*this)应该做什么,因为A在构造函数中std::string,而不是指向自身的指针.
class Base {
public:
virtual ~Base() {}
virtual std::unique_ptr<Base> clone() = 0;
virtual void print() = 0;
};
class A: public Base {
std::string name_;
public:
A(std::string name ){name_ = name;};
std::unique_ptr<Base> clone() override{
return std::make_unique<A>(*this);
};
void print( ) override{
std::cout << "Class A: " << name_;
};
virtual ~A(){};
};
class …Run Code Online (Sandbox Code Playgroud) 我正在用 C++ 编写一个接受 dict 的模块。
如何在 C++ 中操作 pybind11::dict
#include <pybind11/pybind11.h>
#include<iostream>
#include <pybind11/stl.h>
#include<map>
using namespace std;
namespace py = pybind11;
int main() {
py::dict dict;
dict["a"] = 1; // throws exception error - ptyes.h Line 546
dict["b"] = 2; // throws exception error - ptyes.h Line 546
for (auto item : dict)
{
std::cout << "key: " << item.first << ", value=" << item.second << std::endl;
};
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)